diff -r 6988973515d2 -r ca23936b455b src/ldrawalgorithm.cpp --- a/src/ldrawalgorithm.cpp Wed May 25 20:36:34 2022 +0300 +++ b/src/ldrawalgorithm.cpp Mon Jun 06 22:01:22 2022 +0300 @@ -1,53 +1,26 @@ #include "ldrawalgorithm.h" -#include "linetypes/quadrilateral.h" -#include "linetypes/triangle.h" -void ldraw::invert(ModelEditor& editor, ldraw::id_t id, GetPolygonsContext* context) +std::pair splitTriangles( + const Quadrilateral& q, + ldraw::Diagonal diagonal) { - editor.modifyObject(id, [context](ldraw::Object* object){ - object->invert(context); - }); -} - -static std::array splitTriangles(ldraw::Diagonal diagonal, const std::array& points) -{ - std::array result; + std::pair result; switch (diagonal) { case ldraw::Diagonal::Diagonal_13: - result = {geom::Triangle{points[0], points[1], points[2]}, {points[0], points[2], points[3]}}; + result = {Triangle{q.p1, q.p2, q.p3}, {q.p1, q.p3, q.p4}}; break; case ldraw::Diagonal::Diagonal_24: - result = {geom::Triangle{points[0], points[1], points[3]}, {points[1], points[2], points[3]}}; + result = {Triangle{q.p1, q.p2, q.p3}, {q.p2, q.p3, q.p4}}; break; } return result; } -auto ldraw::splitQuadrilateral( - ModelEditor& editor, - ldraw::quadrilateralid_t quadrilateral_id, - ldraw::Diagonal splitType -) -> std::optional> -{ - std::optional> result; - const auto resolved = editor.model().get2(quadrilateral_id); - if (resolved.object != nullptr) - { - const ldraw::Color color = resolved.object->colorIndex; - const std::array split = splitTriangles(splitType, resolved.object->points); - const int position = resolved.index.row(); - editor.remove(position); - result = std::make_pair( - editor.insert(position, split[0].points, color), - editor.insert(position, split[1].points, color)); - } - return result; -} - /** * @brief Modifies the !LDRAW_ORG line so that it becomes unofficial */ +/* void ldraw::makeUnofficial(ModelEditor& editor) { if (editor.model().size() >= 4) @@ -71,4 +44,24 @@ } } } -} \ No newline at end of file +} +*/ + +ModelElement inverted(const ModelElement& element) +{ + return std::visit(overloaded{ + [](Colored ref) -> ModelElement { + ref.inverted = not ref.inverted; + return ref; + }, + [](Colored triangle) -> ModelElement { + std::swap(triangle.p1, triangle.p2); + return triangle; + }, + [](Colored quad) -> ModelElement { + std::swap(quad.p2, quad.p4); + return quad; + }, + [](const ModelElement& x) { return x; } + }, element); +}