PyRect

0.2.0 · active · verified Fri Apr 10

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →