CUGL 2.1
Cornell University Game Library
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cugl::Size Class Reference

#include <CUSize.h>

Public Member Functions

 Size ()
 
 Size (float width, float height)
 
 Size (const float *array)
 
Sizeoperator= (const float *array)
 
Sizeset (float width, float height)
 
Sizeset (const float *array)
 
Sizeset (const Size other)
 
int getIWidth () const
 
int getIHeight () const
 
bool operator< (const Size v) const
 
bool operator<= (const Size v) const
 
bool operator> (const Size v) const
 
bool operator>= (const Size v) const
 
bool operator== (const Size other) const
 
bool operator!= (const Size other) const
 
bool inside (const Size other) const
 
bool contains (const Size other) const
 
bool equals (const Size other, float variance=CU_MATH_EPSILON) const
 
Sizeoperator+= (const Size right)
 
Sizeoperator-= (const Size right)
 
Sizeoperator*= (float a)
 
Sizeoperator*= (const Size right)
 
Sizeoperator/= (float a)
 
Sizeoperator/= (const Size right)
 
Size operator+ (const Size right) const
 
Size operator- (const Size right) const
 
Size operator* (float scalar) const
 
Size operator* (const Size right) const
 
Size operator/ (float scalar) const
 
Size operator/ (const Size right) const
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Vec2 () const
 
 Size (const Vec2 point)
 
 Size (const Vec2 p1, const Vec2 p2)
 
Sizeset (const Vec2 p1, const Vec2 p2)
 
Sizeoperator= (const Vec2 point)
 

Public Attributes

float width
 
float height
 

Static Public Attributes

static const Size ZERO
 

Detailed Description

This class defines a the size of a two dimensional box

Instances of this class may be freely cast to Vec2 and vice-versa.

This class is in standard layout with fields of uniform type. This means that it is also safe to reinterpret_cast objects to float arrays.

Constructor & Destructor Documentation

◆ Size() [1/5]

cugl::Size::Size ( )
inline

Creates a new degenerate size

The width and height of the size are zero.

◆ Size() [2/5]

cugl::Size::Size ( float  width,
float  height 
)
inline

Creates a new size with the given dimensions

Parameters
widthThe width value
heightThe height value

◆ Size() [3/5]

cugl::Size::Size ( const float *  array)
inline

Constructs a new size from the values in the specified array.

The array is read in the order width and height

Parameters
arrayAn array containing at least two elements.

◆ Size() [4/5]

cugl::Size::Size ( const Vec2  point)
explicit

Creates a size from the given Vec2

The x coordinate is converted to width and y to height.

Parameters
pointThe vector to convert

◆ Size() [5/5]

cugl::Size::Size ( const Vec2  p1,
const Vec2  p2 
)

Creates the smallest size containing the two points.

Parameters
p1The first point.
p2The second point.

Member Function Documentation

◆ contains()

bool cugl::Size::contains ( const Size  other) const
inline

Returns true if this size can hold the given size.

The means that all dimensions of the current size are greater than or equal to the size parameter.

Parameters
otherThe potentially smaller size
Returns
True if this size can hold the given size.

◆ equals()

bool cugl::Size::equals ( const Size  other,
float  variance = CU_MATH_EPSILON 
) const
inline

Returns true if the sizes are within tolerance of each other.

The tolerance bound is on each axis independently.

Parameters
otherThe size to compare against.
varianceThe comparison tolerance.
Returns
true if the sizes are within tolerance of each other.

◆ getIHeight()

int cugl::Size::getIHeight ( ) const
inline

Returns the Size height as an integer.

The value is always rounded up.

Returns
the Size height as an integer.

◆ getIWidth()

int cugl::Size::getIWidth ( ) const
inline

Returns the Size width as an integer.

The value is always rounded up.

Returns
the Size width as an integer.

◆ inside()

bool cugl::Size::inside ( const Size  other) const
inline

Returns true if this size fits inside of the given size.

The means that all dimensions of the current size are less than or equal to the size parameter.

Parameters
otherThe potentially larger size
Returns
True if this size fits inside of the given size.

◆ operator std::string()

cugl::Size::operator std::string ( ) const
inline

Cast from Size to a string.

◆ operator Vec2()

cugl::Size::operator Vec2 ( ) const

Cast from from Size to Vec2.

◆ operator!=()

bool cugl::Size::operator!= ( const Size  other) const
inline

Returns true if this size is not equal to the given size.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
otherThe vector to compare against.
Returns
True if this size is not equal to the given size.

◆ operator*() [1/2]

Size cugl::Size::operator* ( const Size  right) const
inline

Returns the scalar product of this size with the given size.

This method is provided to support non-uniform scaling. Note: this does not modify this size.

Parameters
rightThe size to scale by.
Returns
The scalar product of this size with the given size.

◆ operator*() [2/2]

Size cugl::Size::operator* ( float  scalar) const
inline

Returns the scalar product of this size with the given size.

Note: this does not modify this size.

Parameters
scalarThe value to scale by.
Returns
The scalar product of this size with the given value.

◆ operator*=() [1/2]

Size& cugl::Size::operator*= ( const Size  right)
inline

Scales this size in place by the given vector.

Parameters
rightThe vector to scale by
Returns
A reference to this (modified) Size for chaining.

◆ operator*=() [2/2]

Size& cugl::Size::operator*= ( float  a)
inline

Scales this size in place by the given factor.

Parameters
aThe value to scale by
Returns
A reference to this (modified) Size for chaining.

◆ operator+()

Size cugl::Size::operator+ ( const Size  right) const
inline

Returns the sum of this size with the given size.

Note: this does not modify this size.

Parameters
rightThe size to add.
Returns
The sum of this size with the given size.

◆ operator+=()

Size& cugl::Size::operator+= ( const Size  right)
inline

Adds the given size to this one in place.

Parameters
rightThe size to add
Returns
A reference to this (modified) Size for chaining.

◆ operator-()

Size cugl::Size::operator- ( const Size  right) const
inline

Returns the difference of this size with the given size.

Note: this does not modify this size.

Parameters
rightThe size to subtract.
Returns
The difference of this size with the given size.

◆ operator-=()

Size& cugl::Size::operator-= ( const Size  right)
inline

Subtracts the given size from this one in place.

Parameters
rightThe size to subtract
Returns
A reference to this (modified) Size for chaining.

◆ operator/() [1/2]

Size cugl::Size::operator/ ( const Size  right) const
inline

Returns a copy of this size divided by the given size.

This method is provided to support non-uniform scaling. Note: this does not modify this size.

Parameters
rightthe size to divide this size with
Returns
A copy of this size divided by the given size

◆ operator/() [2/2]

Size cugl::Size::operator/ ( float  scalar) const
inline

Returns a copy of this size divided by the given constant

Note: this does not modify this size.

Parameters
scalarthe constant to divide this size with
Returns
A copy of this size divided by the given constant

◆ operator/=() [1/2]

Size& cugl::Size::operator/= ( const Size  right)

Divides this size in place by the given size.

This method is provided to support non-uniform scaling.

Parameters
rightThe size to divide by
Returns
A reference to this (modified) Size for chaining.

◆ operator/=() [2/2]

Size& cugl::Size::operator/= ( float  a)

Divides this size in place by the given factor.

Parameters
aThe scalar to divide by
Returns
A reference to this (modified) Size for chaining.

◆ operator<()

bool cugl::Size::operator< ( const Size  v) const
inline

Returns true if this size is less than the given size.

This comparison uses the lexicographical order. To test if this size can properly fit inside theother, use the method inside().

Parameters
vThe size to compare against.
Returns
True if this size is less than the given size.

◆ operator<=()

bool cugl::Size::operator<= ( const Size  v) const
inline

Returns true if this Size is less than or equal the given Size.

This comparison uses the lexicographical order. To test if this Size can properly fit inside theother, use the method inside().

Parameters
vThe size to compare against.
Returns
True if this size is less than or equal the given size.

◆ operator=() [1/2]

Size& cugl::Size::operator= ( const float *  array)
inline

Sets the dimensions of this size to the contents of the given array.

The array is read in the order width and height

Parameters
arrayAn array containing at least two elements.
Returns
A reference to this (modified) Size for chaining.

◆ operator=() [2/2]

Size& cugl::Size::operator= ( const Vec2  point)

Sets the dimensions of this size to those of the given vector.

The x coordinate is converted to width and y to height.

Parameters
pointThe vector to convert.
Returns
A reference to this (modified) Size for chaining.

◆ operator==()

bool cugl::Size::operator== ( const Size  other) const
inline

Returns true if this size is equal to the given size.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
otherThe vector to compare against.
Returns
True if this size is equal to the given size.

◆ operator>()

bool cugl::Size::operator> ( const Size  v) const
inline

Determines if this size is greater than the given size.

This comparison uses the lexicographical order. To test if this size can properly hold the other vector, use the method contains().

Parameters
vThe vector to compare against.
Returns
True if this size is greater than the given size.

◆ operator>=()

bool cugl::Size::operator>= ( const Size  v) const
inline

Determines if this size is greater than or equal to the given size.

This comparison uses the lexicographical order. To test if this size can properly hold the other vector, use the method contains().

Parameters
vThe vector to compare against.
Returns
True if this size is greater than or equal to the given size.

◆ set() [1/4]

Size& cugl::Size::set ( const float *  array)
inline

Sets the dimensions of this size from the values in the specified array.

The array is read in the order width and height

Parameters
arrayAn array containing at least two elements.
Returns
A reference to this (modified) Siz for chaining.

◆ set() [2/4]

Size& cugl::Size::set ( const Size  other)
inline

Sets the dimensions of this size to those in the specified size.

Parameters
otherThe size to copy.
Returns
A reference to this (modified) Size for chaining.

◆ set() [3/4]

Size& cugl::Size::set ( const Vec2  p1,
const Vec2  p2 
)

Sets this size to the smallest one containing the two points.

Parameters
p1The first point.
p2The second point.
Returns
A reference to this (modified) Vec2 for chaining.

◆ set() [4/4]

Size& cugl::Size::set ( float  width,
float  height 
)
inline

Sets the dimensions of this size to the specified values.

Parameters
widthThe new width value
heightThe new height value
Returns
A reference to this (modified) Size for chaining.

◆ toString()

std::string cugl::Size::toString ( bool  verbose = false) const

Returns a string representation of this size for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this size for debugging purposes.

Member Data Documentation

◆ height

float cugl::Size::height

Height of the Size object.

◆ width

float cugl::Size::width

Width of the Size object.

◆ ZERO

const Size cugl::Size::ZERO
static

The degnerate Size(0,0).


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