CUGL 4.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cugl::IVec2 Class Reference

#include <CUIVec2.h>

Public Member Functions

 IVec2 ()
 
 IVec2 (int x, int y)
 
 IVec2 (const int *array)
 
 IVec2 (const IVec2 &p1, const IVec2 &p2)
 
IVec2operator= (const int *array)
 
IVec2set (int x, int y)
 
IVec2set (const int *array)
 
IVec2set (const IVec2 &v)
 
IVec2set (const IVec2 &p1, const IVec2 &p2)
 
IVec2setZero ()
 
IVec2clamp (const IVec2 &min, const IVec2 &max)
 
IVec2 getClamp (const IVec2 &min, const IVec2 &max) const
 
IVec2add (const IVec2 &v)
 
IVec2add (int x, int y)
 
IVec2subtract (const IVec2 &v)
 
IVec2subtract (int x, int y)
 
IVec2scale (int s)
 
IVec2scale (int sx, int sy)
 
IVec2scale (const IVec2 &v)
 
IVec2negate ()
 
IVec2 getNegation () const
 
IVec2map (std::function< int(int)> func)
 
IVec2 getMap (std::function< int(int)> func) const
 
IVec2operator+= (const IVec2 &v)
 
IVec2operator-= (const IVec2 v)
 
IVec2operator*= (int s)
 
IVec2operator*= (const IVec2 &v)
 
const IVec2 operator+ (const IVec2 v) const
 
const IVec2 operator- (const IVec2 &v) const
 
const IVec2 operator- () const
 
const IVec2 operator* (int s) const
 
const IVec2 operator* (const IVec2 &v) const
 
bool operator< (const IVec2 &v) const
 
bool operator<= (const IVec2 &v) const
 
bool operator> (const IVec2 &v) const
 
bool operator>= (const IVec2 &v) const
 
bool operator== (const IVec2 &v) const
 
bool operator!= (const IVec2 &v) const
 
bool under (const IVec2 &v) const
 
bool over (const IVec2 &v) const
 
bool equals (const IVec2 &v) const
 
bool isZero () const
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Vec2 () const
 
 IVec2 (const Vec2 &v)
 
IVec2operator= (const Vec2 &v)
 
IVec2operator+= (const Vec2 &v)
 
IVec2operator-= (const Vec2 &v)
 
IVec2operator*= (const Vec2 &v)
 
const IVec2 operator+ (const Vec2 &v)
 
const IVec2 operator- (const Vec2 &v)
 
const IVec2 operator* (const Vec2 &v)
 
 operator IVec3 () const
 
 IVec2 (const IVec3 &v)
 
IVec2operator= (const IVec3 &size)
 
 operator IVec4 () const
 
 IVec2 (const IVec4 &v)
 
IVec2operator= (const IVec4 &v)
 

Static Public Member Functions

static IVec2clamp (const IVec2 &v, const IVec2 &min, const IVec2 &max, IVec2 *dst)
 
static IVec2add (const IVec2 &v1, const IVec2 &v2, IVec2 *dst)
 
static IVec2subtract (const IVec2 &v1, const IVec2 &v2, IVec2 *dst)
 
static IVec2scale (const IVec2 &v, int s, IVec2 *dst)
 
static IVec2scale (const IVec2 &v1, const IVec2 &v2, IVec2 *dst)
 
static IVec2negate (const IVec2 &v, IVec2 *dst)
 

Public Attributes

int x
 
int y
 

Static Public Attributes

static const IVec2 ZERO
 
static const IVec2 ONE
 

Detailed Description

This class defines a 2-element integer vector.

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

Constructor & Destructor Documentation

◆ IVec2() [1/7]

cugl::IVec2::IVec2 ( )
inline

Constructs a new vector initialized to all zeros.

◆ IVec2() [2/7]

cugl::IVec2::IVec2 ( int  x,
int  y 
)
inline

Constructs a new vector initialized to the specified values.

Parameters
xThe x coordinate.
yThe y coordinate.

◆ IVec2() [3/7]

cugl::IVec2::IVec2 ( const int *  array)
inline

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

Parameters
arrayAn array containing the elements of the vector in the order x, y.

◆ IVec2() [4/7]

cugl::IVec2::IVec2 ( const IVec2 p1,
const IVec2 p2 
)
inline

Constructs a vector that describes the direction between the specified points.

Parameters
p1The first point
p2The second point

◆ IVec2() [5/7]

cugl::IVec2::IVec2 ( const Vec2 v)
explicit

Creates a vector from the given floating point vector.

The float values are truncated.

Parameters
vThe vector to convert

◆ IVec2() [6/7]

cugl::IVec2::IVec2 ( const IVec3 v)
explicit

Creates a 2d vector from the given 3d one.

The z-value is dropped.

Parameters
vThe vector to convert

◆ IVec2() [7/7]

cugl::IVec2::IVec2 ( const IVec4 v)
explicit

Creates a 2d vector from the given 4d one.

The z and w coordinates are dropped.

Parameters
vThe vector to convert

Member Function Documentation

◆ add() [1/3]

IVec2 & cugl::IVec2::add ( const IVec2 v)
inline

Adds the given vector to this one in place.

Parameters
vThe vector to add
Returns
A reference to this (modified) IVec2 for chaining.

◆ add() [2/3]

static IVec2 * cugl::IVec2::add ( const IVec2 v1,
const IVec2 v2,
IVec2 dst 
)
static

Adds the specified vectors and stores the result in dst.

Parameters
v1The first vector.
v2The second vector.
dstA vector to store the result in
Returns
A reference to dst for chaining

◆ add() [3/3]

IVec2 & cugl::IVec2::add ( int  x,
int  y 
)
inline

Adds the given values to this vector.

Parameters
xThe x coordinate to add.
yThe y coordinate to add.
Returns
A reference to this (modified) IVec2 for chaining.

◆ clamp() [1/2]

IVec2 & cugl::IVec2::clamp ( const IVec2 min,
const IVec2 max 
)

Clamps this vector within the given range.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
A reference to this (modified) Vec2 for chaining.

◆ clamp() [2/2]

static IVec2 * cugl::IVec2::clamp ( const IVec2 v,
const IVec2 min,
const IVec2 max,
IVec2 dst 
)
static

Clamps the specified vector within the given range and returns it in dst.

Parameters
vThe vector to clamp.
minThe minimum value.
maxThe maximum value.
dstA vector to store the result in.
Returns
A reference to dst for chaining

◆ equals()

bool cugl::IVec2::equals ( const IVec2 v) const
inline

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

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

◆ getClamp()

IVec2 cugl::IVec2::getClamp ( const IVec2 min,
const IVec2 max 
) const
inline

Returns a copy of this vector clamped within the given range.

Note: this does not modify this vector.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
A copy of this vector clamped within the given range.

◆ getMap()

IVec2 cugl::IVec2::getMap ( std::function< int(int)>  func) const
inline

Returns a copy of this vector with func applied to each component.

This method supports any function that has the signature float func(float); This includes many of the functions in math.h.

Parameters
funcThe function to map on the coordinates.
Returns
A copy of this vector with func applied to each component.

◆ getNegation()

IVec2 cugl::IVec2::getNegation ( ) const
inline

Returns a negated copy of this vector.

Note: This method does not modify the vector

Returns
a negated copy of this vector.

◆ isZero()

bool cugl::IVec2::isZero ( ) const
inline

Returns true this vector contains all zeros.

Returns
true if this vector contains all zeros, false otherwise.

◆ map()

IVec2 & cugl::IVec2::map ( std::function< int(int)>  func)
inline

Maps the given function to the vector coordinates in place.

This method supports any function that has the signature float func(float); This includes many of the functions in math.h.

Parameters
funcThe function to map on the coordinates.
Returns
A reference to this (modified) Vec2 for chaining.

◆ negate() [1/2]

IVec2 & cugl::IVec2::negate ( )
inline

Negates this vector.

Returns
A reference to this (modified) IVec2 for chaining.

◆ negate() [2/2]

static IVec2 * cugl::IVec2::negate ( const IVec2 v,
IVec2 dst 
)
static

Negates the specified vector and stores the result in dst.

Parameters
vThe vector to negate.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ operator IVec3()

cugl::IVec2::operator IVec3 ( ) const

Casts from IVec2 to IVec2.

The z-value is set to 0.

◆ operator IVec4()

cugl::IVec2::operator IVec4 ( ) const

Casts from IVec2 to IVec4.

The z and w coordinates are set to 0.

◆ operator std::string()

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

Cast from IVec2 to a string.

◆ operator Vec2()

cugl::IVec2::operator Vec2 ( ) const

Cast from IVec2 to Vec2.

◆ operator!=()

bool cugl::IVec2::operator!= ( const IVec2 v) const
inline

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

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

◆ operator*() [1/3]

const IVec2 cugl::IVec2::operator* ( const IVec2 v) const
inline

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

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

Parameters
vThe vector to scale by.
Returns
The scalar product of this vector with the given vector.

◆ operator*() [2/3]

const IVec2 cugl::IVec2::operator* ( const Vec2 v)

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

The float values of v are truncated.

Note: this does not modify this vector.

Parameters
vThe vector to scale by.
Returns
The scalar product of this vector with the given vector.

◆ operator*() [3/3]

const IVec2 cugl::IVec2::operator* ( int  s) const
inline

Returns the scalar product of this vector with the given value.

Note: this does not modify this vector.

Parameters
sThe value to scale by.
Returns
The scalar product of this vector with the given value.

◆ operator*=() [1/3]

IVec2 & cugl::IVec2::operator*= ( const IVec2 v)
inline

Scales this vector nonuniformly by the given vector.

Parameters
vThe vector to scale by
Returns
A reference to this (modified) Vec2 for chaining.

◆ operator*=() [2/3]

IVec2 & cugl::IVec2::operator*= ( const Vec2 v)

Scales this vector nonuniformly by the given vector.

The float values of v are truncated.

Parameters
vThe vector to scale by
Returns
A reference to this (modified) Vec2 for chaining.

◆ operator*=() [3/3]

IVec2 & cugl::IVec2::operator*= ( int  s)
inline

Scales this vector in place by the given factor.

Parameters
sThe value to scale by
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator+() [1/2]

const IVec2 cugl::IVec2::operator+ ( const IVec2  v) const
inline

Returns the sum of this vector with the given vector.

Note: this does not modify this vector.

Parameters
vThe vector to add.
Returns
The sum of this vector with the given vector.

◆ operator+() [2/2]

const IVec2 cugl::IVec2::operator+ ( const Vec2 v)

Returns the sum of this vector with the given vector.

The float values of v are truncated.

Note: this does not modify this vector.

Parameters
vThe vector to add.
Returns
The sum of this vector with the given vector.

◆ operator+=() [1/2]

IVec2 & cugl::IVec2::operator+= ( const IVec2 v)
inline

Adds the given vector to this one in place.

Parameters
vThe vector to add
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator+=() [2/2]

IVec2 & cugl::IVec2::operator+= ( const Vec2 v)

Adds the given vector to this one in place.

The float values of v are truncated.

Parameters
vThe vector to add
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator-() [1/3]

const IVec2 cugl::IVec2::operator- ( ) const
inline

Returns the negation of this vector.

Note: this does not modify this vector.

Returns
The negation of this vector.

◆ operator-() [2/3]

const IVec2 cugl::IVec2::operator- ( const IVec2 v) const
inline

Returns the difference of this vector with the given vector.

Note: this does not modify this vector.

Parameters
vThe vector to subtract.
Returns
The difference of this vector with the given vector.

◆ operator-() [3/3]

const IVec2 cugl::IVec2::operator- ( const Vec2 v)

Returns the difference of this vector with the given vector.

The float values of v are truncated.

Note: this does not modify this vector.

Parameters
vThe vector to subtract.
Returns
The difference of this vector with the given vector.

◆ operator-=() [1/2]

IVec2 & cugl::IVec2::operator-= ( const IVec2  v)
inline

Subtracts the given vector from this one in place.

Parameters
vThe vector to subtract
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator-=() [2/2]

IVec2 & cugl::IVec2::operator-= ( const Vec2 v)

Subtracts the given vector from this one in place.

The float values of v are truncated.

Parameters
vThe vector to subtract
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator<()

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

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

This comparison uses the lexicographical order. To test if all components in this vector are less than those of v, use the method under().

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

◆ operator<=()

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

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

This comparison uses the lexicographical order. To test if all components in this vector are less than those of v, use the method under().

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

◆ operator=() [1/4]

IVec2 & cugl::IVec2::operator= ( const int *  array)
inline

Sets the elements of this vector from the values in the specified array.

Parameters
arrayAn array containing the elements of the vector in the order x, y.
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator=() [2/4]

IVec2 & cugl::IVec2::operator= ( const IVec3 size)

Sets the coordinates of this vector to those of the given 3d vector.

The z-value is dropped.

Parameters
sizeThe vector to convert
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator=() [3/4]

IVec2 & cugl::IVec2::operator= ( const IVec4 v)

Sets the coordinates of this vector to those of the given 4d vector.

The z and w coordinates are dropped.

Parameters
vThe vector to convert
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator=() [4/4]

IVec2 & cugl::IVec2::operator= ( const Vec2 v)

Sets this vector to be the given floating point vector.

The float values are truncated.

Parameters
vThe vector to convert
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator==()

bool cugl::IVec2::operator== ( const IVec2 v) const
inline

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

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

◆ operator>()

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

Returns true if this vector is greater than the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are greater than those of v, use the method over().

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

◆ operator>=()

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

Returns true if this vector is greater than or equal the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are greater than those of v, use the method over().

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

◆ over()

bool cugl::IVec2::over ( const IVec2 v) const
inline

Returns true if this vector dominates the given vector.

Domination means that all components of this vector are greater than or equal to the components of the given vector.

Parameters
vThe vector to compare against.
Returns
True if this vector is dominated by the given vector.

◆ scale() [1/5]

IVec2 & cugl::IVec2::scale ( const IVec2 v)
inline

Scales this vector nonuniformly by the given vector.

Parameters
vThe vector to scale by
Returns
A reference to this (modified) IVec2 for chaining.

◆ scale() [2/5]

static IVec2 * cugl::IVec2::scale ( const IVec2 v,
int  s,
IVec2 dst 
)
static

Scales the specified vector and stores the result in dst.

The scale is uniform by the constant s.

Parameters
vThe vector to scale.
sThe uniform scaling factor.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ scale() [3/5]

static IVec2 * cugl::IVec2::scale ( const IVec2 v1,
const IVec2 v2,
IVec2 dst 
)
static

Scales the specified vector and stores the result in dst.

The scale is nonuniform by the attributes in v2.

Parameters
v1The vector to scale.
v2The nonuniform scaling factor.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ scale() [4/5]

IVec2 & cugl::IVec2::scale ( int  s)
inline

Scales this vector in place by the given factor.

Parameters
sThe scalar to multiply by
Returns
A reference to this (modified) IVec2 for chaining.

◆ scale() [5/5]

IVec2 & cugl::IVec2::scale ( int  sx,
int  sy 
)
inline

Scales this vector nonuniformly by the given factors.

Parameters
sxThe scalar to multiply the x-axis
syThe scalar to multiply the y-axis
Returns
A reference to this (modified) IVec2 for chaining.

◆ set() [1/4]

IVec2 & cugl::IVec2::set ( const int *  array)
inline

Sets the elements of this vector from the values in the specified array.

Parameters
arrayAn array containing the elements of the vector in the order x, y.
Returns
A reference to this (modified) IVec2 for chaining.

◆ set() [2/4]

IVec2 & cugl::IVec2::set ( const IVec2 p1,
const IVec2 p2 
)
inline

Sets this vector to the directional vector between the specified points.

Parameters
p1The initial point of the vector.
p2The terminal point of the vector.
Returns
A reference to this (modified) IVec2 for chaining.

◆ set() [3/4]

IVec2 & cugl::IVec2::set ( const IVec2 v)
inline

Sets the elements of this vector to those in the specified vector.

Parameters
vThe vector to copy.
Returns
A reference to this (modified) IVec2 for chaining.

◆ set() [4/4]

IVec2 & cugl::IVec2::set ( int  x,
int  y 
)
inline

Sets the elements of this vector to the specified values.

Parameters
xThe new x coordinate.
yThe new y coordinate.
Returns
A reference to this (modified) IVec2 for chaining.

◆ setZero()

IVec2 & cugl::IVec2::setZero ( )
inline

Sets the elements of this vector to zero.

Returns
A reference to this (modified) Vec2 for chaining.

◆ subtract() [1/3]

IVec2 & cugl::IVec2::subtract ( const IVec2 v)
inline

Subtracts the given vector from this one in place.

Parameters
vThe vector to subtract
Returns
A reference to this (modified) IVec2 for chaining.

◆ subtract() [2/3]

static IVec2 * cugl::IVec2::subtract ( const IVec2 v1,
const IVec2 v2,
IVec2 dst 
)
static

Subtracts the specified vectors and stores the result in dst. The resulting vector is computed as (v1 - v2).

Parameters
v1The first vector.
v2The second vector.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ subtract() [3/3]

IVec2 & cugl::IVec2::subtract ( int  x,
int  y 
)
inline

Subtracts the given values from this vector.

Parameters
xThe x coordinate to subtract.
yThe y coordinate to subtract.
Returns
A reference to this (modified) IVec2 for chaining.

◆ toString()

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

Returns a string representation of this vector 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 vector for debuggging purposes.

◆ under()

bool cugl::IVec2::under ( const IVec2 v) const
inline

Returns true if this vector is dominated by the given vector.

Domination means that all components of the given vector are greater than or equal to the components of this one.

Parameters
vThe vector to compare against.
Returns
True if this vector is dominated by the given vector.

Member Data Documentation

◆ ONE

const IVec2 cugl::IVec2::ONE
static

The unit vector IVec2(1,1)

◆ x

int cugl::IVec2::x

The x coordinate.

◆ y

int cugl::IVec2::y

The x coordinate.

◆ ZERO

const IVec2 cugl::IVec2::ZERO
static

The zero vector IVec2(0,0)


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