From 16f2fb960b7170b2dd003ce431f572ebebb16248 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 11 Mar 2024 23:21:29 +0100 Subject: [PATCH 1/4] Fix calculation of projection direction in project() --- src/build123d/operations_generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build123d/operations_generic.py b/src/build123d/operations_generic.py index 66001538..ed9b8292 100644 --- a/src/build123d/operations_generic.py +++ b/src/build123d/operations_generic.py @@ -772,7 +772,7 @@ def project( 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_to_screen).Z < 0: projection_direction = -workplane.z_dir * projection_flip else: projection_direction = workplane.z_dir * projection_flip @@ -790,7 +790,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) From 1969ffc35c4ca8bf3d75ed7439358f3232337e2c Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 12 Mar 2024 00:47:11 +0100 Subject: [PATCH 2/4] Fix project() bug when target is not at origin --- src/build123d/operations_generic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/build123d/operations_generic.py b/src/build123d/operations_generic.py index ed9b8292..12a5118c 100644 --- a/src/build123d/operations_generic.py +++ b/src/build123d/operations_generic.py @@ -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.to_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 From 5c70d896217abbf45f02934c37d385761df37a1b Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 12 Mar 2024 01:09:22 +0100 Subject: [PATCH 3/4] Fix broken test: Projecting a face from within a body to the body leads to inverted results --- tests/test_build_generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_build_generic.py b/tests/test_build_generic.py index 69eba0d1..1caec07b 100644 --- a/tests/test_build_generic.py +++ b/tests/test_build_generic.py @@ -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) From 154c1eba410a4bbf0a0d6bfde3200a8b9ec1d798 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 25 Mar 2024 00:35:14 +0100 Subject: [PATCH 4/4] Add check for empty intersection with project_to_shape --- src/build123d/topology.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/build123d/topology.py b/src/build123d/topology.py index 077ab01c..383228b3 100644 --- a/src/build123d/topology.py +++ b/src/build123d/topology.py @@ -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()