Registry / serialization / pyrect

pyrect

JSON →
library0.2.0pypypi✓ verified 26d ago

PyRect is a simple module that provides a `Rect` class, mimicking the functionality of Pygame's `Rect` objects for handling rectangular areas. It is designed to be a standalone, lightweight solution for geometric operations. The current version is 0.2.0, released in March 2022, indicating an infrequent release cadence.

pip install pyrect
INSTALL
IMPORT
SIG · PYRECT
P
pyrect
serializationpythonv0.2.0
Install
2.4s avg
Import
226ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.248s · 19.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.204s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Rect
from pyrect import Rect

Create a Rect object with x, y, width, and height. Access various calculated attributes like topleft, center, and size. Demonstrate moving a rectangle (which returns a new object) versus modifying its attributes in-place. Also shows how to enable float coordinates.

from pyrect import Rect # Create a Rect object: x, y, width, height r = Rect(10, 20, 100, 50) print(f"Initial Rect: {r}") print(f"Top-left: {r.topleft}, Width: {r.width}, Height: {r.height}") print(f"Center: {r.center}") # Move the Rect (returns a new Rect) new_r = r.move(5, 10) print(f"Moved Rect (new object): {new_r}") print(f"Original Rect (unchanged): {r}") # Modify in-place r.x = 0 r.y = 0 print(f"Modified in-place: {r}") # Enable float coordinates r_float = Rect(0, 0, 10, 20, enableFloat=True) r_float.width = 10.5 print(f"Rect with float enabled: {r_float.size}")
Debug
Known issues
gotchaBy default, Rect objects are locked to integer coordinates. Any float values assigned to position or size attributes will be truncated.
fix
To enable float coordinates, create the Rect object with `enableFloat=True` (e.g., `Rect(x, y, w, h, enableFloat=True)`) or set `rect.enableFloat = True` on an existing object.
affects: 0.1.0 to 0.2.0
gotchaMethods that modify the rectangle's position or size, like `move()` or `inflate()`, return a *new* Rect object with the changes, leaving the original object unchanged. This is consistent with Pygame's `Rect` behavior.
fix
If you intend to modify the rectangle in-place, use the `_ip` suffix methods (e.g., `move_ip()`, `inflate_ip()`) or directly assign to attributes like `rect.x`, `rect.y`, `rect.width`, `rect.height`.
affects: 0.1.0 to 0.2.0
gotchaWhen modifying a Rect's `width` or `height` (or `size`), the top-left corner (`topleft`) of the rectangle remains anchored. This means the rectangle expands or shrinks from its top-left point.
fix
Be aware of this anchoring behavior when performing resizing operations. If a different anchor point is desired, you will need to manually adjust the `topleft` coordinates after resizing.
affects: 0.1.0 to 0.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyrect'
The `pyrect` library is not installed in your Python environment.
fix
pip install pyrect
ImportError: cannot import name 'rect' from 'pyrect'
The `Rect` class name in `pyrect` is capitalized, but you attempted to import it with a lowercase 'r'.
fix
from pyrect import Rect
TypeError: Rect.__init__() missing 2 required positional arguments: 'width' and 'height'
The `Rect` constructor requires four arguments (x, y, width, height), but fewer were provided.
fix
my_rect = Rect(10, 20, 100, 50)
AttributeError: type object 'Rect' has no attribute 'width'
You are attempting to access an instance attribute (like `width`) directly on the `Rect` class instead of on an instantiated `Rect` object.
fix
my_rect = Rect(10, 20, 100, 50)
print(my_rect.width)
Upgrade
Version history
0.2.0latest on PyPI · released Mar 16, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
Amazon
1
Resources
pyrect — pip install pyrect · libregistry