Renaming Face.total_area to area_without_holes & Face.remove_holes to without_holes

This commit is contained in:
gumyr 2025-02-06 11:01:38 -05:00
parent 6e0af24b21
commit 2247ea9303
2 changed files with 28 additions and 28 deletions

View file

@ -505,7 +505,7 @@ class Face(Mixin2D, Shape[TopoDS_Face]):
return result
@property
def total_area(self) -> float:
def area_without_holes(self) -> float:
"""
Calculate the total surface area of the face, including the areas of any holes.
@ -519,7 +519,7 @@ class Face(Mixin2D, Shape[TopoDS_Face]):
if self.wrapped is None:
return 0.0
return self.remove_holes().area
return self.without_holes().area
@property
def volume(self) -> float:
@ -1317,8 +1317,24 @@ class Face(Mixin2D, Shape[TopoDS_Face]):
projected_shapes.append(shape)
return projected_shapes
def remove_holes(self) -> Face:
"""remove_holes
def to_arcs(self, tolerance: float = 1e-3) -> Face:
"""to_arcs
Approximate planar face with arcs and straight line segments.
Args:
tolerance (float, optional): Approximation tolerance. Defaults to 1e-3.
Returns:
Face: approximated face
"""
if self.wrapped is None:
raise ValueError("Cannot approximate an empty shape")
return self.__class__.cast(BRepAlgo.ConvertFace_s(self.wrapped, tolerance))
def without_holes(self) -> Face:
"""without_holes
Remove all of the holes from this face.
@ -1339,22 +1355,6 @@ class Face(Mixin2D, Shape[TopoDS_Face]):
holeless.wrapped = modified_shape
return holeless
def to_arcs(self, tolerance: float = 1e-3) -> Face:
"""to_arcs
Approximate planar face with arcs and straight line segments.
Args:
tolerance (float, optional): Approximation tolerance. Defaults to 1e-3.
Returns:
Face: approximated face
"""
if self.wrapped is None:
raise ValueError("Cannot approximate an empty shape")
return self.__class__.cast(BRepAlgo.ConvertFace_s(self.wrapped, tolerance))
def wire(self) -> Wire:
"""Return the outerwire, generate a warning if inner_wires present"""
if self.inner_wires():

View file

@ -453,10 +453,10 @@ class TestFace(unittest.TestCase):
face = Cylinder(1, 1).faces().filter_by(GeomType.CYLINDER)[0]
self.assertAlmostEqual(face.normal_at(0, 1), (1, 0, 0), 5)
def test_remove_holes(self):
def test_without_holes(self):
# Planar test
frame = (Rectangle(1, 1) - Rectangle(0.5, 0.5)).face()
filled = frame.remove_holes()
filled = frame.without_holes()
self.assertEqual(len(frame.inner_wires()), 1)
self.assertEqual(len(filled.inner_wires()), 0)
self.assertAlmostEqual(frame.area, 0.75, 5)
@ -465,11 +465,11 @@ class TestFace(unittest.TestCase):
# Errors
frame.wrapped = None
with self.assertRaises(ValueError):
frame.remove_holes()
frame.without_holes()
# No holes
rect = Face.make_rect(1, 1)
self.assertEqual(rect, rect.remove_holes())
self.assertEqual(rect, rect.without_holes())
# Non-planar test
cyl_face = (
@ -477,16 +477,16 @@ class TestFace(unittest.TestCase):
.faces()
.sort_by(Face.area)[-1]
)
filled = cyl_face.remove_holes()
filled = cyl_face.without_holes()
self.assertEqual(len(cyl_face.inner_wires()), 2)
self.assertEqual(len(filled.inner_wires()), 0)
self.assertTrue(cyl_face.area < filled.area)
self.assertAlmostEqual(cyl_face.total_area, filled.area, 5)
self.assertAlmostEqual(cyl_face.area_without_holes, filled.area, 5)
def test_total_area(self):
def test_area_without_holes(self):
frame = (Rectangle(1, 1) - Rectangle(0.5, 0.5)).face()
frame.wrapped = None
self.assertAlmostEqual(frame.total_area, 0.0, 5)
self.assertAlmostEqual(frame.area_without_holes, 0.0, 5)
def test_axes_of_symmetry(self):
# Empty shape