lab_inheritance
Insidious Inheritance
Vector2 Class Reference

Represents a 2 dimensional vector. More...

#include <vector2.h>

Public Member Functions

 Vector2 ()
 Constructs a new Vector2 at (0, 0) More...
 
 Vector2 (double x, double y)
 Constructs a new Vector2 at (x, y) More...
 
Vector2 operator- (const Vector2 &other) const
 Subtracts two Vector2s and returns the value. More...
 
Vector2 operator+ (const Vector2 &other) const
 Adds two Vector2s together and returns the value. More...
 
Vector2 operator * (int constant)
 Multiples the current Vector2 by a scalar and returns a new Vector2 with its value. More...
 
Vector2 operator/ (int constant)
 Divides the current Vector2 by a scalar and returns a new Vector2 with its value. More...
 
bool operator== (const Vector2 &other) const
 Checks to see if the current Vector2 equals the other Vector2. More...
 
double x () const
 Gets the x coordinate of the Vector2. More...
 
void setX (double x)
 Sets the x coordinate of the Vector2. More...
 
double y () const
 Gets the y coordinate of the Vector2. More...
 
void setY (double y)
 Sets the y coordinate of the Vector2. More...
 
double distanceTo (const Vector2 &other) const
 Computes and returns the distance from the current Vector2 to the other Vector2. More...
 
bool isNorthOf (const Vector2 &other) const
 Checks if the current Vector2 is north of the other Vector2. More...
 
bool isNorthWestOf (const Vector2 &other) const
 Checks if the current Vector2 is north west of the other Vector2. More...
 
bool isNorthEastOf (const Vector2 &other) const
 Checks if the current Vector2 is north east of the other Vector2. More...
 
bool isSouthOf (const Vector2 &other) const
 Checks if the current Vector2 is south of the other Vector2. More...
 
bool isSouthWestOf (const Vector2 &other) const
 Checks if the current Vector2 is south west of the other Vector2. More...
 
bool isSouthEastOf (const Vector2 &other) const
 Checks if the current Vector2 is south east of the other Vector2. More...
 
bool isWestOf (const Vector2 &other) const
 Checks if the current Vector2 is west of the other Vector2. More...
 
bool isEastOf (const Vector2 &other) const
 Checks if the current Vector2 is east of the other Vector2. More...
 
double dotProduct (const Vector2 &other) const
 Computes and returns the dot product of the current Vector2 and other Vector2. More...
 
double crossProduct (const Vector2 &other) const
 Computes and returns the cross product of the current Vector2 and the other Vector2. More...
 
Vector2 projectionOn (const Vector2 &b) const
 Computes and returns the projection of the current Vector2 onto b. More...
 
double length () const
 Computes and returns the length of the Vector2 from the origin. More...
 
double length2 () const
 Computes and returns the length^2 of the Vector2 from the origin. More...
 
double magnitude () const
 Computes and returns the magnitude of the Vector2. More...
 
Vector2 normalize () const
 Computes and returns the normalized form of the current Vector2. More...
 
Vector2 leftHandNormal () const
 Computes and returns the left hand normal of the current Vector2. More...
 
Vector2 rightHandNormal () const
 Computes and returns the right hand normal of the current Vector2. More...
 

Private Attributes

double x_
 The X coordinate of this vector. More...
 
double y_
 The Y coordinate of this vector. More...
 

Detailed Description

Represents a 2 dimensional vector.

Constructor & Destructor Documentation

◆ Vector2() [1/2]

Vector2::Vector2 ( )

Constructs a new Vector2 at (0, 0)

◆ Vector2() [2/2]

Vector2::Vector2 ( double  x,
double  y 
)

Constructs a new Vector2 at (x, y)

Parameters
x
y

Member Function Documentation

◆ crossProduct()

double Vector2::crossProduct ( const Vector2 other) const

Computes and returns the cross product of the current Vector2 and the other Vector2.

Parameters
other
Returns
the cross product of the current Vector2 and the other Vector2

◆ distanceTo()

double Vector2::distanceTo ( const Vector2 other) const

Computes and returns the distance from the current Vector2 to the other Vector2.

Parameters
other
Returns
sqrt((this->x - other.x)^2 + (this-y - other.y)^2)

◆ dotProduct()

double Vector2::dotProduct ( const Vector2 other) const

Computes and returns the dot product of the current Vector2 and other Vector2.

Parameters
other
Returns
the dot product of the current Vector2 and the other Vector2

◆ isEastOf()

bool Vector2::isEastOf ( const Vector2 other) const

Checks if the current Vector2 is east of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is east of the other Vector2

◆ isNorthEastOf()

bool Vector2::isNorthEastOf ( const Vector2 other) const

Checks if the current Vector2 is north east of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is north east of the other Vector2

◆ isNorthOf()

bool Vector2::isNorthOf ( const Vector2 other) const

Checks if the current Vector2 is north of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is north of the other Vector2

◆ isNorthWestOf()

bool Vector2::isNorthWestOf ( const Vector2 other) const

Checks if the current Vector2 is north west of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is north west of the other Vector2

◆ isSouthEastOf()

bool Vector2::isSouthEastOf ( const Vector2 other) const

Checks if the current Vector2 is south east of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is south east of the other Vector2

◆ isSouthOf()

bool Vector2::isSouthOf ( const Vector2 other) const

Checks if the current Vector2 is south of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is south of the other Vector2

◆ isSouthWestOf()

bool Vector2::isSouthWestOf ( const Vector2 other) const

Checks if the current Vector2 is south west of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is south west of the other Vector2

◆ isWestOf()

bool Vector2::isWestOf ( const Vector2 other) const

Checks if the current Vector2 is west of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is west of the other Vector2

◆ leftHandNormal()

Vector2 Vector2::leftHandNormal ( ) const

Computes and returns the left hand normal of the current Vector2.

Returns
the left hand normal of the current Vector2

◆ length()

double Vector2::length ( ) const

Computes and returns the length of the Vector2 from the origin.

Returns
the length of the Vector2 from the origin

◆ length2()

double Vector2::length2 ( ) const

Computes and returns the length^2 of the Vector2 from the origin.

Returns
the length^2 of the Vector2 from the origin

◆ magnitude()

double Vector2::magnitude ( ) const

Computes and returns the magnitude of the Vector2.

Note this is the same as length

Returns
the magnitude of the Vector2

◆ normalize()

Vector2 Vector2::normalize ( ) const

Computes and returns the normalized form of the current Vector2.

Returns
the normalized form of the current Vector2

◆ operator *()

Vector2 Vector2::operator * ( int  constant)

Multiples the current Vector2 by a scalar and returns a new Vector2 with its value.

Parameters
constantto multiply by
Returns
a new Vector2 that equals (x * constant, y * constant)

◆ operator+()

Vector2 Vector2::operator+ ( const Vector2 other) const

Adds two Vector2s together and returns the value.

Parameters
otherVector2 to add
Returns
a new Vector2 that equals *this + other

◆ operator-()

Vector2 Vector2::operator- ( const Vector2 other) const

Subtracts two Vector2s and returns the value.

Parameters
otherVector2 to subtract by
Returns
a new Vector2 that equals *this - other

◆ operator/()

Vector2 Vector2::operator/ ( int  constant)

Divides the current Vector2 by a scalar and returns a new Vector2 with its value.

Parameters
constantto divide by
Returns
a new Vector2 that equals (x / constant, y / constant)

◆ operator==()

bool Vector2::operator== ( const Vector2 other) const

Checks to see if the current Vector2 equals the other Vector2.

Parameters
otherVector2 to check
Returns
true if the current Vector2 equals the other Vector2

◆ projectionOn()

Vector2 Vector2::projectionOn ( const Vector2 b) const

Computes and returns the projection of the current Vector2 onto b.

Parameters
bVector2 to project onto
Returns
the Vector2 representing the projection of the current Vector2 onto b

◆ rightHandNormal()

Vector2 Vector2::rightHandNormal ( ) const

Computes and returns the right hand normal of the current Vector2.

Returns
the right hand normal of the current Vector2

◆ setX()

void Vector2::setX ( double  x)

Sets the x coordinate of the Vector2.

Parameters
xthe new x coordinate of the Vector2

◆ setY()

void Vector2::setY ( double  y)

Sets the y coordinate of the Vector2.

Parameters
ythe new y coordinate of the Vector2

◆ x()

double Vector2::x ( ) const

Gets the x coordinate of the Vector2.

Returns
the x coordinate of the Vector2

◆ y()

double Vector2::y ( ) const

Gets the y coordinate of the Vector2.

Returns
the y coordinate of the Vector2

Member Data Documentation

◆ x_

double Vector2::x_
private

The X coordinate of this vector.

◆ y_

double Vector2::y_
private

The Y coordinate of this vector.


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