add chamfer bad weather tests

This commit is contained in:
Ruud Swinkels 2023-10-13 18:42:53 +02:00
parent ae3a327361
commit 723d02db17
4 changed files with 40 additions and 6 deletions

View file

@ -278,6 +278,8 @@ def chamfer(
ValueError: no objects provided
ValueError: objects must be Edges
ValueError: objects must be Vertices
ValueError: Only one of length2 or angle should be provided
ValueError: Face can only be used in conjunction with length2 or angle
"""
context: Builder = Builder._get_context("chamfer")
if length2 and angle:

View file

@ -1106,6 +1106,10 @@ class Mixin3D:
Returns:
Any: Chamfered solid
"""
if face:
if any((edge for edge in edge_list if edge not in face.edges())):
raise ValueError("Some edges are not part of the face")
native_edges = [e.wrapped for e in edge_list]
# make a edge --> faces mapping
@ -1138,14 +1142,10 @@ class Mixin3D:
new_shape = self.__class__(chamfer_builder.Shape())
if not new_shape.is_valid():
raise Standard_Failure
except StdFail_NotDone as err:
except (StdFail_NotDone, Standard_Failure) as err:
raise ValueError(
"Failed creating a chamfer, try a smaller length value(s)"
) from err
except Standard_Failure as err:
if face:
raise ValueError("Some edges are not part of the face") from err
raise ValueError(str(err)) from err
return new_shape

View file

@ -242,6 +242,15 @@ class ChamferTests(unittest.TestCase):
chamfer(face.edge(), length=1, angle=60,face=face)
self.assertAlmostEqual(test.part.volume, 1000 - 1 * 0.5 * 10 * sqrt(3), 5)
def test_part_chamfer_face_without_length2_or_angel(self):
with BuildPart() as test:
Box(10, 10, 10)
face = test.faces().sort_by(Axis.Z)[-1]
self.assertRaises(ValueError, chamfer, face.edge(), length=1, face=face)
def test_part_chamfer_face_no_objects(self):
self.assertRaises(ValueError, chamfer, None, length=1)
def test_sketch_chamfer(self):
with BuildSketch() as test:
Rectangle(10, 10)

View file

@ -1815,12 +1815,35 @@ class TestMixin1D(DirectApiTestCase):
class TestMixin3D(DirectApiTestCase):
"""Test that 3D add ins"""
def test_chamfer(self):
box = Solid.make_box(1, 1, 1)
chamfer_box = box.chamfer(0.1, None, box.edges().sort_by(Axis.Z)[-1:])
self.assertAlmostEqual(chamfer_box.volume, 1 - 0.005, 5)
def test_chamfer_asym_length(self):
box = Solid.make_box(1, 1, 1)
chamfer_box = box.chamfer(0.1, 0.2, box.edges().sort_by(Axis.Z)[-1:])
self.assertAlmostEqual(chamfer_box.volume, 1 - 0.01, 5)
def test_chamfer_asym_length_with_face(self):
box = Solid.make_box(1, 1, 1)
face = box.faces().sort_by(Axis.Z)[0]
edge = [face.edges().sort_by(Axis.Y)[0]]
chamfer_box = box.chamfer(0.1, 0.2, edge, face=face)
self.assertAlmostEqual(chamfer_box.volume, 1 - 0.01, 5)
def test_chamfer_too_high_length(self):
box = Solid.make_box(1, 1, 1)
face = box.faces
self.assertRaises(ValueError, box.chamfer, 2, None, box.edges().sort_by(Axis.Z)[-1:])
def test_chamfer_edge_not_part_of_face(self):
box = Solid.make_box(1, 1, 1)
edge = box.edges().sort_by(Axis.Z)[-1:]
face = box.faces().sort_by(Axis.Z)[0]
self.assertRaises(ValueError, box.chamfer, 0.1, None, edge, face=face)
def test_hollow(self):
shell_box = Solid.make_box(1, 1, 1).hollow([], thickness=-0.1)
self.assertAlmostEqual(shell_box.volume, 1 - 0.8**3, 5)