Testing - Add unit tests for geometric classes and conversions (#1099)

- Introduced new tests for TopExp class to validate shape mapping and vertex retrieval.
- Added tests for Geom_Circle, Geom_Line, and Geom_Plane classes to ensure correct geometric behavior and transformations.
- Implemented tests for GCPnts_AbscissaPoint to verify length calculations and parameter retrieval for lines and circles.
- Created conversion tests in GeomConvert to check the accuracy of converting geometric entities to B-spline representations.
- Updated CMake files to include new test files for the added tests.
This commit is contained in:
Pasukhin Dmitry
2026-02-20 20:25:09 +00:00
committed by GitHub
parent e72d772e70
commit e384f0bb93
44 changed files with 4243 additions and 26 deletions

View File

@@ -0,0 +1,160 @@
// Copyright (c) 2025 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRep_Tool.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Surface.hxx>
#include <gp.hxx>
#include <gp_Ax2.hxx>
#include <gp_Pnt.hxx>
#include <Precision.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <gtest/gtest.h>
TEST(BRep_Tool_Test, Pnt_FromVertex)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_VERTEX);
ASSERT_TRUE(anExp.More());
const TopoDS_Vertex& aVertex = TopoDS::Vertex(anExp.Current());
gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
// The point coordinates should be within the box bounds [0,10] x [0,20] x [0,30]
EXPECT_GE(aPnt.X(), -Precision::Confusion());
EXPECT_LE(aPnt.X(), 10.0 + Precision::Confusion());
EXPECT_GE(aPnt.Y(), -Precision::Confusion());
EXPECT_LE(aPnt.Y(), 20.0 + Precision::Confusion());
EXPECT_GE(aPnt.Z(), -Precision::Confusion());
EXPECT_LE(aPnt.Z(), 30.0 + Precision::Confusion());
}
TEST(BRep_Tool_Test, Tolerance_Vertex)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_VERTEX);
ASSERT_TRUE(anExp.More());
const TopoDS_Vertex& aVertex = TopoDS::Vertex(anExp.Current());
double aTol = BRep_Tool::Tolerance(aVertex);
EXPECT_GE(aTol, 0.0);
}
TEST(BRep_Tool_Test, Tolerance_Edge)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_EDGE);
ASSERT_TRUE(anExp.More());
const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
double aTol = BRep_Tool::Tolerance(anEdge);
EXPECT_GE(aTol, 0.0);
}
TEST(BRep_Tool_Test, Tolerance_Face)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_FACE);
ASSERT_TRUE(anExp.More());
const TopoDS_Face& aFace = TopoDS::Face(anExp.Current());
double aTol = BRep_Tool::Tolerance(aFace);
EXPECT_GE(aTol, 0.0);
}
TEST(BRep_Tool_Test, Curve_FromEdge)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_EDGE);
ASSERT_TRUE(anExp.More());
const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
double aFirst = 0.0;
double aLast = 0.0;
occ::handle<Geom_Curve> aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
EXPECT_FALSE(aCurve.IsNull()) << "Curve from a box edge should not be null";
EXPECT_LT(aFirst, aLast) << "First parameter should be less than last parameter";
}
TEST(BRep_Tool_Test, Surface_FromFace)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_FACE);
ASSERT_TRUE(anExp.More());
const TopoDS_Face& aFace = TopoDS::Face(anExp.Current());
occ::handle<Geom_Surface> aSurface = BRep_Tool::Surface(aFace);
EXPECT_FALSE(aSurface.IsNull()) << "Surface from a box face should not be null";
}
TEST(BRep_Tool_Test, IsClosed_CircleEdge)
{
occ::handle<Geom_Circle> aCircle = new Geom_Circle(gp_Ax2(gp_Pnt(0.0, 0.0, 0.0), gp::DZ()), 5.0);
BRepBuilderAPI_MakeEdge anEdgeMaker(aCircle);
ASSERT_TRUE(anEdgeMaker.IsDone());
const TopoDS_Edge& anEdge = anEdgeMaker.Edge();
EXPECT_TRUE(BRep_Tool::IsClosed(anEdge)) << "A full circle edge should be closed";
}
TEST(BRep_Tool_Test, IsClosed_LineEdge)
{
BRepBuilderAPI_MakeEdge anEdgeMaker(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(10.0, 0.0, 0.0));
ASSERT_TRUE(anEdgeMaker.IsDone());
const TopoDS_Edge& anEdge = anEdgeMaker.Edge();
EXPECT_FALSE(BRep_Tool::IsClosed(anEdge)) << "A line segment edge should not be closed";
}
TEST(BRep_Tool_Test, Degenerated)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_EDGE);
ASSERT_TRUE(anExp.More());
const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
EXPECT_FALSE(BRep_Tool::Degenerated(anEdge)) << "Box edges should not be degenerated";
}

View File

@@ -2,7 +2,9 @@
set(OCCT_TKBRep_GTests_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}")
set(OCCT_TKBRep_GTests_FILES
BRep_Tool_Test.cxx
BRepAdaptor_CompCurve_Test.cxx
TopExp_Test.cxx
TopoDS_Builder_Test.cxx
TopoDS_Edge_Test.cxx
TopoDS_Iterator_Test.cxx

View File

@@ -0,0 +1,152 @@
// Copyright (c) 2025 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRepPrimAPI_MakeBox.hxx>
#include <gp_Pnt.hxx>
#include <NCollection_IndexedDataMap.hxx>
#include <NCollection_IndexedMap.hxx>
#include <NCollection_List.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ShapeMapHasher.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <gtest/gtest.h>
TEST(TopExp_Test, MapShapes_Faces)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> aFaceMap;
TopExp::MapShapes(aBox, TopAbs_FACE, aFaceMap);
EXPECT_EQ(aFaceMap.Extent(), 6) << "A box should have exactly 6 faces";
}
TEST(TopExp_Test, MapShapes_Edges)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> anEdgeMap;
TopExp::MapShapes(aBox, TopAbs_EDGE, anEdgeMap);
EXPECT_EQ(anEdgeMap.Extent(), 12) << "A box should have exactly 12 edges";
}
TEST(TopExp_Test, MapShapes_Vertices)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> aVertexMap;
TopExp::MapShapes(aBox, TopAbs_VERTEX, aVertexMap);
EXPECT_EQ(aVertexMap.Extent(), 8) << "A box should have exactly 8 vertices";
}
TEST(TopExp_Test, FirstVertex_LastVertex)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_EDGE);
ASSERT_TRUE(anExp.More());
const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
TopoDS_Vertex aFirstVertex = TopExp::FirstVertex(anEdge);
TopoDS_Vertex aLastVertex = TopExp::LastVertex(anEdge);
EXPECT_FALSE(aFirstVertex.IsNull()) << "First vertex should not be null";
EXPECT_FALSE(aLastVertex.IsNull()) << "Last vertex should not be null";
EXPECT_FALSE(aFirstVertex.IsSame(aLastVertex))
<< "First and last vertices of a box edge should be distinct";
}
TEST(TopExp_Test, Vertices)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
TopExp_Explorer anExp(aBox, TopAbs_EDGE);
ASSERT_TRUE(anExp.More());
const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
TopoDS_Vertex aV1, aV2;
TopExp::Vertices(anEdge, aV1, aV2);
EXPECT_FALSE(aV1.IsNull()) << "First vertex from Vertices() should not be null";
EXPECT_FALSE(aV2.IsNull()) << "Second vertex from Vertices() should not be null";
}
TEST(TopExp_Test, CommonVertex)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> anEdgeMap;
TopExp::MapShapes(aBox, TopAbs_EDGE, anEdgeMap);
ASSERT_GE(anEdgeMap.Extent(), 2);
// Find two adjacent edges (sharing a common vertex)
bool isFound = false;
for (int i = 1; i <= anEdgeMap.Extent() && !isFound; ++i)
{
const TopoDS_Edge& anEdge1 = TopoDS::Edge(anEdgeMap(i));
for (int j = i + 1; j <= anEdgeMap.Extent() && !isFound; ++j)
{
const TopoDS_Edge& anEdge2 = TopoDS::Edge(anEdgeMap(j));
TopoDS_Vertex aCommonVertex;
if (TopExp::CommonVertex(anEdge1, anEdge2, aCommonVertex))
{
EXPECT_FALSE(aCommonVertex.IsNull()) << "Common vertex should not be null";
isFound = true;
}
}
}
EXPECT_TRUE(isFound) << "Should find at least one pair of adjacent edges in a box";
}
TEST(TopExp_Test, MapShapesAndAncestors)
{
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
const TopoDS_Shape& aBox = aBoxMaker.Shape();
ASSERT_TRUE(aBoxMaker.IsDone());
NCollection_IndexedDataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>
anEdgeFaceMap;
TopExp::MapShapesAndAncestors(aBox, TopAbs_EDGE, TopAbs_FACE, anEdgeFaceMap);
EXPECT_EQ(anEdgeFaceMap.Extent(), 12) << "A box should have 12 edges in the ancestor map";
// Each edge of a box is shared by exactly 2 faces
for (int i = 1; i <= anEdgeFaceMap.Extent(); ++i)
{
const NCollection_List<TopoDS_Shape>& aFaceList = anEdgeFaceMap(i);
EXPECT_EQ(aFaceList.Extent(), 2) << "Each box edge should be shared by exactly 2 faces";
}
}