Skip to content

Commit

Permalink
feat: add align.NONE
Browse files Browse the repository at this point in the history
  • Loading branch information
erooke committed Nov 12, 2024
1 parent f6bedfb commit 9b26816
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/build123d/build_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Align(Enum):
MIN = auto()
CENTER = auto()
MAX = auto()
NONE = None

def __repr__(self):
return f"<{self.__class__.__name__}.{self.name}>"
Expand Down
2 changes: 2 additions & 0 deletions src/build123d/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2543,4 +2543,6 @@ def to_align_offset(
align_offset.append(-(min_coord + max_coord) / 2)
elif alignment == Align.MAX:
align_offset.append(-max_coord)
elif alignment == Align.NONE:
align_offset.append(0)
return Vector(*align_offset)
2 changes: 1 addition & 1 deletion src/build123d/objects_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def __init__(
side_count: int,
major_radius: bool = True,
rotation: float = 0,
align: tuple[Align, Align] = (Align.CENTER, Align.CENTER),
align: tuple[Align, Align] = (Align.NONE, Align.NONE),
mode: Mode = Mode.ADD,
):
# pylint: disable=too-many-locals
Expand Down
6 changes: 2 additions & 4 deletions tests/test_build_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_regular_polygon(self):
self.assertEqual(r.radius, 2)
self.assertEqual(r.side_count, 6)
self.assertEqual(r.rotation, 0)
self.assertEqual(r.align, (Align.CENTER, Align.CENTER))
self.assertEqual(r.align, (Align.NONE, Align.NONE))
self.assertEqual(r.mode, Mode.ADD)
self.assertAlmostEqual(test.sketch.area, (3 * sqrt(3) / 2) * 2**2, 5)
self.assertTupleAlmostEquals(
Expand All @@ -274,14 +274,13 @@ def test_regular_polygon_minor_radius(self):
self.assertAlmostEqual(r.radius, 1, 5)
self.assertEqual(r.side_count, 3)
self.assertEqual(r.rotation, 0)
self.assertEqual(r.align, (Align.CENTER, Align.CENTER))
self.assertEqual(r.align, (Align.NONE, Align.NONE))
self.assertEqual(r.mode, Mode.ADD)
self.assertAlmostEqual(test.sketch.area, (3 * sqrt(3) / 4) * (0.5 * 2) ** 2, 5)
self.assertTupleAlmostEquals(
test.sketch.faces()[0].normal_at().to_tuple(), (0, 0, 1), 5
)

@pytest.mark.skip(reason="Conflicts with test_regular_polygon_matches_polar")
def test_regular_polygon_align(self):
with BuildSketch() as align:
RegularPolygon(2, 5, align=(Align.MIN, Align.MAX))
Expand All @@ -297,7 +296,6 @@ def test_regular_polygon_align(self):
Vector(align.vertices().sort_by_distance(other=(0, 0, 0))[-1]).length, 2
)

@pytest.mark.skip(reason="Conflicts with test_regular_polygon_align")
def test_regular_polygon_matches_polar(self):
for side_count in range(3, 10):
with BuildSketch():
Expand Down

0 comments on commit 9b26816

Please sign in to comment.