{"id":2710,"library":"pyrect","title":"PyRect","description":"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.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/asweigart/pyrect","tags":["geometry","rectangle","pygame-like"],"install":[{"cmd":"pip install pyrect","lang":"bash","label":"Install PyRect"}],"dependencies":[],"imports":[{"symbol":"Rect","correct":"from pyrect import Rect"}],"quickstart":{"code":"from pyrect import Rect\n\n# Create a Rect object: x, y, width, height\nr = Rect(10, 20, 100, 50)\n\nprint(f\"Initial Rect: {r}\")\nprint(f\"Top-left: {r.topleft}, Width: {r.width}, Height: {r.height}\")\nprint(f\"Center: {r.center}\")\n\n# Move the Rect (returns a new Rect)\nnew_r = r.move(5, 10)\nprint(f\"Moved Rect (new object): {new_r}\")\nprint(f\"Original Rect (unchanged): {r}\")\n\n# Modify in-place\nr.x = 0\nr.y = 0\nprint(f\"Modified in-place: {r}\")\n\n# Enable float coordinates\nr_float = Rect(0, 0, 10, 20, enableFloat=True)\nr_float.width = 10.5\nprint(f\"Rect with float enabled: {r_float.size}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"By default, Rect objects are locked to integer coordinates. Any float values assigned to position or size attributes will be truncated.","severity":"gotcha","affected_versions":"0.1.0 to 0.2.0"},{"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`.","message":"Methods 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.","severity":"gotcha","affected_versions":"0.1.0 to 0.2.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"0.1.0 to 0.2.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}