Skip to content

Commit

Permalink
Fixed intersections of Axis Issue #615
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Jun 19, 2024
1 parent 4561105 commit 2c40e19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
10 changes: 10 additions & 0 deletions tests/test_direct_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2c40e19

Please sign in to comment.