From 2c40e19141992fc89fb241b47d1e637c7e56a596 Mon Sep 17 00:00:00 2001 From: gumyr Date: Wed, 19 Jun 2024 11:42:36 -0400 Subject: [PATCH] Fixed intersections of Axis Issue #615 --- src/build123d/topology.py | 18 ++++++++++-------- tests/test_direct_api.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/build123d/topology.py b/src/build123d/topology.py index d33ff4a4..128f7388 100644 --- a/src/build123d/topology.py +++ b/src/build123d/topology.py @@ -584,9 +584,10 @@ def common_plane(self, *lines: Union[Edge, Wire]) -> Union[None, Plane]: # Shorten any infinite lines (from converted Axis) normal_lines = list(filter(lambda line: line.length <= 1e50, all_lines)) infinite_lines = filter(lambda line: line.length > 1e50, all_lines) - shortened_lines = [ - l.trim(0.4999999999, 0.5000000001) for l in infinite_lines - ] + # shortened_lines = [ + # l.trim(0.4999999999, 0.5000000001) for l in infinite_lines + # ] + shortened_lines = [l.trim_to_length(0.5, 10) for l in infinite_lines] all_lines = normal_lines + shortened_lines for line in all_lines: @@ -4563,17 +4564,18 @@ def intersections( crosses = [plane.from_local_coords(p) for p in crosses] # crosses may contain points beyond the ends of the edge so - # filter those out (a param_at problem?) + # .. filter those out valid_crosses = [] for pnt in crosses: try: if edge is not None: - if (-tolerance <= self.param_at_point(pnt) <= 1.0 + tolerance) and ( - -tolerance <= edge.param_at_point(pnt) <= 1.0 + tolerance + if ( + self.distance_to(pnt) <= TOLERANCE + and edge.distance_to(pnt) <= TOLERANCE ): valid_crosses.append(pnt) else: - if -tolerance <= self.param_at_point(pnt) <= 1.0 + tolerance: + if self.distance_to(pnt) <= TOLERANCE: valid_crosses.append(pnt) except ValueError: pass # skip invalid points @@ -8675,7 +8677,7 @@ def _axis_intersect(self: Axis, *to_intersect: Union[Shape, Axis, Plane]) -> Sha # Check if there is an intersection point if int_cs.NbPoints() > 0: intersections.append(Vertex(*Vector(int_cs.Point(1)).to_tuple())) - if isinstance(intersector, Shape): + elif isinstance(intersector, Shape): intersections.extend(self_i_edge.intersect(intersector)) return ( diff --git a/tests/test_direct_api.py b/tests/test_direct_api.py index 85789cf2..557f77b5 100644 --- a/tests/test_direct_api.py +++ b/tests/test_direct_api.py @@ -317,6 +317,16 @@ def test_axis_intersect(self): intersection = Axis((1, 2, 3), (0, 0, 1)) & Plane.XY self.assertTupleAlmostEquals(intersection.to_tuple(), (1, 2, 0), 5) + arc = Edge.make_circle(20, start_angle=0, end_angle=180) + ax0 = Axis((-20, 30, 0), (4, -3, 0)) + intersections = arc.intersect(ax0).vertices().sort_by(Axis.X) + self.assertTupleAlmostEquals(tuple(intersections[0]), (-5.6, 19.2, 0), 5) + self.assertTupleAlmostEquals(tuple(intersections[1]), (20, 0, 0), 5) + + intersections = ax0.intersect(arc).vertices().sort_by(Axis.X) + self.assertTupleAlmostEquals(tuple(intersections[0]), (-5.6, 19.2, 0), 5) + self.assertTupleAlmostEquals(tuple(intersections[1]), (20, 0, 0), 5) + # TODO: uncomment when generalized edge to surface intersections are complete # non_planar = ( # Solid.make_cylinder(1, 10).faces().filter_by(GeomType.PLANE, reverse=True)