VCV Rack API v2
Loading...
Searching...
No Matches
rack::math::Rect Struct Reference

2-dimensional rectangle for graphics. More...

#include <math.hpp>

Collaboration diagram for rack::math::Rect:
[legend]

Public Member Functions

 Rect ()
 
 Rect (Vec pos, Vec size)
 
 Rect (float posX, float posY, float sizeX, float sizeY)
 
bool contains (Vec v) const
 Returns whether this Rect contains a point, inclusive on the left/top, exclusive on the right/bottom.
 
bool contains (Rect r) const
 Returns whether this Rect contains (is a superset of) a Rect.
 
bool intersects (Rect r) const
 Returns whether this Rect overlaps with another Rect.
 
bool equals (Rect r) const
 
float getLeft () const
 
float getRight () const
 
float getTop () const
 
float getBottom () const
 
float getWidth () const
 
float getHeight () const
 
Vec getCenter () const
 Returns the center point of the rectangle.
 
Vec getTopLeft () const
 
Vec getTopRight () const
 
Vec getBottomLeft () const
 
Vec getBottomRight () const
 
Rect clamp (Rect bound) const
 Clamps the edges of the rectangle to fit within a bound.
 
Rect nudge (Rect bound) const
 Nudges the position to fix inside a bounding box.
 
Rect expand (Rect b) const
 Returns the bounding box of the union of this and b.
 
Rect intersect (Rect b) const
 Returns the intersection of this and b.
 
Rect zeroPos () const
 Returns a Rect with its position set to zero.
 
Rect grow (Vec delta) const
 Expands each corner.
 
Rect shrink (Vec delta) const
 Contracts each corner.
 
Vec interpolate (Vec p)
 Returns pos + size * p
 
bool isContaining (Vec v) const
 
bool isIntersecting (Rect r) const
 
bool isEqual (Rect r) const
 

Static Public Member Functions

static Rect fromMinMax (Vec a, Vec b)
 Constructs a Rect from a top-left and bottom-right vector.
 
static Rect fromCorners (Vec a, Vec b)
 Constructs a Rect from any two opposite corners.
 
static Rect inf ()
 Returns the infinite Rect.
 

Public Attributes

Vec pos
 
Vec size
 

Detailed Description

2-dimensional rectangle for graphics.

Mathematically, Rects include points on its left/top edge but not its right/bottom edge. The infinite Rect (equal to the entire plane) is defined using pos=-inf and size=inf.

Constructor & Destructor Documentation

◆ Rect() [1/3]

rack::math::Rect::Rect ( )
inline

◆ Rect() [2/3]

rack::math::Rect::Rect ( Vec pos,
Vec size )
inline

◆ Rect() [3/3]

rack::math::Rect::Rect ( float posX,
float posY,
float sizeX,
float sizeY )
inline

Member Function Documentation

◆ fromMinMax()

static Rect rack::math::Rect::fromMinMax ( Vec a,
Vec b )
inlinestatic

Constructs a Rect from a top-left and bottom-right vector.

◆ fromCorners()

static Rect rack::math::Rect::fromCorners ( Vec a,
Vec b )
inlinestatic

Constructs a Rect from any two opposite corners.

◆ inf()

static Rect rack::math::Rect::inf ( )
inlinestatic

Returns the infinite Rect.

◆ contains() [1/2]

bool rack::math::Rect::contains ( Vec v) const
inline

Returns whether this Rect contains a point, inclusive on the left/top, exclusive on the right/bottom.

Correctly handles infinite Rects.

◆ contains() [2/2]

bool rack::math::Rect::contains ( Rect r) const
inline

Returns whether this Rect contains (is a superset of) a Rect.

Correctly handles infinite Rects.

◆ intersects()

bool rack::math::Rect::intersects ( Rect r) const
inline

Returns whether this Rect overlaps with another Rect.

Correctly handles infinite Rects.

◆ equals()

bool rack::math::Rect::equals ( Rect r) const
inline

◆ getLeft()

float rack::math::Rect::getLeft ( ) const
inline

◆ getRight()

float rack::math::Rect::getRight ( ) const
inline

◆ getTop()

float rack::math::Rect::getTop ( ) const
inline

◆ getBottom()

float rack::math::Rect::getBottom ( ) const
inline

◆ getWidth()

float rack::math::Rect::getWidth ( ) const
inline

◆ getHeight()

float rack::math::Rect::getHeight ( ) const
inline

◆ getCenter()

Vec rack::math::Rect::getCenter ( ) const
inline

Returns the center point of the rectangle.

Returns a NaN coordinate if pos=-inf and size=inf.

◆ getTopLeft()

Vec rack::math::Rect::getTopLeft ( ) const
inline

◆ getTopRight()

Vec rack::math::Rect::getTopRight ( ) const
inline

◆ getBottomLeft()

Vec rack::math::Rect::getBottomLeft ( ) const
inline

◆ getBottomRight()

Vec rack::math::Rect::getBottomRight ( ) const
inline

◆ clamp()

Rect rack::math::Rect::clamp ( Rect bound) const
inline

Clamps the edges of the rectangle to fit within a bound.

◆ nudge()

Rect rack::math::Rect::nudge ( Rect bound) const
inline

Nudges the position to fix inside a bounding box.

◆ expand()

Rect rack::math::Rect::expand ( Rect b) const
inline

Returns the bounding box of the union of this and b.

◆ intersect()

Rect rack::math::Rect::intersect ( Rect b) const
inline

Returns the intersection of this and b.

◆ zeroPos()

Rect rack::math::Rect::zeroPos ( ) const
inline

Returns a Rect with its position set to zero.

◆ grow()

Rect rack::math::Rect::grow ( Vec delta) const
inline

Expands each corner.

◆ shrink()

Rect rack::math::Rect::shrink ( Vec delta) const
inline

Contracts each corner.

◆ interpolate()

Vec rack::math::Rect::interpolate ( Vec p)
inline

Returns pos + size * p

◆ isContaining()

bool rack::math::Rect::isContaining ( Vec v) const
inline

◆ isIntersecting()

bool rack::math::Rect::isIntersecting ( Rect r) const
inline

◆ isEqual()

bool rack::math::Rect::isEqual ( Rect r) const
inline

Member Data Documentation

◆ pos

Vec rack::math::Rect::pos

◆ size

Vec rack::math::Rect::size

The documentation for this struct was generated from the following file: