FifeGUI 0.3.0
A C++ GUI library designed for games.
fcn::Point Class Reference

#include <point.hpp>

Public Member Functions

int length () const
void normalize ()
bool operator!= (Point const &p) const
Point operator* (int const &i) const
Point operator+ (Point const &p) const
Pointoperator+= (Point const &p)
Point operator- (Point const &p) const
Pointoperator-= (Point const &p)
Point operator/ (int const &i) const
Pointoperator= (Point &&rhs) noexcept
Pointoperator= (Point const &rhs)
bool operator== (Point const &p) const
int & operator[] (int ind)
 Point (int _x=0, int _y=0)
 Point (Point &&rhs) noexcept
 Point (Point const &rhs)
void rotate (double angle)
void rotate (Point const &origin, int angle)
Point rotated (int angle) const
void set (int _x, int _y)

Public Attributes

union { 
   struct { 
      int   x 
      int   y 
   } 
   std::array< int, 2 >   val 
}; 

Friends

std::ostream & operator<< (std::ostream &os, Point const &p)

Detailed Description

Represents a 2D coordinate (X, Y).

This is a small helper class to aid in 2D vector arithmetics.

See also
Rect

Definition at line 33 of file point.hpp.

Constructor & Destructor Documentation

◆ Point() [1/3]

fcn::Point::Point ( int _x = 0,
int _y = 0 )
inlineexplicit

Constructor.

Creates a with 0 as default values.

Parameters
_xThe x coordinate of the point.
_yThe y coordinate of the point.

Definition at line 53 of file point.hpp.

Referenced by operator!=(), operator*(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator<<, operator=(), operator=(), operator==(), Point(), Point(), rotate(), and rotated().

◆ Point() [2/3]

fcn::Point::Point ( Point const & rhs)
inline

Copy Constructor.

Parameters
rhsThe point to copy from.

Definition at line 64 of file point.hpp.

References Point().

◆ Point() [3/3]

fcn::Point::Point ( Point && rhs)
inlinenoexcept

Move Constructor.

Parameters
rhsThe point to move from.

Definition at line 73 of file point.hpp.

References Point().

Member Function Documentation

◆ length()

int fcn::Point::length ( ) const
inline

Return length.

Definition at line 198 of file point.hpp.

References fcn::Math< float >::Sqrt().

Referenced by normalize().

◆ normalize()

void fcn::Point::normalize ( )
inline

Normalizes the point.

Definition at line 207 of file point.hpp.

References length(), and fcn::Math< float >::zeroTolerance().

◆ operator!=()

bool fcn::Point::operator!= ( Point const & p) const
inline

Equality comparision.

Parameters
pThe point to compare with.
Returns
True if the points are not equal, false otherwise.

Definition at line 190 of file point.hpp.

References Point().

◆ operator*()

Point fcn::Point::operator* ( int const & i) const
inline

Scalar multiplication with an integer value.

Parameters
iThe integer to multiply with.
Returns
The result of the multiplication.

Definition at line 157 of file point.hpp.

References Point().

◆ operator+()

Point fcn::Point::operator+ ( Point const & p) const
inline

Vector addition.

Parameters
pThe point to add.
Returns
The sum of the two points.

Definition at line 109 of file point.hpp.

References Point().

◆ operator+=()

Point & fcn::Point::operator+= ( Point const & p)
inline

Vector inplace addition.

Parameters
pThe point to add.
Returns
A reference to this point after addition.

Definition at line 131 of file point.hpp.

References Point().

◆ operator-()

Point fcn::Point::operator- ( Point const & p) const
inline

Vector subtraction.

Parameters
pThe point to subtract.
Returns
The difference of the two points.

Definition at line 120 of file point.hpp.

References Point().

◆ operator-=()

Point & fcn::Point::operator-= ( Point const & p)
inline

Vector inplace subtraction.

Parameters
pThe point to subtract.
Returns
A reference to this point after subtraction.

Definition at line 144 of file point.hpp.

References Point().

◆ operator/()

Point fcn::Point::operator/ ( int const & i) const
inline

Scalar division with an integer value.

Parameters
iThe integer to divide with.
Returns
The result of the division.

Definition at line 168 of file point.hpp.

References Point().

◆ operator=() [1/2]

Point & fcn::Point::operator= ( Point && rhs)
inlinenoexcept

Move assignment.

Parameters
rhsThe point to move from.

Definition at line 95 of file point.hpp.

References Point().

◆ operator=() [2/2]

Point & fcn::Point::operator= ( Point const & rhs)
inline

Copy assignment.

Parameters
rhsThe point to copy from.

Definition at line 82 of file point.hpp.

References Point().

◆ operator==()

bool fcn::Point::operator== ( Point const & p) const
inline

Equality comparision.

Parameters
pThe point to compare with.
Returns
True if the points are equal, false otherwise.

Definition at line 179 of file point.hpp.

References Point().

◆ operator[]()

int & fcn::Point::operator[] ( int ind)
inline

Index accessor for the point components.

Parameters
indIndex 0 for X, 1 for Y. Asserts if out of range.
Returns
Reference to the requested component.

Definition at line 307 of file point.hpp.

◆ rotate() [1/2]

void fcn::Point::rotate ( double angle)
inline

Rotates the point around the origin by angle degrees.

Parameters
angleThe angle to rotate by, in degrees.

Definition at line 244 of file point.hpp.

References fcn::Math< double >::Cos(), fcn::Math< double >::pi(), and fcn::Math< double >::Sin().

◆ rotate() [2/2]

void fcn::Point::rotate ( Point const & origin,
int angle )
inline

Rotates the point around a given origin by angle degrees.

Coordinates stored as int. Uses float math internally. Results are rounded to nearest integer.

Parameters
originThe point to rotate around.
angleThe angle to rotate by, in degrees.

Definition at line 267 of file point.hpp.

References fcn::Math< double >::Cos(), fcn::Math< double >::pi(), Point(), and fcn::Math< double >::Sin().

◆ rotated()

Point fcn::Point::rotated ( int angle) const
inline

Rotates the point around the origin by angle degrees.

Parameters
angleThe angle to rotate by, in degrees.
Returns
The rotated point.

Definition at line 228 of file point.hpp.

References fcn::Math< double >::Cos(), fcn::Math< double >::pi(), Point(), and fcn::Math< double >::Sin().

◆ set()

void fcn::Point::set ( int _x,
int _y )
inline

Sets the x and y coordinate of the 2D point.

Parameters
_xThe x coordinate of the point.
_yThe y coordinate of the point.

Definition at line 295 of file point.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
Point const & p )
friend

Stream output operator for debug/logging.

Formats the point as "(x:y)".

Parameters
osThe output stream to write to.
pThe point to output.
Returns
The output stream after writing.

Definition at line 322 of file point.hpp.

References Point().

Member Data Documentation

◆ val

std::array<int, 2> fcn::Point::val

Definition at line 38 of file point.hpp.

◆ x

int fcn::Point::x

Definition at line 41 of file point.hpp.

◆ y

int fcn::Point::y

Definition at line 41 of file point.hpp.


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