Skip to content

Commit

Permalink
ensure parents of joints are handled properly during deep coppy
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhard-42 committed Dec 8, 2023
1 parent 0bdaabb commit 534ddbb
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,9 @@ def __deepcopy__(self, memo) -> Self:
memo[id(self.wrapped)] = downcast(BRepBuilderAPI_Copy(self.wrapped).Shape())
for key, value in self.__dict__.items():
setattr(result, key, copy.deepcopy(value, memo))
if key == "joints":
for joint in result.joints.values():
joint.parent = result
return result

def __copy__(self) -> Self:
Expand Down Expand Up @@ -4358,14 +4361,12 @@ def intersections(
Returns:
ShapeList[Vector]: list of intersection points
"""
# Convert an Axis into an edge at least as large as self and Axis start point
# Convert an Axis into an edge at least as large as self
if isinstance(edge, Axis):
self_bbox_w_edge = self.bounding_box().add(
Vertex(edge.position).bounding_box()
)
self_bbox = self.bounding_box()
edge = Edge.make_line(
edge.position + edge.direction * (-1 * self_bbox_w_edge.diagonal),
edge.position + edge.direction * self_bbox_w_edge.diagonal,
edge.position + edge.direction * (-1 * self_bbox.diagonal),
edge.position + edge.direction * self_bbox.diagonal,
)
# To determine the 2D plane to work on
plane = self.common_plane(edge)
Expand Down Expand Up @@ -6788,13 +6789,9 @@ def trim(self, start: float, end: float) -> Wire:
trim_start_point = self.position_at(start)
trim_end_point = self.position_at(end)

# If this is really just an edge, skip the complexity of a Wire
if len(self.edges()) == 1:
return Wire.make_wire([self.edge().trim(start, end)])

# Get all the edges
modified_edges: list[Edge] = []
unmodified_edges: list[Edge] = []
original_edges: list[Edge] = []
for edge in self.edges():
# Is edge flipped
flipped = self.param_at_point(edge.position_at(0)) > self.param_at_point(
Expand All @@ -6806,11 +6803,7 @@ def trim(self, start: float, end: float) -> Wire:

# Trim edges containing start or end points
degenerate = False
if contains_start and contains_end:
u_start = edge.param_at_point(trim_start_point)
u_end = edge.param_at_point(trim_end_point)
edge = edge.trim(u_start, u_end)
elif contains_start:
if contains_start:
u_value = edge.param_at_point(trim_start_point)
if not flipped:
degenerate = u_value == 1.0
Expand All @@ -6820,7 +6813,7 @@ def trim(self, start: float, end: float) -> Wire:
degenerate = u_value == 0.0
if not degenerate:
edge = edge.trim(0.0, u_value)
elif contains_end:
if contains_end:
u_value = edge.param_at_point(trim_end_point)
if not flipped:
degenerate = u_value == 0.0
Expand All @@ -6834,10 +6827,10 @@ def trim(self, start: float, end: float) -> Wire:
if contains_start or contains_end:
modified_edges.append(edge)
else:
unmodified_edges.append(edge)
original_edges.append(edge)

# Select the wire containing the start and end points
wire_segments = edges_to_wires(modified_edges + unmodified_edges)
wire_segments = edges_to_wires(modified_edges + original_edges)
trimmed_wire = filter(
lambda w: all(
[
Expand All @@ -6847,10 +6840,9 @@ def trim(self, start: float, end: float) -> Wire:
),
wire_segments,
)
try:
return next(trimmed_wire)
except StopIteration as exc:
raise RuntimeError("Invalid trim result") from exc
if not trimmed_wire:
raise RuntimeError("Invalid trim result")
return next(trimmed_wire)

def order_edges(self) -> ShapeList[Edge]:
"""Return the edges in self ordered by wire direction and orientation"""
Expand Down

0 comments on commit 534ddbb

Please sign in to comment.