The Game Engine  1
Point2D Class Reference

2D position or vector placed here because of general access More...

#include <fns.h>

Public Member Functions

 Point2D ()
 
 Point2D (double X, double Y)
 
 Point2D (const Point2D &copy)
 
 Point2D (const Size2D &copy)
 Copy object. More...
 
double length ()
 The length of the Point (from origin) More...
 
double lengthSquared () const
 The length of the Point (from origin) Ensure that all checks for value 0 use abs(lengthSquared()) < numeric_limits<double>::epsilon() (from limits) More...
 
void zero ()
 Sets the values of x,y to 0. More...
 
Point2D unitVec ()
 The unit vector of the Point (from origin) More...
 
Point2D normalize ()
 Normalizes the vector. More...
 
Point2D add (Point2D pt)
 Adds the value of the point to this. More...
 
Point2D sub (Point2D pt)
 Subtracts the value of the point from this. More...
 
Point2D mult (double d)
 Multiplies the values of this by i. More...
 
Point2D div (double d)
 Divides the values of this by i. More...
 
Point2D operator+ (const Point2D &pt) const
 
Point2D operator- (const Point2D &pt) const
 
Point2D operator* (const double scale) const
 
Point2D operator/ (const double scale) const
 
Point2D operator+= (const Point2D &pt)
 
Point2D operator-= (const Point2D &pt)
 
Point2D operator*= (const double scale)
 
Point2D operator/= (const double scale)
 
bool operator< (const Point2D &vec)
 Compares the value of less as a comparison of the length squared (effectively magnitude squared) More...
 
double dot (Point2D p1, Point2D p2)
 Returns the Dot product of two Point2D. More...
 

Public Attributes

double x
 x position More...
 
double y
 y Position More...
 

Friends

ostream & operator<< (ostream &out, Point2D p)
 

Detailed Description

2D position or vector placed here because of general access

This class is tasked with:

  • storing 2D positions
  • math and scaling for 2D points/vectors
  • normalization
  • comparison of length (use squared if actaul magnitude is not needed)
    Todo:
    implement length squared and length between two points (because it'll be needed)

Definition at line 78 of file fns.h.

Constructor & Destructor Documentation

Point2D::Point2D ( )
inline

Definition at line 81 of file fns.h.

+ Here is the caller graph for this function:

Point2D::Point2D ( double  X,
double  Y 
)
inline

Definition at line 82 of file fns.h.

Point2D::Point2D ( const Point2D copy)
inline
Parameters
copyCopy object

Definition at line 83 of file fns.h.

Point2D::Point2D ( const Size2D copy)

Copy object.

Definition at line 44 of file fns.cpp.

Member Function Documentation

Point2D Point2D::add ( Point2D  pt)

Adds the value of the point to this.

Returns
This after modificaiton

Definition at line 71 of file fns.cpp.

+ Here is the caller graph for this function:

Point2D Point2D::div ( double  d)

Divides the values of this by i.

Returns
This after modificaiton

Definition at line 86 of file fns.cpp.

+ Here is the caller graph for this function:

double Point2D::dot ( Point2D  p1,
Point2D  p2 
)

Returns the Dot product of two Point2D.

Definition at line 92 of file fns.cpp.

double Point2D::length ( )

The length of the Point (from origin)

Returns
length of the vector/point

Definition at line 49 of file fns.cpp.

+ Here is the caller graph for this function:

double Point2D::lengthSquared ( ) const

The length of the Point (from origin) Ensure that all checks for value 0 use abs(lengthSquared()) < numeric_limits<double>::epsilon() (from limits)

Returns
length of the vector/point

Definition at line 53 of file fns.cpp.

+ Here is the caller graph for this function:

Point2D Point2D::mult ( double  d)

Multiplies the values of this by i.

Returns
This after modificaiton

Definition at line 81 of file fns.cpp.

Point2D Point2D::normalize ( )

Normalizes the vector.

Definition at line 67 of file fns.cpp.

+ Here is the call graph for this function:

Point2D Point2D::operator* ( const double  scale) const
inline

Definition at line 103 of file fns.h.

Point2D Point2D::operator*= ( const double  scale)
inline

Definition at line 107 of file fns.h.

Point2D Point2D::operator+ ( const Point2D pt) const
inline

Definition at line 101 of file fns.h.

Point2D Point2D::operator+= ( const Point2D pt)
inline

Definition at line 105 of file fns.h.

Point2D Point2D::operator- ( const Point2D pt) const
inline

Definition at line 102 of file fns.h.

Point2D Point2D::operator-= ( const Point2D pt)
inline

Definition at line 106 of file fns.h.

Point2D Point2D::operator/ ( const double  scale) const
inline

Definition at line 104 of file fns.h.

Point2D Point2D::operator/= ( const double  scale)
inline

Definition at line 108 of file fns.h.

bool Point2D::operator< ( const Point2D vec)
inline

Compares the value of less as a comparison of the length squared (effectively magnitude squared)

Definition at line 109 of file fns.h.

+ Here is the call graph for this function:

Point2D Point2D::sub ( Point2D  pt)

Subtracts the value of the point from this.

Returns
This after modification

Definition at line 76 of file fns.cpp.

Point2D Point2D::unitVec ( )

The unit vector of the Point (from origin)

Returns
length of the vector/point

Definition at line 62 of file fns.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Point2D::zero ( )

Sets the values of x,y to 0.

Definition at line 57 of file fns.cpp.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

ostream& operator<< ( ostream &  out,
Point2D  p 
)
friend

Definition at line 112 of file fns.h.

Member Data Documentation

double Point2D::x

x position

Definition at line 90 of file fns.h.

double Point2D::y

y Position

Definition at line 91 of file fns.h.


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