Skip to content

Commit

Permalink
Make transform origin respect Text alignment (#110)
Browse files Browse the repository at this point in the history
Fixes #109
  • Loading branch information
ajyoon authored Jan 7, 2024
1 parent 03e8526 commit 621dca7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions neoscore/core/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ def bounding_rect(self) -> Rect:
"""The bounding rect for this text positioned relative to ``pos``.
The rect ``(x, y)`` position is relative to the object's position.
Note that with text objects, the rect's ``(x, y)`` position will
typically not be at the origin.
Note that this currently accounts for scaling, but not rotation.
This currently accounts for scaling and alignment, but not rotation.
Rotated objects will generally have incorrect bounding rects.
"""
raw_rect = self._raw_scaled_bounding_rect
alignment_offset = self._alignment_offset
Expand Down Expand Up @@ -206,7 +209,7 @@ def _render_slice(
None if inside_flowable else self.parent.interface_for_children,
self.scale,
self.rotation,
self.transform_origin,
self.transform_origin - self._alignment_offset,
self.brush.interface,
self.pen.interface,
self.text,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_core/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ def test_rendered_interface_with_offset(self):
"testing",
alignment_x=AlignmentX.CENTER,
alignment_y=AlignmentY.CENTER,
transform_origin=(Unit(15), Unit(10)),
)
obj.render()
rendered_pos = obj.interfaces[0].pos
transform_origin = obj.interfaces[0].transform_origin
assert_almost_equal(rendered_pos, Point(Unit(-20), Unit(2.5)), epsilon=1.5)
assert_almost_equal(
transform_origin,
Point(Unit(35), Unit(7.5)),
epsilon=1.5,
)

0 comments on commit 621dca7

Please sign in to comment.