Skip to content

Commit

Permalink
relative point in rect helper
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiDuncan committed Sep 29, 2024
1 parent 4dbaacf commit 02d7f1d
Showing 1 changed file with 14 additions and 0 deletions.
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

0 comments on commit 02d7f1d

Please sign in to comment.