--- 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<Triangle, Triangle> splitTriangles( + const Quadrilateral& q, + ldraw::Diagonal diagonal) { - editor.modifyObject(id, [context](ldraw::Object* object){ - object->invert(context); - }); -} - -static std::array<geom::Triangle, 2> splitTriangles(ldraw::Diagonal diagonal, const std::array<glm::vec3, 4>& points) -{ - std::array<geom::Triangle, 2> result; + std::pair<Triangle, Triangle> 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::pair<ldraw::triangleid_t, ldraw::triangleid_t>> -{ - std::optional<std::pair<ldraw::triangleid_t, ldraw::triangleid_t>> result; - const auto resolved = editor.model().get2(quadrilateral_id); - if (resolved.object != nullptr) - { - const ldraw::Color color = resolved.object->colorIndex; - const std::array<geom::Triangle, 2> split = splitTriangles(splitType, resolved.object->points); - const int position = resolved.index.row(); - editor.remove(position); - result = std::make_pair( - editor.insert<ldraw::Triangle>(position, split[0].points, color), - editor.insert<ldraw::Triangle>(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<SubfileReference> ref) -> ModelElement { + ref.inverted = not ref.inverted; + return ref; + }, + [](Colored<Triangle> triangle) -> ModelElement { + std::swap(triangle.p1, triangle.p2); + return triangle; + }, + [](Colored<Quadrilateral> quad) -> ModelElement { + std::swap(quad.p2, quad.p4); + return quad; + }, + [](const ModelElement& x) { return x; } + }, element); +}