Skip to content

The Rect, Pt. II: The Rect-oning and the Vec-oning #2096

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 53 commits into from
Jun 1, 2024

Conversation

DigiDuncan
Copy link
Collaborator

@DigiDuncan DigiDuncan commented May 29, 2024

Don't call it a comeback.

Welcome to the new stage of Rect: integration. We put Rects anywhere that mattered except GUI, we'll work on that with @eruvanos, and it makes the library code and the end-user experience so much nicer. See for yourself:

  • Rect
    • Added Rect.distance_from_bounds()
    • Added position_to_uv() and uv_to_position()
    • Added point in rect support for Rect
    • Added * and / support for scaling relative to (0, 0).
    • Added bool() support (area is not 0)
    • Added support for round(), floor(), and ceil()
    • Added .area property
    • Functions expecting Vec2 now accept Tuple[AsFloat, AsFloat]
    • Improved docstrings
    • Fixed .viewport
  • Added type aliases Point2 and Point3
  • Camera
    • All camera functions now take Point, Point2, or Point3 where points are expected
    • All camera functions return Vec2 or Vec3 as expected
    • Viewport has been removed from the ProjectionData Protocol
    • Projectors now accept a viewport Rect, and a Scissor Rect
  • Added Rect and it's constructors, Vec2, and Vec3 to top-level module
  • Added Texture.draw_rect()
  • Added BasicSprite.rect
  • Added Section.rect
  • Added Window.rect
  • Added SpriteSolidColor.from_rect()
  • Added NinePatchTexture.from_rect()
  • Remove IntRect, FloatRect, RectList aliases
  • Rename the old Rect in arcade.GUI to GUIRect
  • Most things that were returning Tuple[float, float] now return Vec2, same for Vec3

@DigiDuncan
Copy link
Collaborator Author

Added Window.rect and Rect.position_to_uv() and Rect.uv_to_position(), which technically contains the functionality contained in #2051, though I'd argue the DX (developer experience) found in that PR is slightly nicer.

@alejcas
Copy link
Member

alejcas commented May 30, 2024

What's the reason behind having Vec2 and Tuple[AsFloat, AsFloat] coexist?

@alejcas
Copy link
Member

alejcas commented May 30, 2024

Also what about typing Rect[int] or Rect[float] seems that rect sizes are always floats.

@pushfoo
Copy link
Member

pushfoo commented May 30, 2024

What's the reason behind having Vec2 and Tuple[AsFloat, AsFloat] coexist?

The same one was Color and RGBA255: allow people to pass non-Vec2 types for convenience.

Also what about typing Rect[int] or Rect[float] seems that rect sizes are always floats.

TL;DR: My understanding is that it's unneeded complexity.

As far as I understand, the only case where we lock to int is when we're dealing with viewport pixels. Otherwise, the main purpose of rectangles is bound checking.

If we were to add Rect[int], then we'd have ugly issues with rounding behavior. I think I once found a way for an object to become aware of what it was annotated as, but it was complex and probably slow. The alternative would be to pass in a type for rects at creation, but that's ugly.

@Cleptomania Cleptomania merged commit 285bc2b into pythonarcade:development Jun 1, 2024
8 checks passed
@DigiDuncan DigiDuncan deleted the the-rect-pt-ii branch July 3, 2024 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants