Gorgon Game Engine
basic_Point< T_ > Class Template Reference

This class represents a 2D point. More...

Inheritance diagram for basic_Point< T_ >:
[legend]

Public Types

typedef T_ BaseType
 Base type of the point elements. More...
 

Public Member Functions

 basic_Point ()
 Default constructor, does not zero initialize point. More...
 
template<class O_ >
 basic_Point (const basic_Point< O_ > &point)
 Conversion from a different point type. More...
 
 basic_Point (const std::string &str)
 Conversion from string. More...
 
 basic_Point (const T_ &X, const T_ &Y)
 Filling constructor. More...
 
Float Angle () const
 Calculates the angle of the line formed from the origin to this point. More...
 
Float Angle (const basic_Point &origin) const
 Calculates the angle of the line formed from the given point to this point. More...
 
bool Compare (const basic_Point &point) const
 Compares two points. More...
 
T_ CrossProduct (const basic_Point< T_ > &value) const
 Calculates cross product of two points. More...
 
Float Distance () const
 Calculates Euclidean distance from this point to origin. More...
 
Float Distance (const basic_Point &target) const
 Calculates Euclidean distance from this point to the given target. More...
 
T_ DotProduct (const basic_Point< T_ > &value) const
 Calculates dot product of two points. More...
 
Float EuclideanSquare () const
 Calculates EuclideanSquare distance from this point to the given target. More...
 
Float EuclideanSquare (const basic_Point &target) const
 Calculates EuclideanSquare distance from this point to the given target. More...
 
Float ManhattanDistance () const
 Calculates Manhattan distance from this point to origin. More...
 
Float ManhattanDistance (const basic_Point &target) const
 Calculates Manhattan distance from this point to the given target. More...
 
void Move (const T_ &x, const T_ &y)
 Moves this point to the given coordinates. More...
 
basic_Point Normalize () const
 Normalizes the point as a unit vector. More...
 
 operator std::string () const
 Converts this object to string. More...
 
bool operator!= (const basic_Point &point) const
 Compares two points. More...
 
T_ operator* (const basic_Point< T_ > &value) const
 Multiplies two points. This is essentially a dot product. More...
 
template<class O_ >
basic_Point operator* (O_ value) const
 Multiply this point with a scalar value. More...
 
template<class O_ >
basic_Pointoperator*= (O_ value)
 Scales this point. More...
 
basic_Point operator+ (const basic_Point &point) const
 Adds another point to this one and returns the result. More...
 
basic_Pointoperator+= (const basic_Point &point)
 Adds another point from this point. More...
 
basic_Point operator- () const
 Negates this point. More...
 
basic_Point operator- (const basic_Point &point) const
 Subtracts another point from this one. More...
 
basic_Pointoperator-= (const basic_Point &point)
 Subtracts another point from this point. More...
 
template<class O_ >
basic_Point operator/ (O_ value) const
 Divides this point to a scalar value. More...
 
template<class O_ >
basic_Pointoperator/= (O_ value)
 Scales this point. More...
 
template<class O_ >
basic_Pointoperator= (const basic_Point< O_ > &point)
 Assignment from a different point type. More...
 
bool operator== (const basic_Point &point) const
 Compares two points. More...
 
basic_Point Perpendicular () const
 Calculates perpendicular vector to this point. More...
 
Float Slope () const
 Calculates the slope of the line formed from the origin to this point. More...
 
Float Slope (const basic_Point &point) const
 Calculates the slope of the line formed from the given point to this point. More...
 

Static Public Member Functions

template<class O_ >
static basic_Point FromVector (Float magnitute, Float angle, const basic_Point< O_ > &origin={0, 0})
 Creates a new point from the given vector data. More...
 
static basic_Point Parse (const std::string &str, bool require_parenthesis=false)
 Properly parses given string into a point. More...
 

Public Attributes

union {
   struct {
      T_   X
 X coordinate. More...
 
      T_   Y
 Y coordinate. More...
 
   } 
 
   T_   Vector [2]
 Allows this point to be accessed as a vector. More...
 
}; 
 

Detailed Description

template<class T_>
class Gorgon::Geometry::basic_Point< T_ >

This class represents a 2D point.

Points are serialized to string as (X, Y) form. However, unserialization, by default, accepts X, Y as well.

Member Typedef Documentation

◆ BaseType

typedef T_ BaseType

Base type of the point elements.

Constructor & Destructor Documentation

◆ basic_Point() [1/4]

Default constructor, does not zero initialize point.

◆ basic_Point() [2/4]

basic_Point ( const T_ &  X,
const T_ &  Y 
)

Filling constructor.

◆ basic_Point() [3/4]

basic_Point ( const basic_Point< O_ > &  point)

Conversion from a different point type.

◆ basic_Point() [4/4]

basic_Point ( const std::string &  str)
explicit

Conversion from string.

Member Function Documentation

◆ Angle() [1/2]

Float Angle ( ) const

Calculates the angle of the line formed from the origin to this point.

Returns
angle in radians

◆ Angle() [2/2]

Float Angle ( const basic_Point< T_ > &  origin) const

Calculates the angle of the line formed from the given point to this point.

Parameters
originis the starting point of the line
Returns
angle in radians

◆ Compare()

bool Compare ( const basic_Point< T_ > &  point) const

Compares two points.

◆ CrossProduct()

T_ CrossProduct ( const basic_Point< T_ > &  value) const

Calculates cross product of two points.

◆ Distance() [1/2]

Float Distance ( ) const

Calculates Euclidean distance from this point to origin.

◆ Distance() [2/2]

Float Distance ( const basic_Point< T_ > &  target) const

Calculates Euclidean distance from this point to the given target.

◆ DotProduct()

T_ DotProduct ( const basic_Point< T_ > &  value) const

Calculates dot product of two points.

◆ EuclideanSquare() [1/2]

Float EuclideanSquare ( ) const

Calculates EuclideanSquare distance from this point to the given target.

◆ EuclideanSquare() [2/2]

Float EuclideanSquare ( const basic_Point< T_ > &  target) const

Calculates EuclideanSquare distance from this point to the given target.

◆ FromVector()

static basic_Point FromVector ( Float  magnitute,
Float  angle,
const basic_Point< O_ > &  origin = {0,0} 
)
static

Creates a new point from the given vector data.

Parameters
magnituteis the magnitute of the vector
angleis the direction of the vector in radians
originis the source origin to calculate new point

◆ ManhattanDistance() [1/2]

Float ManhattanDistance ( ) const

Calculates Manhattan distance from this point to origin.

◆ ManhattanDistance() [2/2]

Float ManhattanDistance ( const basic_Point< T_ > &  target) const

Calculates Manhattan distance from this point to the given target.

◆ Move()

void Move ( const T_ &  x,
const T_ &  y 
)

Moves this point to the given coordinates.

◆ Normalize()

basic_Point Normalize ( ) const

Normalizes the point as a unit vector.

◆ operator std::string()

operator std::string ( ) const
explicit

Converts this object to string.

◆ operator!=()

bool operator!= ( const basic_Point< T_ > &  point) const

Compares two points.

◆ operator*() [1/2]

T_ operator* ( const basic_Point< T_ > &  value) const

Multiplies two points. This is essentially a dot product.

◆ operator*() [2/2]

basic_Point operator* ( O_  value) const

Multiply this point with a scalar value.

This is effectively scales the point

◆ operator*=()

basic_Point& operator*= ( O_  value)

Scales this point.

◆ operator+()

basic_Point operator+ ( const basic_Point< T_ > &  point) const

Adds another point to this one and returns the result.

◆ operator+=()

basic_Point& operator+= ( const basic_Point< T_ > &  point)

Adds another point from this point.

Result is assigned to this point

◆ operator-() [1/2]

basic_Point operator- ( ) const

Negates this point.

◆ operator-() [2/2]

basic_Point operator- ( const basic_Point< T_ > &  point) const

Subtracts another point from this one.

◆ operator-=()

basic_Point& operator-= ( const basic_Point< T_ > &  point)

Subtracts another point from this point.

Result is assigned to this point

◆ operator/()

basic_Point operator/ ( O_  value) const

Divides this point to a scalar value.

This is effectively scales the point

◆ operator/=()

basic_Point& operator/= ( O_  value)

Scales this point.

◆ operator=()

basic_Point& operator= ( const basic_Point< O_ > &  point)

Assignment from a different point type.

◆ operator==()

bool operator== ( const basic_Point< T_ > &  point) const

Compares two points.

◆ Parse()

static basic_Point Parse ( const std::string &  str,
bool  require_parenthesis = false 
)
static

Properly parses given string into a point.

Throws errors if the point is not well formed. Works only on types that can be parsed using strtod. Following error codes are reported by this parse function:

  • IllegalTokenError 111001: Illegal token while reading X coordinate
  • IllegalTokenError 111002: Illegal token while looking for coordinate separator
  • IllegalTokenError 111003: Illegal token while reading Y coordinate
  • IllegalTokenError 111004: Illegal token(s) at the end
  • IllegalTokenError 111005: Unmatched parenthesis
  • ParseError 110006: Missing parenthesis, only if require_parenthesis is set to true
  • ParseError 110007: Missing operand

◆ Perpendicular()

basic_Point Perpendicular ( ) const

Calculates perpendicular vector to this point.

◆ Slope() [1/2]

Float Slope ( ) const

Calculates the slope of the line formed from the origin to this point.

◆ Slope() [2/2]

Float Slope ( const basic_Point< T_ > &  point) const

Calculates the slope of the line formed from the given point to this point.

Parameters
pointis the starting point of the line

Member Data Documentation

◆ @4

union { ... }

◆ Vector

T_ Vector[2]

Allows this point to be accessed as a vector.

◆ X

T_ X

X coordinate.

◆ Y

T_ Y

Y coordinate.


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