Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculation of projection direction in project() #587

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/build123d/operations_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ def project(
projected_shapes = []
obj: Shape
for obj in face_list + line_list:
obj_to_screen = (target.center() - obj.center()).normalized()
if workplane.from_local_coords(obj_to_screen).Z < 0:
if workplane.to_local_coords(obj.center()).Z > 0:
projection_direction = -workplane.z_dir * projection_flip
else:
projection_direction = workplane.z_dir * projection_flip
Expand All @@ -790,7 +789,7 @@ def project(
projected_points = []
for pnt in point_list:
pnt_to_target = (workplane.origin - pnt).normalized()
if workplane.from_local_coords(pnt_to_target).Z < 0:
if workplane.to_local_coords(pnt_to_target).Z < 0:
projection_axis = -Axis(pnt, workplane.z_dir * projection_flip)
else:
projection_axis = Axis(pnt, workplane.z_dir * projection_flip)
Expand Down
3 changes: 3 additions & 0 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -6043,6 +6043,9 @@ def project_to_shape(
for target_face in target_object.faces():
intersected_faces.extend(face_extruded.intersect(target_face).faces())

if len(intersected_faces) == 0:
return ShapeList()

# intersected faces may be fragmented so we'll put them back together
sewed_face_list = Face.sew_faces(intersected_faces)
sewed_faces = ShapeList()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def test_project_to_sketch1(self):
def test_project_to_sketch2(self):
with BuildPart() as test2:
Box(4, 4, 1)
with BuildSketch(Plane.XY.offset(0.1)) as c:
with BuildSketch(Plane.XY.offset(2)) as c:
Rectangle(1, 1)
project()
extrude(amount=1)
Expand Down