Skip to content

Commit b7f4b79

Browse files
committed
Add test for plane boundaryBox where TopoDS_Shape is neither vertex, edge or surface
1 parent 8210518 commit b7f4b79

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/Core/Geom/OCCHelper.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,15 +1004,37 @@ computeBoundingBox(const TopoDS_Shape& shape, gp_Pnt& pmin, gp_Pnt& pmax)
10041004
{
10051005
Bnd_Box box;
10061006
BRepCheck_Analyzer analyzer(shape);
1007+
10071008
if (analyzer.IsValid()) {
10081009
BRepBndLib::AddClose(shape, box);
10091010
} else {
10101011
BRepBndLib::AddOptimal(shape, box);
10111012
}
10121013

10131014
if (box.IsVoid())
1015+
{
10141016
BRepBndLib::Add(shape, box);
1017+
}
10151018

1019+
TopAbs_ShapeEnum type = shape.ShapeType();
1020+
if (type != TopAbs_FACE && type != TopAbs_EDGE && type != TopAbs_VERTEX)
1021+
{
1022+
// On teste si la box est plane
1023+
// Récupérer les coins min et max
1024+
gp_Pnt minCorner = box.CornerMin();
1025+
gp_Pnt maxCorner = box.CornerMax();
1026+
1027+
// Calculer les dimensions
1028+
double width = maxCorner.X() - minCorner.X();
1029+
double height = maxCorner.Y() - minCorner.Y();
1030+
double depth = maxCorner.Z() - minCorner.Z();
1031+
1032+
// Vérifier si l'une des dimensions est nulle ou quasi-nulle
1033+
double tolerance = 1e-7;
1034+
if (width < tolerance || height < tolerance || depth < tolerance) {
1035+
BRepBndLib::Add(shape, box);
1036+
}
1037+
}
10161038
double xmin, ymin, zmin, xmax, ymax, zmax;
10171039
box.Get(xmin, ymin, zmin, xmax, ymax, zmax);
10181040
pmin.SetCoord(xmin, ymin, zmin);

test_link/test_issue262.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pyMagix3D as Mgx3D
2+
import math
3+
4+
# Issue262 : Le bloc créé oar boite englobante d'un volume peut avoir de mauvaises dimensions
5+
# la création d'un bloc sur une sphère crée un bloc plat
6+
7+
def assertPoint(tm, name, x, y, z):
8+
p = tm.getCoord(name)
9+
assert math.isclose(p.getX(), x, rel_tol=1e-7)
10+
assert math.isclose(p.getY(), y, rel_tol=1e-7)
11+
assert math.isclose(p.getZ(), z, rel_tol=1e-7)
12+
13+
def test_issue262():
14+
ctx = Mgx3D.getStdContext()
15+
ctx.clearSession() # Clean the session after the previous test
16+
gm = ctx.getGeomManager()
17+
tm = ctx.getTopoManager()
18+
# Création du volume Vol0000
19+
gm.newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.ENTIER)
20+
# Création d'un bloc topologique structuré sans projection (Vol0000)
21+
tm.newFreeTopoOnGeometry ("Vol0000")
22+
# Annulation de : Création d'un bloc topologique structuré sans projection (Vol0000)
23+
ctx.undo()
24+
# Création d'un bloc unitaire mis dans le groupe AAA
25+
ctx.getTopoManager().newFreeBoundedTopoInGroup ("AAA", 3, ["Vol0000"])
26+
27+
assertPoint(tm, "Som0000", -1, -1, -1)
28+
assertPoint(tm, "Som0007", 1, 1, 1)

0 commit comments

Comments
 (0)