-
Notifications
You must be signed in to change notification settings - Fork 343
Reinvent the Rectangle, or The First Step Towards Rectangle Unification. #2088
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
Conversation
If we ever do support it, remove this.
This reverts commit 08f4abe.
More rect touchups as examples for fixing other remaining issues
Could we get a mutable rect as well? |
Just agreed (with @DigiDuncan) that RectInt should be removed after we merged this huge PR. |
Right now we stick to the immutable version only. From my point of view, the convenience benefits are not big enough to introduce a second Rect option, which is mutable. |
So summary: I am fine with the PR. @einarf @pvcraven please give feedback what you think about the naming of the Rect constructor functions (XYWH, LBWH, ...) being uppercase. I would merge the PR over the next day, if you give feedback afterwards. We can still do it in another PR.
|
@DigiDuncan Can you check, if you can make the PR mergable? |
Take that, Thales of Miletus.
For years, Arcade has suffered from Rectangle fragmentation. The GUI, GL, Camera, draw commands, they all redefine and reinvent the rectangle. Need proof? We have proof. But why have many rectangle when one
Rect
do trick?With
Rect
, you can:Rect
to your heart's contentRect
s (now with bonus|
and&
support)They have a beautiful
__str__
method, backwards-compatible aliases, dead-simple property names, and implement every way rectangles were used in the library.You can create them from
**kwargs
, or using one of several DX-friendly helper methods, includingLRBT
,LBWH
,XYWH
,XYRR
(you're welcome, @einarf!), andViewport
(you're welcome @DragonMoffon!)And they're fast. All eights values are pre-calculated on
__init__
(despite only needing four values to create), and they subclassNamedTuple
, so dot-access is Sonic-level fast.Immutable. Extendable. Human-usable.
Merging in this PR allows a full rework of every rectangle in Arcade, making them easy to use for contributors, developers, and end users.
And as a bonus, it cleans the heck out of
draw_commands
.