Skip to content

Commit

Permalink
Redesign unittest to be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
svengoldberg committed Oct 17, 2024
1 parent 8bcf478 commit 791924b
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions tests/unittests/tiglWingCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ TEST(WingCell, IssueCellsNoOverlap)

ReturnCode tixiRet;
TiglReturnCode tiglRet;
Standard_Real first1, last1, first2, last2;
gp_Pnt pntCurve1, pntCurve2;

TiglCPACSConfigurationHandle tiglHandle = -1;
TixiDocumentHandle tixiHandle = -1;
Expand All @@ -133,13 +135,37 @@ TEST(WingCell, IssueCellsNoOverlap)
TopoDS_Shape cellLoft1 = cell1.GetLoft()->Shape();

auto& cell2 = uid_mgr.ResolveObject<tigl::CCPACSWingCell>(cell2Name.c_str());

TopoDS_Shape cellLoft2 = cell2.GetLoft()->Shape();
TopoDS_Shape cellCut = CutShapes(cellLoft1, cellLoft2);
TopTools_IndexedMapOfShape faces;
TopExp::MapShapes (cellCut, TopAbs_EDGE, faces);

// Test whether the cut of the two cells is only one line and not an area
// Therefore count the edges, must be equal to one
ASSERT_EQ(1, faces.Extent());
// Take the outermost edge of the first cell and the innermost edge of the second cell which should be compared
// If these edges are identical, the cut of the cells is exactely defined by this edge
// Hence, the cells have no overlap
// In the following, the edges are compared by comparing three points at parameters 0, 0.5 and 1
// If the resulting points are pairwise the same (up to tolerance), the edges are the same and the cells do not overlap
TopTools_IndexedMapOfShape edges1, edges2;
TopExp::MapShapes (cellLoft1, TopAbs_EDGE, edges1);
TopExp::MapShapes (cellLoft2, TopAbs_EDGE, edges2);

TopoDS_Edge edge1 = TopoDS::Edge(edges1(8)); // Since the cell is defined on two segments, it consists of two faces (-> 8 edges)
TopoDS_Edge edge2 = TopoDS::Edge(edges2(2));
Handle(Geom_BSplineCurve) curve1 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(edge1, first1, last1));
Handle(Geom_BSplineCurve) curve2 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(edge2, first2, last2));

curve1->D0(0., pntCurve1);
curve2->D0(0., pntCurve2);
ASSERT_NEAR(pntCurve1.X(), pntCurve2.X(), 1e-3);
ASSERT_NEAR(pntCurve1.Y(), pntCurve2.Y(), 1e-3);
ASSERT_NEAR(pntCurve1.Z(), pntCurve2.Z(), 1e-3);

curve1->D0(0.5, pntCurve1);
curve2->D0(0.5, pntCurve2);
ASSERT_NEAR(pntCurve1.X(), pntCurve2.X(), 1e-3);
ASSERT_NEAR(pntCurve1.Y(), pntCurve2.Y(), 1e-3);
ASSERT_NEAR(pntCurve1.Z(), pntCurve2.Z(), 1e-3);

curve1->D0(1., pntCurve1);
curve2->D0(1., pntCurve2);
ASSERT_NEAR(pntCurve1.X(), pntCurve2.X(), 1e-3);
ASSERT_NEAR(pntCurve1.Y(), pntCurve2.Y(), 1e-3);
ASSERT_NEAR(pntCurve1.Z(), pntCurve2.Z(), 1e-3);
}

0 comments on commit 791924b

Please sign in to comment.