pods::SDLx::Rect(3pm)
π NAME π
Okay so this is the pods::SDLx::Rect(3pm) page β straight out of the User Contributed Perl Documentation, bestie β and it's all about SDLx::Rect: an SDL extension for storing and manipulating rectangular coordinates. π
π¦ CATEGORY π¦
Extension (yes, that's the whole category, iconic and brief β¨)
β¨ SYNOPSIS β¨
The tea is: SDLx::Rect works as a SDL::Rect in the lower layer (SDL::*) but provides more methods to users. So you get all the base behavior plus extra stuff, no cap.
use SDLx::Rect; #instead of SDL::Rect
my $rect = SDLx::Rect->new( $x, $y, $w, $h); #same as SDL::Rect
...
SDL::Video::fill_rect( .. , $rect, ...); # use like SDL::Rect
πΈ DESCRIPTION πΈ
"SDLx::Rect" objects are used to store and manipulate rectangular areas. You make a Rect object out of a combo of left (or x), top (or y), width (or w) and height (or h) values β literally just like raw "SDL::Rect objects". Same energy, more perks. π
Okay so this part is important, don't skip it: all "SDLx::Rect" methods that change either position or size of a Rect return a new copy of the Rect with the affected changes. The original Rect is not modified. So if you're out here expecting your original to mutate, she's not doing that. If you do wish to modify the current Rect object, use the equivalent "in-place" methods β those don't return a thing, they just affect the original Rect directly. Those "in-place" methods are denoted with the "ip" suffix, iykyk. π
Heads up: changing a Rect's attribute is always an in-place operation. No new copy for you there. π
π§ ATTRIBUTES π§
All Rect attributes are accessors, meaning you can get them by name, and set them by passing a value:
$rect->left(15);
$rect->left; # 15
The Rect object has several attributes which can be used to resize, move and align the Rect. Behold:
width,wβ gets/sets object's widthheight,hβ gets/sets object's heightleft,xβ moves the object left position to match the given coordinatetop,yβ moves the object top position to match the given coordinatebottomβ moves the object bottom position to match the given coordinaterightβ moves the object right position to match the given coordinatecenterxβ moves the object's horizontal center to match the given coordinatecenteryβ moves the object's vertical center to match the given coordinate
Some of the attributes above can be fetched or set in pairs β cute little bundles, love that for them:
$rect->topleft(10, 15); # top is now 10, left is now 15
my ($width, $height) = $rect->size;
sizeβ gets/sets object's size (width, height)topleftβ gets/sets object's top and left positionsmidleftβ gets/sets object's vertical center and left positionsbottomleftβ gets/sets object's bottom and left positionscenterβ gets/sets object's center (horizontal(x), vertical(y))toprightβ gets/sets object's top and right positionsmidrightβ gets/sets object's vertical center and right positionsbottomrightβ gets/sets object's bottom and right positionsmidtopβ gets/sets object's horizontal center and top positionsmidbottomβ gets/sets object's horizontal center and bottom positions
π METHODS π
Methods denoted as receiving Rect objects can receive either "<SDLx::Rect>" or raw "<SDL::Rect>" objects. Flexible? We love her. π«Ά
π« new ($left, $top, $width, $height)
Returns a new Rect object with the given coordinates. If any value is omitted (by passing undef), 0 is used instead. Defaults to zero, no drama. β¨
π« copy
π« duplicate
Returns a new Rect object having the same position and size as the original. Twin behavior, lowkey obsessed.
π« move(x, y)
Returns a new Rect that is moved by the given offset. The x and y arguments can be any integer value, positive or negative β go backwards, go wild, it's fine. π₯
π« move_ip(x, y)
Same as "<move"> above, but moves the current Rect in place and returns nothing. Glow-up happens to the original, not a clone.
π« inflate(x, y)
Grows or shrinks the rectangle. Returns a new Rect with the size changed by the given offset. The rectangle remains centered around its current center. Negative values will return a shrunken rectangle instead. Shrink era, growth era, your call. π
π« inflate_ip(x, y)
Same as "<inflate"> above, but grows/shrinks the current Rect in place and returns nothing.
π« clamp($rect)
Returns a new Rect moved to be completely inside the Rect object passed as an argument. If the current Rect is too large to fit inside the passed Rect, it is centered inside it, but its size is not changed. She gets centered, she does not get resized. Periodt. π
π« clamp_ip($rect)
Same as "<clamp"> above, but moves the current Rect in place and returns nothing.
π« clip($rect)
Returns a new Rect with the intersection between the two Rect objects β that is, returns a new Rect cropped to be completely inside the Rect object passed as an argument. If the two rectangles do not overlap to begin with, a Rect with 0 size is returned, in the original Rect's (x,y) coordinates. No overlap? Zero-size rect, moving on. π
π« clip_ip($rect)
Same as "<clip"> above, but crops the current Rect in place and returns nothing. As the original method, the Rect becomes zero-sized if the two rectangles do not overlap to begin with, retaining its (x, y) coordinates.
π« union($rect)
Returns a new rectangle that completely covers the area of the current Rect and the one passed as an argument. There may be area inside the new Rect that is not covered by the originals β so it's the whole vibe containing both, not a perfect pixel match. π
π« union_ip($rect)
Same as "<union"> above, but resizes the current Rect in place and returns nothing.
π« unionall( [$rect1, $rect2, ...] )
Returns the union of one rectangle with a sequence of many rectangles, passed as an ARRAY REF. Group chat of rectangles, all unioned together. π«Ά
π« unionall_ip( [$rect1, $rect2, ...] )
Same as "<unionall"> above, but resizes the current Rect in place and returns nothing.
π« fit($rect)
Returns a new Rect moved and resized to fit the Rect object passed as an argument. The aspect ratio of the original Rect is preserved, so the new rectangle may be smaller than the target in either width or height. Aspect ratio is sacred, so she stays proportional and might not fill the whole target. π¦
π« fit_ip($rect)
Same as "<fit"> above, but moves/resizes the current Rect in place and returns nothing.
π« normalize
Corrects negative sizes, flipping width/height of the Rect if they have a negative size. No repositioning is made, so the rectangle will remain in the same place, but the negative sides will be swapped. This method returns nothing. β¨
π« contains($rect)
Returns true (non-zero) when the argument is completely inside the Rect. Otherwise returns undef.
π« collidepoint(x, y)
Returns true (non-zero) if the given point is inside the Rect, otherwise returns undef. A point along the right or bottom edge is not considered to be inside the rectangle. Edges are exclusive, sorry bestie, rules are rules. π
π« colliderect($rect)
Returns true (non-zero) if any portion of either rectangles overlap (except for the top+bottom or left+right edges). Touching edges don't count. π
π« collidelist( [$rect1, $rect2, ...] )
Test whether the rectangle collides with any in a sequence of rectangles, passed as an ARRAY REF. The index of the first collision found is returned. Returns undef if no collisions are found. First match wins, main character energy. π
π« collidelistall( [$rect1, $rect2, ...] )
Returns an ARRAY REF of all the indices that contain rectangles that collide with the Rect. If no intersecting rectangles are found, an empty list ref is returned. Everyone who showed up to the collision party, listed. π
π« collidehash( {key1 => $rect1, key2 => $rect2, ...} )
Receives a HASH REF and returns the a (key, value) list with the key and value of the first hash item that collides with the Rect. If no collisions are found, returns (undef, undef).
π« collidehashall( {key1 => $rect1, key2 => $rect2, ...} )
Returns a HASH REF of all the key and value pairs that intersect with the Rect. If no collisions are found an empty hash ref is returned.
π BUGS π
Please report any bugs or feature requests to the bug tracker. I will be notified, and then you'll automatically be notified of progress on your bug as we make changes. So like, you're looped in the entire time, no ghosting. π«Ά
π SUPPORT π
You can find documentation for this module with the perldoc command.
perldoc SDLx::Rect
π AUTHORS π
See "AUTHORS" in SDL. (Yes, that's the whole section. She's lowkey.) π
π§ ACKNOWLEDGEMENTS π§
Many thanks to the authors of pygame.rect, in which this particular module is heavily based. Credit where credit is due, always. π
β COPYRIGHT & LICENSE β
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π SEE ALSO π
perl, SDL, SDL::Rect, SDL::Game
okay that's the whole page, bestie β this was pods::SDLx::Rect(3pm) from perl v5.42.3, dated 2026-08-19. go build your rectangles, they're gonna slay π
β¨π
π¦ where this page comes from
- ubuntu stonking: libsdl-perl 2.548-6build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms