Kaim::Vec2i Class Reference

Kaim::Vec2i Class Reference

#include <vec2i.h>

Class Description

This class defines a two-dimensional vector whose coordinates are stored using 32-bit integers.

This class is typically used to identify a cell within a regular two-dimensional grid.

+ Examples:

Inherited by Kaim::RasterPoint.

Creation & Initialization

 Vec2i ()
 
 Vec2i (KyInt32 _x, KyInt32 _y)
 
 Vec2i (KyInt32 *coords)
 
void Set (KyInt32 _x, KyInt32 _y)
 
void Set (KyInt32 *coords)
 

Operators

KyInt32 operator[] (KyInt32 idx) const
 
KyInt32operator[] (KyInt32 idx)
 
bool operator== (const Vec2i &v) const
 
bool operator!= (const Vec2i &v) const
 
bool operator< (const Vec2i &v) const
 
bool operator<= (const Vec2i &v) const
 
bool operator> (const Vec2i &v) const
 
bool operator>= (const Vec2i &v) const
 
Vec2ioperator*= (KyInt32 s)
 
Vec2ioperator/= (KyInt32 d)
 
Vec2ioperator+= (KyInt32 t)
 
Vec2ioperator-= (KyInt32 t)
 
Vec2ioperator+= (const Vec2i &v)
 
Vec2ioperator-= (const Vec2i &v)
 
Vec2i operator* (KyInt32 s) const
 
Vec2i operator/ (KyInt32 d) const
 
Vec2i operator+ (const Vec2i &v) const
 
Vec2i operator- (const Vec2i &v) const
 
Vec2i operator- () const
 
KyInt32 operator* (const Vec2i &v) const
 
KyInt32 operator^ (const Vec2i &v) const
 

Main interface

KyInt32 CrossProd (const Vec2i &v) const
 
KyInt32 Orient2d (const Vec2i &A, const Vec2i &B) const
 
Vec2i PerpCCW () const
 
Vec2i PerpCW () const
 
bool IsOnLeftSide (const Vec2i &A, const Vec2i &B) const
 
bool IsStrictlyOnLeftSide (const Vec2i &A, const Vec2i &B) const
 
KyInt32 GetSquareLength () const
 

Neighbors

Vec2i NeighborEast () const
 
void NeighborEast (Vec2i &neighbor) const
 
Vec2i NeighborWest () const
 
void NeighborWest (Vec2i &neighbor) const
 
Vec2i NeighborNorth () const
 
void NeighborNorth (Vec2i &neighbor) const
 
Vec2i NeighborSouth () const
 
void NeighborSouth (Vec2i &neighbor) const
 
Vec2i Neighbor (CardinalDir dir) const
 
void Neighbor (CardinalDir dir, Vec2i &neighbor) const
 
Vec2i NeighborNorthEast () const
 
Vec2i NeighborNorthWest () const
 
Vec2i NeighborSouthEast () const
 
Vec2i NeighborSouthWest () const
 

Triangle Inclusion Checkers

bool IsInsideTriangle (const Vec2i &A, const Vec2i &B, const Vec2i &C) const
 
bool IsInsideNotColinearTriangle (const Vec2i &A, const Vec2i &B, const Vec2i &C) const
 
bool IsStrictlyInsideTriangle (const Vec2i &A, const Vec2i &B, const Vec2i &C) const
 

Static methods

static Vec2i UnitX ()
 
static Vec2i UnitY ()
 

Public Data Members

KyInt32 x
 
KyInt32 y
 

Constructor & Destructor Documentation

Kaim::Vec2i::Vec2i ( )
inline

Creates a vector with coordinates (0,0).

Kaim::Vec2i::Vec2i ( KyInt32  _x,
KyInt32  _y 
)
inline

Creates a vector with the specified coordinates.

Parameters
_xThe size of the vector on the X axis.
_yThe size of the vector on the Y axis.
Kaim::Vec2i::Vec2i ( KyInt32 coords)
inlineexplicit

Creates a vector with the specified coordinates.

Parameters
coordsAn array of two integers that contains the size of the vector along the X and Y axes respectively.

Member Function Documentation

KyInt32 Kaim::Vec2i::CrossProd ( const Vec2i v) const
inline

Returns the magnitude on the Z axis of the cross product between this vector and v.

KyInt32 Kaim::Vec2i::GetSquareLength ( ) const
inline

Returns the square of the magnitude of the vector.

bool Kaim::Vec2i::IsInsideNotColinearTriangle ( const Vec2i A,
const Vec2i B,
const Vec2i C 
) const
inline

Returns true if this vector is inside the clockwise triangle formed by theA,B and C parameters, or if this vector is on any edge between A,B and C.

This method assumes that the three points that make up the triangle are not colinear: i.e. they do not lie all in a straight line.

bool Kaim::Vec2i::IsInsideTriangle ( const Vec2i A,
const Vec2i B,
const Vec2i C 
) const
inline

Returns true if this vector is inside the clockwise triangle formed by theA,B and C parameters, or if this vector is on any edge between A,B and C.

bool Kaim::Vec2i::IsOnLeftSide ( const Vec2i A,
const Vec2i B 
) const
inline

Returns true if this vector is on the left side when moving from A to B, or if this vector is on the line between A and B.

bool Kaim::Vec2i::IsStrictlyInsideTriangle ( const Vec2i A,
const Vec2i B,
const Vec2i C 
) const
inline

Returns true if this vector is inside the clockwise triangle formed by theA,B and C parameters, but not on any edge between A,B andC.

bool Kaim::Vec2i::IsStrictlyOnLeftSide ( const Vec2i A,
const Vec2i B 
) const
inline

Returns true if this vector is on the left side when moving from A to B, but not if this vector is on the line between A and B.

Vec2i Kaim::Vec2i::Neighbor ( CardinalDir  dir) const
inline

Returns a vector that identifies the next grid cell in the direction of the specified CardinalDir.

void Kaim::Vec2i::Neighbor ( CardinalDir  dir,
Vec2i neighbor 
) const
inline

Set the neighbor vector coordinates to identify the next grid cell in the direction of the specified CardinalDir.

Vec2i Kaim::Vec2i::NeighborEast ( ) const
inline

Returns a vector that identifies the next grid cell to the East: i.e. in the positive direction of the X axis.

void Kaim::Vec2i::NeighborEast ( Vec2i neighbor) const
inline

Set theneighbor vector coordinates to identify the next grid cell to the East: i.e. in the positive direction of the X axis.

Vec2i Kaim::Vec2i::NeighborNorth ( ) const
inline

Returns a vector that identifies the next grid cell to the North: i.e. in the positive direction of the Y axis.

void Kaim::Vec2i::NeighborNorth ( Vec2i neighbor) const
inline

Set theneighbor vector coordinates to identify the next grid cell to the North: i.e. in the positive direction of the Y axis.

Vec2i Kaim::Vec2i::NeighborNorthEast ( ) const
inline

Returns a vector that identifies the next grid cell to the North-East: i.e.

in the positive direction of the X and Y axes.

Vec2i Kaim::Vec2i::NeighborNorthWest ( ) const
inline

Returns a vector that identifies the next grid cell to the North-West: i.e.

in the positive direction of the Y axis and the negative direction of the X axis.

Vec2i Kaim::Vec2i::NeighborSouth ( ) const
inline

Returns a vector that identifies the next grid cell to the South: i.e. in the negative direction of the Y axis.

void Kaim::Vec2i::NeighborSouth ( Vec2i neighbor) const
inline

Set theneighbor vector coordinates to identify the next grid cell to the South: i.e. in the negative direction of the Y axis.

Vec2i Kaim::Vec2i::NeighborSouthEast ( ) const
inline

Returns a vector that identifies the next grid cell to the South-East: i.e.

in the positive direction of the X axis and the negative direction of the Y axis.

Vec2i Kaim::Vec2i::NeighborSouthWest ( ) const
inline

Returns a vector that identifies the next grid cell to the South-West: i.e.

in the negative direction of the X and Y axes.

Vec2i Kaim::Vec2i::NeighborWest ( ) const
inline

Returns a vector that identifies the next grid cell to the West: i.e. in the negative direction of the X axis.

void Kaim::Vec2i::NeighborWest ( Vec2i neighbor) const
inline

Set theneighbor vector coordinates to identify the next grid cell to the West: i.e. in the negative direction of the X axis.

bool Kaim::Vec2i::operator!= ( const Vec2i v) const
inline

Returns true if this object contains at least one different coordinate from v.

Vec2i Kaim::Vec2i::operator* ( KyInt32  s) const
inline

Multiplies both the X and Y coordinates of the vector by the specified value.

KyInt32 Kaim::Vec2i::operator* ( const Vec2i v) const
inline

Returns the dot product of this vector and v.

Vec2i& Kaim::Vec2i::operator*= ( KyInt32  s)
inline

Multiplies both the X and Y coordinates of this vector by the specified value.

Vec2i Kaim::Vec2i::operator+ ( const Vec2i v) const
inline

Adds the X coordinate of v to the X coordinate of this vector, and adds the Y coordinate of v to the Y coordinate of this vector.

Vec2i& Kaim::Vec2i::operator+= ( KyInt32  t)
inline

Addst to both the X and Y coordinates of this vector.

Vec2i& Kaim::Vec2i::operator+= ( const Vec2i v)
inline

Adds the X coordinate of v to the X coordinate of this vector, and adds the Y coordinate of v to the Y coordinate of this vector.

Vec2i Kaim::Vec2i::operator- ( const Vec2i v) const
inline

Subtracts the X coordinate of v from the X coordinate of this vector, and subtracts the Y coordinate of v from the Y coordinate of this vector.

Vec2i Kaim::Vec2i::operator- ( ) const
inline

Negates the X and Y coordinates of this vector, effectively flipping it around the origin.

Vec2i& Kaim::Vec2i::operator-= ( KyInt32  t)
inline

Subtractst from both the X and Y coordinates of this vector.

Vec2i& Kaim::Vec2i::operator-= ( const Vec2i v)
inline

Subtracts the X coordinate of v from the X coordinate of this vector, and subtracts the Y coordinate of v from the Y coordinate of this vector.

Vec2i Kaim::Vec2i::operator/ ( KyInt32  d) const
inline

Divides both the X and Y coordinates of the vector by the specified value.

Vec2i& Kaim::Vec2i::operator/= ( KyInt32  d)
inline

Divides both the X and Y coordinates of this vector by the specified value.

bool Kaim::Vec2i::operator< ( const Vec2i v) const
inline

order by x first: (1,9)<(2,8).

bool Kaim::Vec2i::operator<= ( const Vec2i v) const
inline

order by x first: (1,9)<=(2,8).

bool Kaim::Vec2i::operator== ( const Vec2i v) const
inline

Returns true if this object contains the same coordinates as v.

bool Kaim::Vec2i::operator> ( const Vec2i v) const
inline

order by x first: (2,8)>(1,9).

bool Kaim::Vec2i::operator>= ( const Vec2i v) const
inline

order by x first: (2,8)>=(1,9).

KyInt32 Kaim::Vec2i::operator[] ( KyInt32  idx) const
inline

Retrieves the size of the vector around one of its axes.

Use [0] for the X axis, or [1] for the Y axis.

KyInt32& Kaim::Vec2i::operator[] ( KyInt32  idx)
inline

Retrieves the size of the vector around one of its axes.

Use [0] for the X axis, or [1] for the Y axis. Non-const and returned as a reference to allow modification of the member.

KyInt32 Kaim::Vec2i::operator^ ( const Vec2i v) const
inline

Returns the magnitude on the Z axis of the cross product between this vector and v.

KyInt32 Kaim::Vec2i::Orient2d ( const Vec2i A,
const Vec2i B 
) const
inline

Indicates whether or not the polyline formed by (A to B to this vector ) outlines a triangle in counter-clockwise order when seen from above.

Returns
Twice the area of the triangle outlined by (A to B to this vector ).
  • If this value is positive, (A to B to this vector ) outlines a triangle in counter-clockwise order.
  • If this value is negative, (A to B to this vector ) outlines a triangle in clockwise order.
  • If this value is 0, then A,B and this vector are all colinear.
Vec2i Kaim::Vec2i::PerpCCW ( ) const
inline

Rotates this vector 90 degrees counter-clockwise (negating the Y coordinate).

Vec2i Kaim::Vec2i::PerpCW ( ) const
inline

Rotates this vector 90 degrees clockwise (negating the X coordinate).

void Kaim::Vec2i::Set ( KyInt32  _x,
KyInt32  _y 
)
inline

Sets the coordinates of the vector to match the specified values.

Parameters
_xThe size of the vector on the X axis.
_yThe size of the vector on the Y axis.
void Kaim::Vec2i::Set ( KyInt32 coords)
inline

Sets the coordinates of the vector to match the specified values.

Parameters
coordsAn array of two floating-point numbers that contains the size of the vector along the X and Y axes respectively.
static Vec2i Kaim::Vec2i::UnitX ( )
inlinestatic

Returns the normalized orientation of the X axis.

static Vec2i Kaim::Vec2i::UnitY ( )
inlinestatic

Returns the normalized orientation of the Y axis.

Member Data Documentation

KyInt32 Kaim::Vec2i::x

The size of the vector along the X axis.

+ Examples:
KyInt32 Kaim::Vec2i::y

The size of the vector along the Y axis.

+ Examples:

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