Next: , Previous: , Up: Math   [Contents][Index]


4.2.2 Rectangles

(use-modules (sly math rect))

Rects are 2D axis-aligned bounding boxes. They are useful for defining rectangular regions, such as the hitbox of a game entity, or the viewport of a camera. Because rects are axis-aligned, they provide a cheap means to perform simple collision detection.

The <rect> type descriptor has been exposed for use with Guile’s (ice-9 match) pattern matching module.

Scheme Variable: <rect>

Rectangle data type with fields x, y, width, height, in that order.

Scheme Procedure: make-rect x y width height

Create a new rectangle with position (x, y), and dimensions (width, height).

Scheme Variable: null-rect

Rectangle with x, y, width, and height of 0.

Scheme Syntax: rect? obj

Return #t if obj is a rectangle.

Scheme Syntax: rect-x rect

Return the x coordinate of rect.

Scheme Syntax: rect-y rect

Return the x coordinate of rect.

Scheme Syntax: rect-width rect

Return the width of rect.

Scheme Syntax: rect-height rect

Return the height of rect.

Scheme Procedure: rect-left rect

Return the left-hand x coordinate of rect.

Scheme Procedure: rect-right rect

Return the right-hand x coordinate of rect.

Scheme Procedure: rect-top rect

Return the top y coordinate of rect

Scheme Procedure: rect-bottom rect

Return the bottom y coordinate of rect.

Scheme Procedure: rect-top-left rect

Return the top-left corner of rect.

Scheme Procedure: rect-top-right rect

Return the top-right corner of rect.

Scheme Procedure: rect-bottom-left rect
Scheme Procedure: rect-position rect

Return the bottom-left corner of rect

Scheme Procedure: rect-bottom-right rect

Return the bottom-right corner of rect.

Scheme Procedure: rect-center-x rect

Return the center x coordinate of rect.

Scheme Procedure: rect-center-y rect

Return the center y coordinate of rect.

Scheme Procedure: rect-center rect

Return the center of rect.

Scheme Procedure: rect-half-width rect

Return the half width of rect.

Scheme Procedure: rect-half-height rect

Return the half height of rect.

Scheme Procedure: rect-size rect

Return the size of rect.

Scheme Procedure: rect-move rect v
Scheme Procedure: rect-move rect x y

Create a new rectangle by moving rect by the given 2D vector offset v, or the coordinates x and y.

Scheme Procedure: rect-inflate rect size
Scheme Procedure: rect-inflate rect width height

Create a new rectangle by growing rect by the 2D vector size (or width and height) without changing the center point.

Scheme Procedure: rect-union rect1 rect2

Create a new rectangle that covers the area of both rect1 and rect2.

Scheme Procedure: rect-clip rect1 rect2

Create a new rectangle that is the overlapping region of rect1 and rect2. If the rects do not overlap, a rect of size 0 is returned.

Scheme Procedure: rect-clamp rect v

Return a new 2D vector by constraining v to the bounds of rect.

Scheme Procedure: rect-within? rect1 rect2

Return #t if rect2 is completely within rect1.

Scheme Procedure: rect-intersects? rect1 rect2

Return #t if rect2 overlaps rect1.

Scheme Procedure: rect-contains? rect v
Scheme Procedure: rect-contains? rect x y

Return #t if the 2D vector v (or the coordinates x and y) is within rect.


Next: , Previous: , Up: Math   [Contents][Index]