FifeGUI 0.2.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 28 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.

Definition at line 45 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.

Definition at line 50 of file point.hpp.

References Point().

◆ Point() [3/3]

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

Move Constructor.

Definition at line 55 of file point.hpp.

References Point().

Member Function Documentation

◆ length()

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

Return length.

Definition at line 150 of file point.hpp.

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

Referenced by normalize().

◆ normalize()

void fcn::Point::normalize ( )
inline

Normalizes the point.

Definition at line 159 of file point.hpp.

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

◆ operator!=()

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

Equality comparision.

Definition at line 142 of file point.hpp.

References Point().

◆ operator*()

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

Scalar multiplication with an integer value.

Definition at line 118 of file point.hpp.

References Point().

◆ operator+()

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

Vector addition.

Definition at line 82 of file point.hpp.

References Point().

◆ operator+=()

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

Vector inplace addition.

Definition at line 98 of file point.hpp.

References Point().

◆ operator-()

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

Vector subtraction.

Definition at line 90 of file point.hpp.

References Point().

◆ operator-=()

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

Vector inplace subtraction.

Definition at line 108 of file point.hpp.

References Point().

◆ operator/()

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

Scalar division with an integer value.

Definition at line 126 of file point.hpp.

References Point().

◆ operator=() [1/2]

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

Move assignment.

Definition at line 71 of file point.hpp.

References Point().

◆ operator=() [2/2]

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

Copy assignment.

Definition at line 60 of file point.hpp.

References Point().

◆ operator==()

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

Equality comparision.

Definition at line 134 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 246 of file point.hpp.

◆ rotate() [1/2]

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

Rotates the point around the origin by angle degrees.

Definition at line 189 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.

Definition at line 209 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.

Definition at line 176 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.

Definition at line 234 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)".

Definition at line 257 of file point.hpp.

References Point().

Member Data Documentation

◆ val

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

Definition at line 33 of file point.hpp.

◆ x

int fcn::Point::x

Definition at line 36 of file point.hpp.

◆ y

int fcn::Point::y

Definition at line 36 of file point.hpp.


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