--- a/src/modeleditcontext.cpp Mon Mar 09 22:12:50 2020 +0200 +++ b/src/modeleditcontext.cpp Mon Mar 09 23:42:26 2020 +0200 @@ -63,27 +63,16 @@ return this->storedModel; } -namespace +static std::array<geom::Triangle, 2> splitTriangles(ldraw::Diagonal diagonal, const glm::vec3(&points)[4]) { - using PropertyTriplet = std::tuple<ldraw::Property, ldraw::Property, ldraw::Property>; -} - -static std::array<PropertyTriplet, 2> diagonalToPointProperties(ldraw::Diagonal diagonal) -{ - std::array<PropertyTriplet, 2> result; + std::array<geom::Triangle, 2> result; switch (diagonal) { case ldraw::Diagonal::Diagonal_13: - result = { - std::make_tuple(ldraw::Property::Point1, ldraw::Property::Point2, ldraw::Property::Point3), - std::make_tuple(ldraw::Property::Point1, ldraw::Property::Point3, ldraw::Property::Point4) - }; + result = {geom::Triangle{points[0], points[1], points[2]}, {points[0], points[2], points[3]}}; break; case ldraw::Diagonal::Diagonal_24: - result = { - std::make_tuple(ldraw::Property::Point1, ldraw::Property::Point2, ldraw::Property::Point4), - std::make_tuple(ldraw::Property::Point2, ldraw::Property::Point3, ldraw::Property::Point4) - }; + result = {geom::Triangle{points[0], points[1], points[3]}, {points[1], points[2], points[3]}}; break; } return result; @@ -100,24 +89,13 @@ const ldraw::Quadrilateral* quadrilateral = editor.model().get(quadrilateral_id, &index); if (quadrilateral != nullptr) { - Q_ASSERT(index.isValid()); - int position = index.row(); + const ldraw::Color color = quadrilateral->colorIndex; + const std::array<geom::Triangle, 2> split = splitTriangles(splitType, quadrilateral->points); + const int position = index.row(); editor.remove(position); - std::vector<ldraw::triangleid_t> triangles; - triangles.reserve(2); - const std::array<PropertyTriplet, 2> split = diagonalToPointProperties(splitType); - for (const PropertyTriplet& properties : split) - { - const ldraw::triangleid_t triangle = editor.insert<ldraw::Triangle>( - position, - quadrilateral->getProperty(std::get<0>(properties)).value<glm::vec3>(), - quadrilateral->getProperty(std::get<1>(properties)).value<glm::vec3>(), - quadrilateral->getProperty(std::get<2>(properties)).value<glm::vec3>(), - ldraw::Color{quadrilateral->getProperty(ldraw::Property::Color).toInt()}); - triangles.push_back(triangle); - position += 1; - } - result = {triangles[0], triangles[1]}; + result = std::make_pair( + editor.insert<ldraw::Triangle>(position, split[0].points, color), + editor.insert<ldraw::Triangle>(position, split[1].points, color)); } return result; }