My Project
Public Member Functions | Static Public Member Functions | List of all members
Vec2d Class Reference

Bridge vector class to sf::Vector2i/f that provides some common math methods. More...

#include <Vec2d.hpp>

Public Member Functions

 Vec2d (double x, double y)
 
 Vec2d (sf::Vector2f const &sfvect)
 
 Vec2d (sf::Vector2i const &sfvect)
 
 Vec2d (Vec2d const &other)=default
 
Vec2doperator= (Vec2d const &other)=default
 
 operator sf::Vector2f () const
 
 operator sf::Vector2i () const
 
j::Value save () const
 Save internal representation as JSON value.
 
double lengthSquared () const
 Computes the length of the vector (squared). More...
 
double length () const
 Computes the length of the vector. More...
 
Vec2d normalised () const
 Computes the normalized vector. More...
 
Vec2d normal () const
 Computes the normal (orthogonal) vector for this vector. More...
 
double angle () const
 Computes the angle of the vector in polar coordinates. More...
 
double dot (Vec2d const &other) const
 Computes the dot product between this and another vector. More...
 
int sign (Vec2d const &other) const
 Compares the angle between another vector and this one. More...
 
Vec2d operator- () const
 Negation.
 
Vec2d operator- (Vec2d const &b) const
 
Vec2d operator+ (Vec2d const &b) const
 
Vec2d operator* (double c) const
 
Vec2d operator/ (double c) const
 
Vec2doperator-= (Vec2d const &b)
 
Vec2doperator+= (Vec2d const &b)
 
Vec2doperator*= (double c)
 
Vec2doperator/= (double c)
 
bool operator== (Vec2d const &b) const
 
bool operator!= (Vec2d const &b) const
 
double operator[] (int axis) const
 Accesses the coordinates by dimension, read-only. More...
 
double x () const
 
double y () const
 

Static Public Member Functions

static Vec2d fromAngle (double rad)
 Create a unitary Vec2d from an angle. More...
 
static Vec2d fromRandomAngle (double min=0, double max=TAU)
 Create a random vector. More...
 
static Vec2d fromJSON (j::Value json)
 Construct a vector from its internal representation in JSON format. More...
 

Detailed Description

Bridge vector class to sf::Vector2i/f that provides some common math methods.

It can be implicitly constructed from a sf::Vector2i or sf::Vector2f and can be converted implicitly to those same types.

Member Function Documentation

◆ angle()

double Vec2d::angle ( ) const

Computes the angle of the vector in polar coordinates.

Returns
the angle of this, in [-PI, PI]

◆ dot()

double Vec2d::dot ( Vec2d const &  other) const

Computes the dot product between this and another vector.

Parameters
otheranother vector
Returns
the inner product

◆ fromAngle()

Vec2d Vec2d::fromAngle ( double  rad)
static

Create a unitary Vec2d from an angle.

Parameters
radthe angle
Returns
the corresponding Vec2d

◆ fromJSON()

Vec2d Vec2d::fromJSON ( j::Value  json)
static

Construct a vector from its internal representation in JSON format.

Exceptions
j::BadConversionor j::NoSuchElement if internal format is not valid
See also
save

◆ fromRandomAngle()

Vec2d Vec2d::fromRandomAngle ( double  min = 0,
double  max = TAU 
)
static

Create a random vector.

Parameters
minminimal angle in rad
maxmaximal angle in rad
Returns
a random vector

◆ length()

double Vec2d::length ( ) const

Computes the length of the vector.

Returns
the module of this

◆ lengthSquared()

double Vec2d::lengthSquared ( ) const

Computes the length of the vector (squared).

Returns
the square module of this

◆ normal()

Vec2d Vec2d::normal ( ) const

Computes the normal (orthogonal) vector for this vector.

Returns
n such that this ยท n = 0

◆ normalised()

Vec2d Vec2d::normalised ( ) const

Computes the normalized vector.

Returns
w such that |w| and w * |this| = this

◆ operator[]()

double Vec2d::operator[] ( int  axis) const

Accesses the coordinates by dimension, read-only.

Parameters
axisonly value 0 and 1 are allowed
Returns
x if axis is 0, y if axis if 1, undefined otherwise

Accesses the coordinates by dimension, read-only.

Parameters
axisonly value 0 and 1 are allowed
Returns
x if axis is 0, y if axis if 1, undefined otherwise

◆ sign()

int Vec2d::sign ( Vec2d const &  other) const

Compares the angle between another vector and this one.

Returns
1 if other is clockwise of this vector, -1 otherwise (anticlockwise), or 0 if other is null or equal to this vector.

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