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

Relative point helper for Rect #2378

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
14 changes: 14 additions & 0 deletions arcade/types/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,20 @@ def uv_to_position(self, uv: Point2) -> Vec2:
x, y = uv
return Vec2(self.left + x * self.width, self.bottom + y * self.height)

def get_relative_to_anchor(self, point: Point2, anchor: Vec2 = AnchorPoint.CENTER) -> Vec2:
"""Convert a point to a relative offset from the anchor point.
Args:
point:
The point to make relative.
anchor:
The anchor point to make the point relative to.
"""
x, y = point
rx = x - (self.left + (self.width * anchor.x))
ry = y - (self.bottom + (self.height * anchor.y))
return Vec2(rx, ry)

def to_points(self) -> tuple[Vec2, Vec2, Vec2, Vec2]:
"""Return a new :py:class:`tuple` of this rectangle's corner points.
Expand Down
Loading