From 3a6f70946aab34c17188a2ec41cf54842630e15f Mon Sep 17 00:00:00 2001 From: bgbsww <120601209+bgbsww@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:00:47 -0400 Subject: [PATCH] Fix #16013 (#16090) * Fix #16013 * Fix #16013 --- src/Mod/Part/App/TopoShapeExpansion.cpp | 8 +-- tests/src/Mod/Part/App/TopoShapeExpansion.cpp | 66 ++++++++++++++----- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index c7a8f7cf6c..cfcbfc6230 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -2226,15 +2226,15 @@ TopoShape& TopoShape::makeElementRuledSurface(const std::vector& shap if (!a1.IsNull() && !a2.IsNull()) { // get end points of 1st curve - gp_Pnt p1 = a1->Value(a1->FirstParameter()); - gp_Pnt p2 = a1->Value(a1->LastParameter()); + gp_Pnt p1 = a1->Value(0.9 * a1->FirstParameter() + 0.1 * a1->LastParameter()); + gp_Pnt p2 = a1->Value(0.1 * a1->FirstParameter() + 0.9 * a1->LastParameter()); if (S1.getShape().Orientation() == TopAbs_REVERSED) { std::swap(p1, p2); } // get end points of 2nd curve - gp_Pnt p3 = a2->Value(a2->FirstParameter()); - gp_Pnt p4 = a2->Value(a2->LastParameter()); + gp_Pnt p3 = a2->Value(0.9 * a2->FirstParameter() + 0.1 * a2->LastParameter()); + gp_Pnt p4 = a2->Value(0.1 * a2->FirstParameter() + 0.9 * a2->LastParameter()); if (S2.getShape().Orientation() == TopAbs_REVERSED) { std::swap(p3, p4); } diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index 8aff441b62..dbaa489f13 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -1676,11 +1676,21 @@ TEST_F(TopoShapeExpansionTest, makeElementRuledSurfaceEdges) EXPECT_FLOAT_EQ(getArea(topoShape.getShape()), 20); // Assert that we're creating a correct element map EXPECT_TRUE(topoShape.getMappedChildElements().empty()); - // TODO: Revisit these when resetElementMap() is fully worked through. Suspect that last loop - // of makeElementRuledSurface is dependent on this to create elementMaps. - // EXPECT_EQ(elements.size(), 24); - // EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1); - // EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Vertex1;:G;PSH;:H2:7,E")); + EXPECT_EQ(elements.size(), 9); + EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1); + EXPECT_TRUE(allElementsMatch( + topoShape, + { + "Edge1", + "Edge1;:L(Edge1;D1|Vertex1;:L(Vertex1;D1);RSF|Vertex2;:L(Vertex2;D1);RSF);RSF", + "Edge1;D1", + "Vertex1", + "Vertex1;:L(Vertex1;D1);RSF", + "Vertex1;D1", + "Vertex2", + "Vertex2;:L(Vertex2;D1);RSF", + "Vertex2;D1", + })); } TEST_F(TopoShapeExpansionTest, makeElementRuledSurfaceWires) @@ -1690,18 +1700,44 @@ TEST_F(TopoShapeExpansionTest, makeElementRuledSurfaceWires) TopoShape cube1TS {cube1, 1L}; std::vector subWires = cube1TS.getSubTopoShapes(TopAbs_WIRE); // Act - cube1TS.makeElementRuledSurface({subWires[0], subWires[1]}, 0); // TODO: orientation as enum? - auto elements = elementMap(cube1TS); + auto surface = cube1TS.makeElementRuledSurface({subWires[0], subWires[1]}, + 0); // TODO: orientation as enum? + auto elements = elementMap(surface); // Assert - EXPECT_EQ(cube1TS.countSubElements("Wire"), 4); - EXPECT_NEAR(getArea(cube1TS.getShape()), 2.023056, 1e-6); + EXPECT_EQ(surface.countSubElements("Wire"), 4); + EXPECT_NEAR(getArea(surface.getShape()), 4, 1e-7); // Assert that we're creating a correct element map - EXPECT_TRUE(cube1TS.getMappedChildElements().empty()); - // TODO: Revisit these when resetElementMap() is fully worked through. Suspect that last loop - // of makeElementRuledSurface is dependent on this to create elementMaps. - // EXPECT_EQ(elements.size(), 24); - // EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1); - // EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Vertex1;:G;PSH;:H2:7,E")); + EXPECT_TRUE(surface.getMappedChildElements().empty()); + EXPECT_EQ(elements.size(), 24); + EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1); + EXPECT_TRUE(elementsMatch( // Depending on OCCT versions can get 24 or 28 entries here. + surface, + { + "Edge1", + "Edge1;:L(Edge1;D1|Vertex1;:L(Vertex1;D1);RSF|Vertex2;:L(Vertex2;D1);RSF);RSF", + "Edge1;D1", + "Edge2", + "Edge2;:L(Edge2;D1|Vertex1;:L(Vertex1;D1);RSF|Vertex3;:L(Vertex3;D1);RSF);RSF", + "Edge2;D1", + "Edge3", + "Edge3;:L(Edge3;D1|Vertex3;:L(Vertex3;D1);RSF|Vertex4;:L(Vertex4;D1);RSF);RSF", + "Edge3;D1", + "Edge4", + "Edge4;:L(Edge4;D1|Vertex2;:L(Vertex2;D1);RSF|Vertex4;:L(Vertex4;D1);RSF);RSF", + "Edge4;D1", + "Vertex1", + "Vertex1;:L(Vertex1;D1);RSF", + "Vertex1;D1", + "Vertex2", + "Vertex2;:L(Vertex2;D1);RSF", + "Vertex2;D1", + "Vertex3", + "Vertex3;:L(Vertex3;D1);RSF", + "Vertex3;D1", + "Vertex4", + "Vertex4;:L(Vertex4;D1);RSF", + "Vertex4;D1", + })); } TEST_F(TopoShapeExpansionTest, makeElementLoft)