Skip to content

Commit

Permalink
Ensure offset faces have same normal Issue #564
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Feb 22, 2024
1 parent c4167ea commit 568c351
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/build123d/operations_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,10 @@ def offset(
inner_wires.append(offset_wire)
except:
pass
new_faces.append(Face(outer_wire, inner_wires))
new_face = Face(outer_wire, inner_wires)
if (new_face.normal_at() - face.normal_at()).length > 0.001:
new_face = -new_face
new_faces.append(new_face)
if edges:
if len(edges) == 1 and edges[0].geom_type == GeomType.LINE:
new_wires = [
Expand Down
10 changes: 10 additions & 0 deletions tests/test_build_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,16 @@ def test_offset_failure(self):
with self.assertRaises(RuntimeError):
offset(amount=-2, openings=topf)

def test_flipped_faces(self):
box = Box(10, 10, 10)
original_faces = box.faces()
offset_faces = [offset(face, amount=-3).face() for face in original_faces]

for original_face, offset_face in zip(original_faces, offset_faces):
self.assertTupleAlmostEquals(
tuple(original_face.normal_at()), tuple(offset_face.normal_at()), 3
)


class PolarLocationsTests(unittest.TestCase):
def test_errors(self):
Expand Down

0 comments on commit 568c351

Please sign in to comment.