Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | List of all members
G3D::Rect2D Class Reference


If you are using this class for pixel rectangles, keep in mind that the last pixel you can draw to is at x0() + width() - 1. More...

Public Member Functions

 Rect2D (const Any &any)
 
 Rect2D (const Rect2D &r)
 
 Rect2D ()
 Creates the empty set rectangle. More...
 
 Rect2D (const Vector2 &wh)
 Creates a rectangle at 0,0 with the given width and height. More...
 
 Rect2D (const Rect2D &a, const Rect2D &b)
 Computes a rectangle that contains both a and b. More...
 
float area () const
 
Rect2D border (float delta) const
 
Point2 center () const
 
template<class T >
void clip (const Array< T > &inPoly, Array< T > &outPoly) const
 
Clips so that the rightmost point of the outPoly is at rect.x1 (e.g. More...
 
bool contains (const Point2 &v) const
 
bool contains (const Rect2D &r) const
 
Point2 corner (int i) const
 Returns the corners in the order: (min,min), (max,min), (max,max), (min,max). More...
 
void deserialize (class BinaryInput &b)
 
Rect2D expand (float delta) const
 Returns a new Rect2D that is bigger/smaller by the specified amount (negative is shrink.) More...
 
Vector2 extent () const
 
float height () const
 
Rect2D intersect (const Rect2D &other) const
 
Returns the overlap region between the two rectangles. More...
 
bool intersects (const Rect2D &r) const
 True if there is non-zero area to the intersection between this and r. More...
 
bool intersectsOrTouches (const Rect2D &r) const
 Like intersection, but counts the adjacent case as touching. More...
 
bool isEmpty () const
 Returns true if this is the empty set, which is distinct from a zero-area rectangle. More...
 
bool isFinite () const
 
Rect2D largestCenteredSubRect (float ww, float hh) const
 Returns the largest, centered Rect2D that can fit inside this while maintaining the aspect ratio of x:y. More...
 
Rect2D lerp (const Rect2D &other, float alpha) const
 
void merge (const Rect2D &other)
 
bool operator!= (const Rect2D &other) const
 
Rect2D operator* (float s) const
 
Rect2D operator* (const Vector2 &s) const
 
Rect2D operator+ (const Vector2 &v) const
 
Rect2D operator- (const Vector2 &v) const
 
Rect2D operator/ (float s) const
 
Rect2D operator/ (const Vector2 &s) const
 
bool operator== (const Rect2D &other) const
 
Point2 randomPoint () const
 Uniformly random point on the interior. More...
 
void serialize (class BinaryOutput &b) const
 
Any toAny () const
 Converts the Rect2D to an Any. More...
 
Vector2 wh () const
 Width and height. More...
 
float width () const
 
float x0 () const
 
Point2 x0y0 () const
 Min, min corner. More...
 
Point2 x0y1 () const
 
float x1 () const
 
Point2 x1y0 () const
 
Point2 x1y1 () const
 Max,max corner. More...
 
float y0 () const
 
float y1 () const
 

Static Public Member Functions

static const Rect2Dempty ()
 
static Rect2D inf ()
 Constructs a Rect2D with infinite boundaries. More...
 
static Rect2D xywh (float x, float y, float w, float h)
 
static Rect2D xywh (const Point2 &v, const Vector2 &w)
 
static Rect2D xyxy (float x0, float y0, float x1, float y1)
 
static Rect2D xyxy (const Point2 &v0, const Point2 &v1)
 

Detailed Description


If you are using this class for pixel rectangles, keep in mind that the last pixel you can draw to is at x0() + width() - 1.

Constructor & Destructor Documentation

◆ Rect2D() [1/5]

G3D::Rect2D::Rect2D ( const Any any)
Parameters
anyMust either Rect2D::xywh(#, #, #, #) or Rect2D::xyxy(#, #, #, #)

◆ Rect2D() [2/5]

G3D::Rect2D::Rect2D ( const Rect2D r)
inline

◆ Rect2D() [3/5]

G3D::Rect2D::Rect2D ( )
inline

Creates the empty set rectangle.

◆ Rect2D() [4/5]

G3D::Rect2D::Rect2D ( const Vector2 wh)
inline

Creates a rectangle at 0,0 with the given width and height.

◆ Rect2D() [5/5]

G3D::Rect2D::Rect2D ( const Rect2D a,
const Rect2D b 
)
inline

Computes a rectangle that contains both a and b.

Note that even if or has zero area, its origin will be included.

Member Function Documentation

◆ area()

float G3D::Rect2D::area ( ) const
inline

◆ border()

Rect2D G3D::Rect2D::border ( float  delta) const
inline

◆ center()

Point2 G3D::Rect2D::center ( ) const
inline

◆ clip()

template<class T >
void G3D::Rect2D::clip ( const Array< T > &  inPoly,
Array< T > &  outPoly 
) const
inline


Clips so that the rightmost point of the outPoly is at rect.x1 (e.g.

a 800x600 window produces rightmost point 799, not 800). The results are suitable for pixel rendering if iRounded. Templated so that it will work for Vector2,3,4 (the z and w components are interpolated linearly). The template parameter must define T.lerp and contain x and y components.

If the entire polygon is clipped by a single side, the result will be empty. The result might also have zero area but not be empty.

◆ contains() [1/2]

bool G3D::Rect2D::contains ( const Point2 v) const
inline

◆ contains() [2/2]

bool G3D::Rect2D::contains ( const Rect2D r) const
inline

◆ corner()

Point2 G3D::Rect2D::corner ( int  i) const
inline

Returns the corners in the order: (min,min), (max,min), (max,max), (min,max).

Referenced by largestCenteredSubRect().

◆ deserialize()

void G3D::Rect2D::deserialize ( class BinaryInput b)

◆ empty()

static const Rect2D& G3D::Rect2D::empty ( )
static

Referenced by intersect().

◆ expand()

Rect2D G3D::Rect2D::expand ( float  delta) const
inline

Returns a new Rect2D that is bigger/smaller by the specified amount (negative is shrink.)

◆ extent()

Vector2 G3D::Rect2D::extent ( ) const
inline

◆ height()

float G3D::Rect2D::height ( ) const
inline

◆ inf()

static Rect2D G3D::Rect2D::inf ( )
inlinestatic

Constructs a Rect2D with infinite boundaries.

Use isFinite() to test either min or max.

◆ intersect()

Rect2D G3D::Rect2D::intersect ( const Rect2D other) const
inline


Returns the overlap region between the two rectangles.

This may have zero area if they do not intersect. See the two-Rect2D constructor and merge() for a way to compute a union-like rectangle.

Referenced by G3D::RenderDevice::intersectClip2D().

◆ intersects()

bool G3D::Rect2D::intersects ( const Rect2D r) const
inline

True if there is non-zero area to the intersection between this and r.

Note that two rectangles that are adjacent do not intersect because there is zero area to the overlap, even though one of them "contains" the corners of the other.

Referenced by intersect().

◆ intersectsOrTouches()

bool G3D::Rect2D::intersectsOrTouches ( const Rect2D r) const
inline

Like intersection, but counts the adjacent case as touching.

◆ isEmpty()

bool G3D::Rect2D::isEmpty ( ) const
inline

Returns true if this is the empty set, which is distinct from a zero-area rectangle.

Referenced by extent(), G3D::Args::hasRect(), height(), merge(), wh(), and width().

◆ isFinite()

bool G3D::Rect2D::isFinite ( ) const
inline

◆ largestCenteredSubRect()

Rect2D G3D::Rect2D::largestCenteredSubRect ( float  ww,
float  hh 
) const
inline

Returns the largest, centered Rect2D that can fit inside this while maintaining the aspect ratio of x:y.

Convenient for displaying images in odd-shaped windows.

◆ lerp()

Rect2D G3D::Rect2D::lerp ( const Rect2D other,
float  alpha 
) const
inline

◆ merge()

void G3D::Rect2D::merge ( const Rect2D other)
inline

Referenced by Rect2D().

◆ operator!=()

bool G3D::Rect2D::operator!= ( const Rect2D other) const
inline

◆ operator*() [1/2]

Rect2D G3D::Rect2D::operator* ( float  s) const
inline

◆ operator*() [2/2]

Rect2D G3D::Rect2D::operator* ( const Vector2 s) const
inline

◆ operator+()

Rect2D G3D::Rect2D::operator+ ( const Vector2 v) const
inline

◆ operator-()

Rect2D G3D::Rect2D::operator- ( const Vector2 v) const
inline

◆ operator/() [1/2]

Rect2D G3D::Rect2D::operator/ ( float  s) const
inline

◆ operator/() [2/2]

Rect2D G3D::Rect2D::operator/ ( const Vector2 s) const
inline

◆ operator==()

bool G3D::Rect2D::operator== ( const Rect2D other) const
inline

◆ randomPoint()

Point2 G3D::Rect2D::randomPoint ( ) const
inline

Uniformly random point on the interior.

◆ serialize()

void G3D::Rect2D::serialize ( class BinaryOutput b) const

◆ toAny()

Any G3D::Rect2D::toAny ( ) const

Converts the Rect2D to an Any.

◆ wh()

Vector2 G3D::Rect2D::wh ( ) const
inline

Width and height.

Referenced by G3D::GuiControl::toOSWindowCoords().

◆ width()

float G3D::Rect2D::width ( ) const
inline

◆ x0()

float G3D::Rect2D::x0 ( ) const
inline

Referenced by border(), clip(), expand(), and xyxy().

◆ x0y0()

Point2 G3D::Rect2D::x0y0 ( ) const
inline

◆ x0y1()

Point2 G3D::Rect2D::x0y1 ( ) const
inline

◆ x1()

float G3D::Rect2D::x1 ( ) const
inline

◆ x1y0()

Point2 G3D::Rect2D::x1y0 ( ) const
inline

◆ x1y1()

Point2 G3D::Rect2D::x1y1 ( ) const
inline

Max,max corner.

◆ xywh() [1/2]

static Rect2D G3D::Rect2D::xywh ( float  x,
float  y,
float  w,
float  h 
)
inlinestatic

◆ xywh() [2/2]

static Rect2D G3D::Rect2D::xywh ( const Point2 v,
const Vector2 w 
)
inlinestatic

◆ xyxy() [1/2]

static Rect2D G3D::Rect2D::xyxy ( float  x0,
float  y0,
float  x1,
float  y1 
)
inlinestatic

◆ xyxy() [2/2]

static Rect2D G3D::Rect2D::xyxy ( const Point2 v0,
const Point2 v1 
)
inlinestatic

◆ y0()

float G3D::Rect2D::y0 ( ) const
inline

Referenced by border(), clip(), expand(), and xyxy().

◆ y1()

float G3D::Rect2D::y1 ( ) const
inline

Referenced by clip(), and xyxy().


documentation generated on Wed Nov 24 2021 08:01:59 using doxygen 1.8.15