This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GfRect2i Class Reference

A 2D rectangle with integer coordinates. More...

#include <rect2i.h>

Public Member Functions

 GfRect2i ()
 Constructs an empty rectangle.
 
 GfRect2i (const GfVec2i &min, const GfVec2i &max)
 Constructs a rectangle with min and max corners.
 
 GfRect2i (const GfVec2i &min, int width, int height)
 Constructs a rectangle with min corner and the indicated width and height.
 
bool IsNull () const
 Returns true if the rectangle is a null rectangle.
 
bool IsEmpty () const
 Returns true if the rectangle is empty.
 
bool IsValid () const
 Return true if the rectangle is valid (equivalently, not empty).
 
GF_API GfRect2i GetNormalized () const
 Returns a normalized rectangle, i.e.
 
const GfVec2iGetMin () const
 Returns the min corner of the rectangle.
 
const GfVec2iGetMax () const
 Returns the max corner of the rectangle.
 
int GetMinX () const
 Return the X value of min corner.
 
void SetMinX (int x)
 Set the X value of the min corner.
 
int GetMaxX () const
 Return the X value of the max corner.
 
void SetMaxX (int x)
 Set the X value of the max corner.
 
int GetMinY () const
 Return the Y value of the min corner.
 
void SetMinY (int y)
 Set the Y value of the min corner.
 
int GetMaxY () const
 Return the Y value of the max corner.
 
void SetMaxY (int y)
 Set the Y value of the max corner.
 
void SetMin (const GfVec2i &min)
 Sets the min corner of the rectangle.
 
void SetMax (const GfVec2i &max)
 Sets the max corner of the rectangle.
 
GfVec2i GetCenter () const
 Returns the center point of the rectangle.
 
void Translate (const GfVec2i &displacement)
 Move the rectangle by displ.
 
unsigned long GetArea () const
 Return the area of the rectangle.
 
GfVec2i GetSize () const
 Returns the size of the rectangle as a vector (width,height).
 
int GetWidth () const
 Returns the width of the rectangle.
 
int GetHeight () const
 Returns the height of the rectangle.
 
GfRect2i GetIntersection (const GfRect2i &that) const
 Computes the intersection of two rectangles.
 
GfRect2i Intersect (const GfRect2i &that) const
 Computes the intersection of two rectangles.
 
GfRect2i GetUnion (const GfRect2i &that) const
 Computes the union of two rectangles.
 
GfRect2i Union (const GfRect2i &that) const
 Computes the union of two rectangles.
 
bool Contains (const GfVec2i &p) const
 Returns true if the specified point in the rectangle.
 
GfRect2i operator+= (const GfRect2i &that)
 Computes the union of two rectangles.
 

Friends

size_t hash_value (const GfRect2i &r)
 
bool operator== (const GfRect2i &r1, const GfRect2i &r2)
 Returns true if r1 and r2 are equal.
 
bool operator!= (const GfRect2i &r1, const GfRect2i &r2)
 Returns true if r1 and r2 are different.
 
GfRect2i operator+ (const GfRect2i r1, const GfRect2i &r2)
 

Detailed Description

A 2D rectangle with integer coordinates.

A rectangle is internally represented as two corners. We refer to these as the min and max corner where the min's x-coordinate and y-coordinate are assumed to be less than or equal to the max's corresponding coordinates. Normally, it is expressed as a min corner and a size.

Note that the max corner is included when computing the size (width and height) of a rectangle as the number of integral points in the x- and y-direction. In particular, if the min corner and max corner are the same, then the width and the height of the rectangle will both be one since we have exactly one integral point with coordinates greater or equal to the min corner and less or equal to the max corner.

Specifically, width = maxX - minX + 1 and height = maxY - minY + 1.

Definition at line 43 of file rect2i.h.

Constructor & Destructor Documentation

◆ GfRect2i() [1/3]

GfRect2i ( )
inline

Constructs an empty rectangle.

Definition at line 46 of file rect2i.h.

◆ GfRect2i() [2/3]

GfRect2i ( const GfVec2i min,
const GfVec2i max 
)
inline

Constructs a rectangle with min and max corners.

Definition at line 51 of file rect2i.h.

◆ GfRect2i() [3/3]

GfRect2i ( const GfVec2i min,
int  width,
int  height 
)
inline

Constructs a rectangle with min corner and the indicated width and height.

Definition at line 58 of file rect2i.h.

Member Function Documentation

◆ Contains()

bool Contains ( const GfVec2i p) const
inline

Returns true if the specified point in the rectangle.

Definition at line 246 of file rect2i.h.

◆ GetArea()

unsigned long GetArea ( ) const
inline

Return the area of the rectangle.

Definition at line 182 of file rect2i.h.

◆ GetCenter()

GfVec2i GetCenter ( ) const
inline

Returns the center point of the rectangle.

Definition at line 171 of file rect2i.h.

◆ GetHeight()

int GetHeight ( ) const
inline

Returns the height of the rectangle.

Note
If the min and max y-coordinates are coincident, the height is one.

Definition at line 203 of file rect2i.h.

◆ GetIntersection()

GfRect2i GetIntersection ( const GfRect2i that) const
inline

Computes the intersection of two rectangles.

Definition at line 208 of file rect2i.h.

◆ GetMax()

const GfVec2i & GetMax ( ) const
inline

Returns the max corner of the rectangle.

Definition at line 111 of file rect2i.h.

◆ GetMaxX()

int GetMaxX ( ) const
inline

Return the X value of the max corner.

Definition at line 129 of file rect2i.h.

◆ GetMaxY()

int GetMaxY ( ) const
inline

Return the Y value of the max corner.

Definition at line 151 of file rect2i.h.

◆ GetMin()

const GfVec2i & GetMin ( ) const
inline

Returns the min corner of the rectangle.

Definition at line 106 of file rect2i.h.

◆ GetMinX()

int GetMinX ( ) const
inline

Return the X value of min corner.

Definition at line 117 of file rect2i.h.

◆ GetMinY()

int GetMinY ( ) const
inline

Return the Y value of the min corner.

Definition at line 140 of file rect2i.h.

◆ GetNormalized()

GF_API GfRect2i GetNormalized ( ) const

Returns a normalized rectangle, i.e.

one that has a non-negative width and height.

GetNormalized() swaps the min and max x-coordinates to ensure a non-negative width, and similarly for the y-coordinates.

◆ GetSize()

GfVec2i GetSize ( ) const
inline

Returns the size of the rectangle as a vector (width,height).

Definition at line 187 of file rect2i.h.

◆ GetUnion()

GfRect2i GetUnion ( const GfRect2i that) const
inline

Computes the union of two rectangles.

Definition at line 227 of file rect2i.h.

◆ GetWidth()

int GetWidth ( ) const
inline

Returns the width of the rectangle.

Note
If the min and max x-coordinates are coincident, the width is one.

Definition at line 195 of file rect2i.h.

◆ Intersect()

GfRect2i Intersect ( const GfRect2i that) const
inline

Computes the intersection of two rectangles.

Deprecated:
Use GetIntersection() instead

Definition at line 222 of file rect2i.h.

◆ IsEmpty()

bool IsEmpty ( ) const
inline

Returns true if the rectangle is empty.

An empty rectangle has one or both of its min coordinates strictly greater than the corresponding max coordinate.

An empty rectangle is not valid.

Definition at line 87 of file rect2i.h.

◆ IsNull()

bool IsNull ( ) const
inline

Returns true if the rectangle is a null rectangle.

A null rectangle has both the width and the height set to 0, that is

GetMaxX() == GetMinX() - 1
int GetMinX() const
Return the X value of min corner.
Definition: rect2i.h:117
int GetMaxX() const
Return the X value of the max corner.
Definition: rect2i.h:129

and

GetMaxY() == GetMinY() - 1
int GetMinY() const
Return the Y value of the min corner.
Definition: rect2i.h:140
int GetMaxY() const
Return the Y value of the max corner.
Definition: rect2i.h:151

Remember that if GetMinX() and GetMaxX() return the same value then the rectangle has width 1, and similarly for the height.

A null rectangle is both empty, and not valid.

Definition at line 77 of file rect2i.h.

◆ IsValid()

bool IsValid ( ) const
inline

Return true if the rectangle is valid (equivalently, not empty).

Definition at line 92 of file rect2i.h.

◆ operator+=()

GfRect2i operator+= ( const GfRect2i that)
inline

Computes the union of two rectangles.

See also
GetUnion()

Definition at line 267 of file rect2i.h.

◆ SetMax()

void SetMax ( const GfVec2i max)
inline

Sets the max corner of the rectangle.

Definition at line 166 of file rect2i.h.

◆ SetMaxX()

void SetMaxX ( int  x)
inline

Set the X value of the max corner.

Definition at line 134 of file rect2i.h.

◆ SetMaxY()

void SetMaxY ( int  y)
inline

Set the Y value of the max corner.

Definition at line 156 of file rect2i.h.

◆ SetMin()

void SetMin ( const GfVec2i min)
inline

Sets the min corner of the rectangle.

Definition at line 161 of file rect2i.h.

◆ SetMinX()

void SetMinX ( int  x)
inline

Set the X value of the min corner.

Definition at line 123 of file rect2i.h.

◆ SetMinY()

void SetMinY ( int  y)
inline

Set the Y value of the min corner.

Definition at line 146 of file rect2i.h.

◆ Translate()

void Translate ( const GfVec2i displacement)
inline

Move the rectangle by displ.

Definition at line 176 of file rect2i.h.

◆ Union()

GfRect2i Union ( const GfRect2i that) const
inline

Computes the union of two rectangles.

Deprecated:
Use GetUnion() instead.

Definition at line 241 of file rect2i.h.

Friends And Related Function Documentation

◆ hash_value

size_t hash_value ( const GfRect2i r)
friend

Definition at line 251 of file rect2i.h.

◆ operator!=

bool operator!= ( const GfRect2i r1,
const GfRect2i r2 
)
friend

Returns true if r1 and r2 are different.

Definition at line 261 of file rect2i.h.

◆ operator+

GfRect2i operator+ ( const GfRect2i  r1,
const GfRect2i r2 
)
friend

Definition at line 272 of file rect2i.h.

◆ operator==

bool operator== ( const GfRect2i r1,
const GfRect2i r2 
)
friend

Returns true if r1 and r2 are equal.

Definition at line 256 of file rect2i.h.


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