The (chickadee math rect)
module provides an API for
manipulating axis-aligned bounding boxes (AABBs). AABBs are often
used for collision detection in games. Common use-cases are defining
“hitboxes” in platformers or using them for the “broad phase” of a
collision detection algorithm that uses a more complex (and thus
slower) method of determining the actual collisions.
Like some of the other math modules, there exists a collection of functions that do in-place modification of rectangles for use in performance critical code paths.
Create a new rectangle that is width by height in size and whose bottom-left corner is located at (x, y).
Return #t
if obj is a rectangle.
Return #t
if rect2 is completely within rect1.
Return #t
if rect2 overlaps rect1.
Return #t
if the coordinates (x, y) are within
rect.
Return #t
if the 2D vector v is within the bounds of
rect.
Return the X coordinate of the lower-left corner of rect.
Return the Y coordinate of the lower-left corner of rect.
Return the left-most X coordinate of rect.
Return the right-most X coordinate of rect.
Return the bottom-most Y coordinate of rect.
Return the top-most Y coordinate of rect.
Return the X coordinate of the center of rect.
Return the Y coordinate of the center of rect.
Return the width of rect.
Return the height of rect.
Return the surface area covered by rect.
Restrict x to the portion of the X axis covered by rect.
Restrict y to the portion of the Y axis covered by rect.
Return a new rect that adjusts the location of rect1 so that it is completely within rect2. An exception is thrown in the case that rect1 cannot fit completely within rect2.
Return a new rectangle based on rect but moved to the coordinates (x, y).
Return a new rectangle based on rect but moved to the coordinates in the 2D vector v.
Return a new rectangle based on rect but moved by (x, y) units relative to its current location.
Return a new rectangle based on rect but moved by the 2D vector v relative to its current location.
Return a new rectangle based on rect, but expanded by width units on the X axis and height units on the Y axis, while keeping the rectangle centered on the same point.
Return a new rectangle that completely covers the area of rect1 and rect2.
Return a new rectangle that is the overlapping region of rect1 and rect2. If the two rectangles do not overlap, a rectangle of 0 width and 0 height is returned.
Set the left X coordinate of rect to x.
Set the bottom Y coordinate of rect to y.
Set the width of rect to width.
Set the height of rect to height.
Move rect to (x, y) in-place.
Move rect to the 2D vector v in-place.
Move rect by (x, y) in-place.
Move rect by the 2D vector v in-place.
Expand rect by width and height in-place.
Modify rect1 in-place to completely cover the area of both rect1 and rect2.
Modify rect1 in-place to be the overlapping region of rect1 and rect2.
Adjust the location of rect1 in-place so that its bounds are completely within rect2. An exception is thrown in the case that rect1 cannot fit completely within rect2.
Restrict the coordinates of the 2D vector v so that they are within the bounds of rect. v is modified in-place.