diff -r 7c4a63a02632 -r 028798a72591 src/modeleditcontext.cpp --- 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 splitTriangles(ldraw::Diagonal diagonal, const glm::vec3(&points)[4]) { - using PropertyTriplet = std::tuple; -} - -static std::array diagonalToPointProperties(ldraw::Diagonal diagonal) -{ - std::array result; + std::array 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 split = splitTriangles(splitType, quadrilateral->points); + const int position = index.row(); editor.remove(position); - std::vector triangles; - triangles.reserve(2); - const std::array split = diagonalToPointProperties(splitType); - for (const PropertyTriplet& properties : split) - { - const ldraw::triangleid_t triangle = editor.insert( - position, - quadrilateral->getProperty(std::get<0>(properties)).value(), - quadrilateral->getProperty(std::get<1>(properties)).value(), - quadrilateral->getProperty(std::get<2>(properties)).value(), - 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(position, split[0].points, color), + editor.insert(position, split[1].points, color)); } return result; }