Skip to content

More rect touchups as examples for fixing other remaining issues #7

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

Merged
merged 5 commits into from
May 22, 2024
Merged
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
35 changes: 30 additions & 5 deletions arcade/types/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,39 @@ class Rect(NamedTuple):
You can also use :py:func:`~arcade.types.rect.Rect.from_kwargs` to create a Rect from keyword arguments.

"""
#: The X position of the rectangle's left edge.
left: float
#: The X position of the rectangle's right edge.
right: float
#: The Y position of the rectangle's bottom edge.
bottom: float
#: The Y position of the rectangle's top edge.
top: float
#: The total width of the rectangle along the X axis.
#: To get the rectangle's :py:attr:`.height` well, use
#: :py:attr:`.size`
width: float
#: The total height of the rectangle along the Y axis.
#: To get the rectangle's :py:attr:`.width` as well, use
#: :py:attr:`.size`.
height: float
#: The center of the rectangle along the X axis. To get its
#: center :py:attr:`.y` as well, use :py:attr:`.center`.
x: float
#: The center of the rectangle along the Y axis. To get its
#: center :py:attr:`.x` as well, use :py:attr:`.center`.
y: float

@property
@warning(ReplacementWarning, message=".center_x is deprecated. Please use .x instead.")
def center_x(self) -> float:
"""Backwards-compatible alias for `Rect.x`."""
"""Backwards-compatible alias for :py:attr:`.x`."""
return self.x

@property
@warning(ReplacementWarning, message=".center_y is deprecated. Please use .y instead.")
def center_y(self) -> float:
"""Backwards-compatible alias for `Rect.y`."""
"""Backwards-compatible alias for :py:attr:`.y`."""
return self.y

@property
Expand Down Expand Up @@ -244,9 +258,20 @@ def clamp_height(self, min_height: Optional[AsFloat] = None, max_height: Optiona

def clamp_width(self, min_width: Optional[AsFloat] = None, max_width: Optional[AsFloat] = None,
anchor: Vec2 = AnchorPoint.CENTER) -> Rect:
"""
Return a :py:class:`~arcade.types.rect.Rect` that is has a width between `min_width` and `max_width`, positioned at
the current position and anchored to a point (default center.)
"""Return a :py:class:`.Rect` constrained to the passed dimension.

It will be created as follows:

* Its :py:attr:`.width` will be between any provided ``min_width``
and ``max_width``
* It will be positioned at the current position using the passed
``anchor``

:param min_width: An optional minimum width.
:param max_width: An optional maximum width.
:param anchor: A :py:class:`~pyglet.math.Vec2` of the fractional
percentage of the rectangle's total :py:attr:`.size` along
both axes. It defaults to the center.
"""
width = min(max_width or float("inf"), max(min_width or 0.0, self.width))
return self.resize(width, self.height, anchor)
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import gc
import os
import sys
Expand Down