mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 02:30:55 -08:00
Correct area/volume calculations from intersect with new return type of ShapeList
This commit is contained in:
parent
c13ef47cef
commit
315605f485
7 changed files with 20 additions and 18 deletions
|
|
@ -453,7 +453,7 @@ class DimensionLine(BaseSketchObject):
|
|||
if self_intersection is None:
|
||||
self_intersection_area = 0.0
|
||||
else:
|
||||
self_intersection_area = self_intersection.area
|
||||
self_intersection_area = sum(f.area for f in self_intersection.faces())
|
||||
d_line += placed_label
|
||||
bbox_size = d_line.bounding_box().diagonal
|
||||
|
||||
|
|
@ -467,7 +467,7 @@ class DimensionLine(BaseSketchObject):
|
|||
if line_intersection is None:
|
||||
common_area = 0.0
|
||||
else:
|
||||
common_area = line_intersection.area
|
||||
common_area = sum(f.area for f in line_intersection.faces())
|
||||
common_area += self_intersection_area
|
||||
score = (d_line.area - 10 * common_area) / bbox_size
|
||||
d_lines[d_line] = score
|
||||
|
|
|
|||
|
|
@ -649,11 +649,7 @@ class Compound(Mixin3D, Shape[TopoDS_Compound]):
|
|||
children[child_index_pair[1]]
|
||||
)
|
||||
if obj_intersection is not None:
|
||||
common_volume = (
|
||||
0.0
|
||||
if isinstance(obj_intersection, list)
|
||||
else obj_intersection.volume
|
||||
)
|
||||
common_volume = sum(s.volume for s in obj_intersection.solids())
|
||||
if common_volume > tolerance:
|
||||
return (
|
||||
True,
|
||||
|
|
|
|||
|
|
@ -778,15 +778,13 @@ class Face(Mixin2D, Shape[TopoDS_Face]):
|
|||
).sort_by(Axis(cog, cross_dir))
|
||||
|
||||
bottom_area = sum(f.area for f in bottom_list)
|
||||
intersect_area = 0.0
|
||||
for flipped_face, bottom_face in zip(top_flipped_list, bottom_list):
|
||||
intersection = flipped_face.intersect(bottom_face)
|
||||
if intersection is None or isinstance(intersection, list):
|
||||
if intersection is None:
|
||||
intersect_area = -1.0
|
||||
break
|
||||
else:
|
||||
assert isinstance(intersection, Face)
|
||||
intersect_area += intersection.area
|
||||
intersect_area = sum(f.area for f in intersection.faces())
|
||||
|
||||
if intersect_area == -1.0:
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -229,13 +229,15 @@ class TestOrientedBoundBox(unittest.TestCase):
|
|||
obb = OrientedBoundBox(rect)
|
||||
corners = obb.corners
|
||||
poly = Polygon(*corners, align=None)
|
||||
self.assertAlmostEqual(rect.intersect(poly).area, rect.area, 5)
|
||||
area = sum(f.area for f in rect.intersect(poly).faces())
|
||||
self.assertAlmostEqual(area, rect.area, 5)
|
||||
|
||||
for face in Box(1, 2, 3).faces():
|
||||
obb = OrientedBoundBox(face)
|
||||
corners = obb.corners
|
||||
poly = Polygon(*corners, align=None)
|
||||
self.assertAlmostEqual(face.intersect(poly).area, face.area, 5)
|
||||
area = sum(f.area for f in face.intersect(poly).faces())
|
||||
self.assertAlmostEqual(area, face.area, 5)
|
||||
|
||||
def test_line_corners(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -299,7 +299,8 @@ class TestShape(unittest.TestCase):
|
|||
predicted_location = Location(offset) * Rotation(*rotation)
|
||||
located_shape = Solid.make_box(1, 1, 1).locate(predicted_location)
|
||||
intersect = shape.intersect(located_shape)
|
||||
self.assertAlmostEqual(intersect.volume, 1, 5)
|
||||
volume = sum(s.volume for s in intersect.solids())
|
||||
self.assertAlmostEqual(volume, 1, 5)
|
||||
|
||||
def test_position_and_orientation(self):
|
||||
box = Solid.make_box(1, 1, 1).locate(Location((1, 2, 3), (10, 20, 30)))
|
||||
|
|
@ -588,7 +589,7 @@ class TestShape(unittest.TestCase):
|
|||
empty.distance_to_with_closest_points(Vector(1, 1, 1))
|
||||
with self.assertRaises(ValueError):
|
||||
empty.distance_to(Vector(1, 1, 1))
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(AttributeError):
|
||||
box.intersect(empty_loc)
|
||||
self.assertEqual(empty._ocp_section(Vertex(1, 1, 1)), ([], []))
|
||||
self.assertEqual(empty.faces_intersected_by_axis(Axis.Z), ShapeList())
|
||||
|
|
|
|||
|
|
@ -153,7 +153,9 @@ class TestSolid(unittest.TestCase):
|
|||
self.assertAlmostEqual(twist.volume, 1, 5)
|
||||
top = twist.faces().sort_by(Axis.Z)[-1].rotate(Axis.Z, 45)
|
||||
bottom = twist.faces().sort_by(Axis.Z)[0]
|
||||
self.assertAlmostEqual(top.translate((0, 0, -1)).intersect(bottom).area, 1, 5)
|
||||
intersect = top.translate((0, 0, -1)).intersect(bottom)
|
||||
area = sum(f.area for f in intersect.faces())
|
||||
self.assertAlmostEqual(area, 1, 5)
|
||||
# Wire
|
||||
base = Wire.make_rect(1, 1)
|
||||
twist = Solid.extrude_linear_with_rotation(
|
||||
|
|
@ -162,7 +164,9 @@ class TestSolid(unittest.TestCase):
|
|||
self.assertAlmostEqual(twist.volume, 1, 5)
|
||||
top = twist.faces().sort_by(Axis.Z)[-1].rotate(Axis.Z, 45)
|
||||
bottom = twist.faces().sort_by(Axis.Z)[0]
|
||||
self.assertAlmostEqual(top.translate((0, 0, -1)).intersect(bottom).area, 1, 5)
|
||||
intersect = top.translate((0, 0, -1)).intersect(bottom)
|
||||
area = sum(f.area for f in intersect.faces())
|
||||
self.assertAlmostEqual(area, 1, 5)
|
||||
|
||||
def test_make_loft(self):
|
||||
loft = Solid.make_loft(
|
||||
|
|
|
|||
|
|
@ -231,7 +231,8 @@ class DimensionLineTestCase(unittest.TestCase):
|
|||
],
|
||||
draft=metric,
|
||||
)
|
||||
self.assertGreater(hole.intersect(d_line).area, 0)
|
||||
area = sum(f.area for f in hole.intersect(d_line).faces())
|
||||
self.assertGreater(area, 0)
|
||||
|
||||
def test_outside_arrows(self):
|
||||
d_line = DimensionLine([(0, 0, 0), (15, 0, 0)], draft=metric)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue