From f57577d01bdd950a0c29de5ba6eb2fd38d88d267 Mon Sep 17 00:00:00 2001 From: Ruud Swinkels Date: Wed, 18 Oct 2023 19:27:37 +0200 Subject: [PATCH] add chamfer direction for 2d Wire --- src/build123d/operations_generic.py | 2 +- src/build123d/topology.py | 14 +++++++++----- tests/test_direct_api.py | 7 +++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/build123d/operations_generic.py b/src/build123d/operations_generic.py index 8e10638..a54dc5b 100644 --- a/src/build123d/operations_generic.py +++ b/src/build123d/operations_generic.py @@ -360,7 +360,7 @@ def chamfer( ), object_list, ) - new_wire = target.chamfer_2d(length, length2, object_list) + new_wire = target.chamfer_2d(length, length2, object_list, edge) if context is not None: context._add_to_context(new_wire, mode=Mode.REPLACE) return new_wire diff --git a/src/build123d/topology.py b/src/build123d/topology.py index be083f7..3ecc65b 100644 --- a/src/build123d/topology.py +++ b/src/build123d/topology.py @@ -5464,9 +5464,11 @@ class Face(Shape): """Apply 2D chamfer to a face Args: - distance: float: - distance2: float: - vertices: Iterable[Vertex]: + distance (float): chamfer length + distance2 (float): chamfer length + vertices (Iterable[Vertex]): vertices to chamfer + edge (Edge): identifies the side where length is measured. The virtices must be + part of the edge Returns: @@ -6907,7 +6909,7 @@ class Wire(Shape, Mixin1D): return Face.make_from_wires(self).fillet_2d(radius, vertices).outer_wire() def chamfer_2d( - self, distance: float, distance2: float, vertices: Iterable[Vertex] + self, distance: float, distance2: float, vertices: Iterable[Vertex], edge:Edge = None ) -> Wire: """chamfer_2d @@ -6917,13 +6919,15 @@ class Wire(Shape, Mixin1D): distance (float): chamfer length distance2 (float): chamfer length vertices (Iterable[Vertex]): vertices to chamfer + edge (Edge): identifies the side where length is measured. The virtices must be + part of the edge Returns: Wire: chamfered wire """ return ( Face.make_from_wires(self) - .chamfer_2d(distance, distance2, vertices) + .chamfer_2d(distance, distance2, vertices, edge) .outer_wire() ) diff --git a/tests/test_direct_api.py b/tests/test_direct_api.py index 182ac75..15249e1 100644 --- a/tests/test_direct_api.py +++ b/tests/test_direct_api.py @@ -3283,6 +3283,13 @@ class TestWire(DirectApiTestCase): squaroid.length, 4 * (1 - 2 * 0.1 + 0.1 * math.sqrt(2)), 5 ) + def test_chamfer_2d_edge(self): + square = Wire.make_rect(1, 1) + edge = square.edges().sort_by(Axis.Y)[0] + vertex = edge.vertices().sort_by(Axis.X)[0] + square = square.chamfer_2d(distance=0.1, distance2=0.2,vertices=[vertex], edge=edge) + self.assertAlmostEqual(square.edges().sort_by(Axis.Y)[0].length, 0.9) + def test_make_convex_hull(self): # overlapping_edges = [ # Edge.make_circle(10, end_angle=60),