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

Add an "Align.NONE" enum member. #734

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion docs/cheat_sheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Cheat Sheet
.. card:: Enums

+----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| :class:`~build_enums.Align` | MIN, CENTER, MAX |
| :class:`~build_enums.Align` | MIN, CENTER, MAX, NONE |
+----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| :class:`~build_enums.ApproxOption` | ARC, NONE, SPLINE |
+----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
Expand Down
10 changes: 5 additions & 5 deletions docs/objects_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@

# [Ex. 11]
with BuildSketch() as example_11:
Text("text", 1)
Text("text", 1, align=(Align.CENTER, Align.NONE))
# [Ex. 11]
s = 100 / max(*example_11.sketch.bounding_box().size)
svg = ExportSVG(scale=s)
Expand All @@ -123,7 +123,7 @@
with BuildSketch() as example_12:
t = Trapezoid(2, 1, 80)
with Locations((-0.6, -0.3)):
Text("80°", 0.3, mode=Mode.SUBTRACT)
Text("80°", 0.3, mode=Mode.SUBTRACT, align=(Align.CENTER, Align.NONE))
# [Ex. 12]
s = 100 / max(*example_12.sketch.bounding_box().size)
svg = ExportSVG(scale=s)
Expand Down Expand Up @@ -207,9 +207,9 @@
p1 = CenterArc(t.vertices().group_by(Axis.Y)[0].sort_by(Axis.X)[0], 8, 0, t.B)
p2 = CenterArc(t.vertices().group_by(Axis.Y)[0].sort_by(Axis.X)[-1], 8, 180 - t.C, t.C)
p3 = CenterArc(t.vertices().sort_by(Axis.Y)[-1], 8, 270 - t.A / 2, t.A)
t1 = Text("B", font_size=d.font_size).moved(Pos(p1 @ 0.5))
t2 = Text("C", font_size=d.font_size).moved(Pos(p2 @ 0.5))
t3 = Text("A", font_size=d.font_size).moved(Pos(p3 @ 0.5))
t1 = Text("B", font_size=d.font_size, align=(Align.CENTER, Align.NONE)).moved(Pos(p1 @ 0.5)
t2 = Text("C", font_size=d.font_size, align=(Align.CENTER, Align.NONE)).moved(Pos(p2 @ 0.5)
t3 = Text("A", font_size=d.font_size, align=(Align.CENTER, Align.NONE)).moved(Pos(p3 @ 0.5)

s = 100 / max(*isosceles_triangle.sketch.bounding_box().size)
svg = ExportSVG(scale=s)
Expand Down
4 changes: 4 additions & 0 deletions src/build123d/build_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,8 @@
align_offset.append(-size[i] / 2)
elif self.align[i] == Align.MAX:
align_offset.append(-size[i])
elif self.align[i] == Align.NONE:
align_offset.append(0)

Check warning on line 955 in src/build123d/build_common.py

View check run for this annotation

Codecov / codecov/patch

src/build123d/build_common.py#L954-L955

Added lines #L954 - L955 were not covered by tests

# Align the points
points = ShapeList(
Expand Down Expand Up @@ -1151,6 +1153,8 @@
align_offset.append(-size[i] / 2)
elif self.align[i] == Align.MAX:
align_offset.append(-size[i])
elif self.align[i] == Align.NONE:
align_offset.append(0)

Check warning on line 1157 in src/build123d/build_common.py

View check run for this annotation

Codecov / codecov/patch

src/build123d/build_common.py#L1156-L1157

Added lines #L1156 - L1157 were not covered by tests

self.min = Vector(*align_offset) #: bottom left corner
self.max = self.min + self.size #: top right corner
Expand Down
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 = auto()

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 @@ -1033,6 +1033,8 @@
)
elif align[i] == Align.MAX:
align_offset.append(-self.max.to_tuple()[i])
elif align[i] == Align.NONE:
align_offset.append(0)

Check warning on line 1037 in src/build123d/geometry.py

View check run for this annotation

Codecov / codecov/patch

src/build123d/geometry.py#L1036-L1037

Added lines #L1036 - L1037 were not covered by tests
return align_offset


Expand Down
2 changes: 2 additions & 0 deletions src/build123d/objects_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
)
elif align[i] == Align.MAX:
align_offset.append(-bbox.max.to_tuple()[i])
elif align[i] == Align.NONE:
align_offset.append(0)

Check warning on line 77 in src/build123d/objects_part.py

View check run for this annotation

Codecov / codecov/patch

src/build123d/objects_part.py#L76-L77

Added lines #L76 - L77 were not covered by tests
part.move(Location(Vector(*align_offset)))

context: BuildPart = BuildPart._get_context(self, log=False)
Expand Down
4 changes: 4 additions & 0 deletions src/build123d/objects_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@
align_offset.append(0)
elif align[i] == Align.MAX:
align_offset.append(-maxs[i])
elif align[i] == Align.NONE:
align_offset.append(0)

Check warning on line 348 in src/build123d/objects_sketch.py

View check run for this annotation

Codecov / codecov/patch

src/build123d/objects_sketch.py#L347-L348

Added lines #L347 - L348 were not covered by tests
else:
align_offset = [0, 0]
pts = [point + Vector(*align_offset) for point in pts]
Expand Down Expand Up @@ -531,6 +533,8 @@
text, values must be between 0.0 and 1.0. Defaults to 0.0.
rotation (float, optional): angles to rotate objects. Defaults to 0.
mode (Mode, optional): combination mode. Defaults to Mode.ADD.

"Align.NONE", used vertically, places the text on its baseline.
"""

# pylint: disable=too-many-instance-attributes
Expand Down