diff --git a/src/BRepBndLib/BRepBndLib.cxx b/src/BRepBndLib/BRepBndLib.cxx index e8e3a98708..f3ab8ed860 100644 --- a/src/BRepBndLib/BRepBndLib.cxx +++ b/src/BRepBndLib/BRepBndLib.cxx @@ -127,6 +127,14 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next()) { const TopoDS_Edge& E = TopoDS::Edge(ex.Current()); + + if (!useTriangulation && BRep_Tool::IsGeometric(E)) + { + BC.Initialize(E); + BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(E), B); + continue; + } + Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l); if (!P3d.IsNull() && P3d->NbNodes() > 0) { @@ -143,7 +151,7 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria else { BRep_Tool::PolygonOnTriangulation(E, Poly, T, l); - if (useTriangulation && !Poly.IsNull() && !T.IsNull() && T->NbNodes() > 0) + if (!Poly.IsNull() && !T.IsNull() && T->NbNodes() > 0) { const TColStd_Array1OfInteger& Indices = Poly->Nodes(); nbNodes = Indices.Length(); diff --git a/src/BRepTest/BRepTest_CurveCommands.cxx b/src/BRepTest/BRepTest_CurveCommands.cxx index b0f58d031e..4bd39be3b7 100644 --- a/src/BRepTest/BRepTest_CurveCommands.cxx +++ b/src/BRepTest/BRepTest_CurveCommands.cxx @@ -281,9 +281,11 @@ static Standard_Integer mkedge(Draw_Interpretor& di, Standard_Integer n, const c Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]); Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]); - if (C.IsNull() && C2d.IsNull()) { + Handle(Poly_Polygon3D) P3d = DrawTrSurf::GetPolygon3D(a[2]); + + if (C.IsNull() && C2d.IsNull() && P3d.IsNull()) { //std::cout << a[2] << " is not a curve" << std::endl; - di << a[2] << " is not a curve\n"; + di << a[2] << " is not a curve or polygon 3d\n"; return 1; } @@ -291,7 +293,12 @@ static Standard_Integer mkedge(Draw_Interpretor& di, Standard_Integer n, const c if (n == 3) { if (!C.IsNull()) edge = BRepBuilderAPI_MakeEdge(C); - else edge = BRepBuilderAPI_MakeEdge2d(C2d); + else if (!C2d.IsNull()) edge = BRepBuilderAPI_MakeEdge2d(C2d); + else + { + BRep_Builder aBB; + aBB.MakeEdge(edge, P3d); + } } else { Handle(Geom_Surface) S; diff --git a/tests/lowalgos/bnd/bug30292 b/tests/lowalgos/bnd/bug30292 new file mode 100644 index 0000000000..4bc136f9eb --- /dev/null +++ b/tests/lowalgos/bnd/bug30292 @@ -0,0 +1,68 @@ +puts "========" +puts "0030292: Modeling Algorithms - BRepBndLib should avoid using Poly_Polygon3D when called with useTriangulation set to false" +puts "========" +puts "" + +## geometric edge without any discrete representations + +circle c 0 0 0 1 +mkedge e c +set res1 [bounding e] +set res2 [bounding e -noTriangulation] +if {$res1 != $res2} { + puts "Error: bounding boxes are different for geometric edge" +} + +## geometric edge with polygon 3d + +incmesh e 0.1 +set res1_ref "-1.1000000999999999 -1.0927089740980542 -0.10000010000000001 1.1000000999999999 1.092708974098054 0.10000010000000001" +set res2_ref "-1.0000001000000001 -1.0000001000000001 -9.9999999999999995e-08 1.0000001000000001 1.0000001000000001 9.9999999999999995e-08" +unset res1 +set res1 [bounding e] +foreach dd $res1 { + if ![regexp $dd $res1_ref] { + puts "Error: bounding box is wrong" + } +} +unset res2 +set res2 [bounding e -noTriangulation] +foreach dd $res2 { + if ![regexp $dd $res2_ref] { + puts "Error: bounding box is wrong" + } +} + +## geometric edge with polygon on triangulation + +pcylinder cyl 1 1 +incmesh cyl 0.1 +explode cyl e +renamevar cyl_3 e +unset res1 +set res1 [bounding e] +foreach dd $res1 { + if ![regexp $dd $res1_ref] { + puts "Error: bounding box is wrong" + } +} +unset res2 +set res2 [bounding e -noTriangulation] +foreach dd $res2 { + if ![regexp $dd $res2_ref] { + puts "Error: bounding box is wrong" + } +} + +## not geometric edge with polygon 3d + +polygon3d pol3d 5 1 0 0 0 1 0 -1 0 0 0 -1 0 1 0 0 +mkedge e pol3d +unset res1 +set res1 [bounding e] +unset res2 +set res2 [bounding e -noTriangulation] +if {$res1 != $res2} { + puts "Error: bounding boxes are different for not geometric edge" +} +