NGL  6.5
The NCCA Graphics Library
ngl::Vec2 Class Reference

simple Vec2 encapsulates a 3 float object like glsl Vec2 but not maths use the Vec2 class for maths and the asVec2 to return a Vec2 More...

#include <Vec2.h>

+ Collaboration diagram for ngl::Vec2:

Public Member Functions

void set (Real _x, Real _y) noexcept
 sets the Vec2 component from 3 values More...
 
void set (const Vec2 &_v) noexcept
 set from another Vec2 More...
 
void set (const Vec4 &_v) noexcept
 set from another Vector More...
 
void set (const Vec2 *_v) noexcept
 set from another Vec2 More...
 
 Vec2 (const Vec2 &_v) noexcept
 copy ctor More...
 
 Vec2 (Real _x=0.0, Real _y=0.0) noexcept
 initialise the constructor from 3 or 4 Real More...
 
 Vec2 (Real _x) noexcept
 ctor using a single float all components are set to the value _x More...
 
void null () noexcept
 clears the Vec2 to 0,0,0 More...
 
Realoperator[] (int _i) noexcept
 [] index operator to access the index component of the Vec2 More...
 
const Realoperator[] (int _i) const noexcept
 [] index operator to access the index component of the Vec2 More...
 
void operator+= (const Vec2 &_v) noexcept
 += operator add Vec2 v to current Vec2 More...
 
void operator-= (const Vec2 &_v) noexcept
 -= operator this-=v More...
 
Vec2 operator* (const Real &_i) const noexcept
 this * i for each element More...
 
Real length () const noexcept
 returns the length of the vector More...
 
Real lengthSquared () const noexcept
 returns the length squared of the vector (no sqrt so quicker) More...
 
Vec2 operator+ (const Vec2 &_v) const noexcept
 
  • operator add Vec2+Vec2
More...
 
Vec2 operator/ (Real _v) const noexcept
 divide Vec2 components by a scalar More...
 
void operator/= (Real _v) noexcept
 divide this Vec2 components by a scalar More...
 
void operator*= (Real _v) noexcept
 multiply this Vec2 components by a scalar More...
 
Vec2 operator- (const Vec2 &_v) const noexcept
 subtraction operator subtract vevtor-Vec2 More...
 
Vec2 operator* (const Vec2 &_v) const noexcept
 
  • operator mult vevtor*Vec2
More...
 
Vec2operator= (const Vec2 &_v) noexcept
 assignment operator set the current Vec2 to rhs More...
 
Vec2 operator- () const noexcept
 negate the Vec2 components More...
 
bool operator== (const Vec2 &_v) const noexcept
 check for equality uses FCompare (from Util.h) as float values More...
 
bool operator!= (const Vec2 &_v) const noexcept
 not equal check More...
 
Vec2 operator/ (const Vec2 &_v) const noexcept
 \ operator div Vec2/Vec2 More...
 
Vec2 operator* (Real _i) const noexcept
 this * i for each element More...
 
void normalize () noexcept
 Normalize the vector using
$x=x/\sqrt{x^2+y^2} $
$y=y/\sqrt{x^2+y^2} $. More...
 
Real dot (const Vec2 &_b) const noexcept
 return this dotted with _b More...
 
RealopenGL () noexcept
 accesor to the m_openGL matrix returns the address of the 0th element More...
 

Public Attributes

Real m_x
 x component of the Vec2 More...
 
Real m_y
 y component of the Vec2 More...
 
std::array< Real, 2 > m_openGL
 array of four floats mapped to the x,y,z,w components of the Vec2 useful for openGL fv data types this is mapped as a union to the following
m_x == m_openGL[0]
m_y == m_openGL[1]
More...
 

Detailed Description

simple Vec2 encapsulates a 3 float object like glsl Vec2 but not maths use the Vec2 class for maths and the asVec2 to return a Vec2

Definition at line 49 of file Vec2.h.

Constructor & Destructor Documentation

ngl::Vec2::Vec2 ( const Vec2 _v)
inlinenoexcept

copy ctor

Parameters
[in]_vthe value to set

Definition at line 81 of file Vec2.h.

+ Here is the caller graph for this function:

ngl::Vec2::Vec2 ( Real  _x = 0.0,
Real  _y = 0.0 
)
inlinenoexcept

initialise the constructor from 3 or 4 Real

Parameters
[in]_xx value
[in]_yy value
[in]_w1.0f default so acts as a points

Definition at line 91 of file Vec2.h.

ngl::Vec2::Vec2 ( Real  _x)
inlinenoexcept

ctor using a single float all components are set to the value _x

Parameters
[in]_xthe value to set all components

Definition at line 98 of file Vec2.h.

Member Function Documentation

Real ngl::Vec2::dot ( const Vec2 _b) const
noexcept

return this dotted with _b

Parameters
[in]_bvector to dot current vector with
Returns
the dot product

Definition at line 177 of file Vec2.cpp.

References m_x, and m_y.

Real ngl::Vec2::length ( ) const
noexcept

returns the length of the vector

Returns
$\sqrt{x^2+y^2} $

Definition at line 195 of file Vec2.cpp.

References m_x, and m_y.

Real ngl::Vec2::lengthSquared ( ) const
noexcept

returns the length squared of the vector (no sqrt so quicker)

Returns
$x^2+y^2$

Definition at line 184 of file Vec2.cpp.

References m_x, and m_y.

void ngl::Vec2::normalize ( )
noexcept

Normalize the vector using
$x=x/\sqrt{x^2+y^2} $
$y=y/\sqrt{x^2+y^2} $.

Definition at line 164 of file Vec2.cpp.

References m_x, m_y, and NGL_ASSERT.

+ Here is the caller graph for this function:

void ngl::Vec2::null ( )
noexcept

clears the Vec2 to 0,0,0

Definition at line 49 of file Vec2.cpp.

References m_x, and m_y.

Real* ngl::Vec2::openGL ( )
inlinenoexcept

accesor to the m_openGL matrix returns the address of the 0th element

Definition at line 239 of file Vec2.h.

bool ngl::Vec2::operator!= ( const Vec2 _v) const
noexcept

not equal check

Parameters
[in]_vthe Vec2 to check against
Returns
true of false

Definition at line 125 of file Vec2.cpp.

References FCompare, m_x, and m_y.

Vec2 ngl::Vec2::operator* ( const Real _i) const
noexcept

this * i for each element

Parameters
[in]_ithe scalar to mult by
Returns
Vec2
Vec2 ngl::Vec2::operator* ( const Vec2 _v) const
noexcept

  • operator mult vevtor*Vec2

Parameters
[in]_vthe value to mult
Returns
new Vec2 this*v

Definition at line 133 of file Vec2.cpp.

References m_x, m_y, and Vec2().

+ Here is the call graph for this function:

Vec2 ngl::Vec2::operator* ( Real  _i) const
noexcept

this * i for each element

Parameters
[in]_ithe scalar to mult by
Returns
Vec2

Definition at line 148 of file Vec2.cpp.

References m_x, m_y, and Vec2().

+ Here is the call graph for this function:

void ngl::Vec2::operator*= ( Real  _v)
noexcept

multiply this Vec2 components by a scalar

Parameters
[in]_vthe scalar to multiply by sets the Vec2 to Vec2 V(x*v,y*v)

Definition at line 86 of file Vec2.cpp.

References m_x, and m_y.

Vec2 ngl::Vec2::operator+ ( const Vec2 _v) const
noexcept

  • operator add Vec2+Vec2

Parameters
[in]&_vthe value to add
Returns
the Vec2 + v

Definition at line 105 of file Vec2.cpp.

References m_x, m_y, and Vec2().

+ Here is the call graph for this function:

void ngl::Vec2::operator+= ( const Vec2 _v)
noexcept

+= operator add Vec2 v to current Vec2

Parameters
[in]&_vVec2 to add

Definition at line 72 of file Vec2.cpp.

References m_x, and m_y.

Vec2 ngl::Vec2::operator- ( const Vec2 _v) const
noexcept

subtraction operator subtract vevtor-Vec2

Parameters
[in]&_vthe value to sub
Returns
this - v

Definition at line 111 of file Vec2.cpp.

References m_x, m_y, and Vec2().

+ Here is the call graph for this function:

Vec2 ngl::Vec2::operator- ( ) const
noexcept

negate the Vec2 components

Definition at line 65 of file Vec2.cpp.

References m_x, m_y, and Vec2().

+ Here is the call graph for this function:

void ngl::Vec2::operator-= ( const Vec2 _v)
noexcept

-= operator this-=v

Parameters
[in]&_vVec2 to subtract

Definition at line 92 of file Vec2.cpp.

References m_x, and m_y.

Vec2 ngl::Vec2::operator/ ( Real  _v) const
noexcept

divide Vec2 components by a scalar

Parameters
[in]_vthe scalar to divide by
Returns
a Vec2 V(x/v,y/v,z/v,w)

Definition at line 99 of file Vec2.cpp.

References m_x, m_y, and Vec2().

+ Here is the call graph for this function:

Vec2 ngl::Vec2::operator/ ( const Vec2 _v) const
noexcept

\ operator div Vec2/Vec2

Parameters
[in]_vthe value to div by
Returns
Vec2 / Vec2

Definition at line 142 of file Vec2.cpp.

References m_x, m_y, and Vec2().

+ Here is the call graph for this function:

void ngl::Vec2::operator/= ( Real  _v)
noexcept

divide this Vec2 components by a scalar

Parameters
[in]_vthe scalar to divide by sets the Vec2 to Vec2 V(x/v,y/v)

Definition at line 79 of file Vec2.cpp.

References m_x, m_y, and NGL_ASSERT.

Vec2 & ngl::Vec2::operator= ( const Vec2 _v)
noexcept

assignment operator set the current Vec2 to rhs

Parameters
[in]_vthe Vec2 to set
Returns
a new Vec2

Definition at line 156 of file Vec2.cpp.

References m_x, and m_y.

bool ngl::Vec2::operator== ( const Vec2 _v) const
noexcept

check for equality uses FCompare (from Util.h) as float values

Parameters
[in]_vthe Vec2 to check against
Returns
true or false

Definition at line 117 of file Vec2.cpp.

References FCompare, m_x, and m_y.

Real & ngl::Vec2::operator[] ( int  _i)
noexcept

[] index operator to access the index component of the Vec2

Returns
this[x] as a Real

Definition at line 56 of file Vec2.cpp.

References m_x, and NGL_ASSERT.

const Real& ngl::Vec2::operator[] ( int  _i) const
inlinenoexcept

[] index operator to access the index component of the Vec2

Returns
this[x] as a Real

Definition at line 116 of file Vec2.h.

References ngl::operator*(), and ngl::operator==().

+ Here is the call graph for this function:

void ngl::Vec2::set ( Real  _x,
Real  _y 
)
noexcept

sets the Vec2 component from 3 values

Parameters
[in]_xthe x component
[in]_ythe y component

Definition at line 29 of file Vec2.cpp.

void ngl::Vec2::set ( const Vec2 _v)
noexcept

set from another Vec2

Parameters
[in]_vthe Vec2 to set from

Definition at line 36 of file Vec2.cpp.

void ngl::Vec2::set ( const Vec4 _v)
noexcept

set from another Vector

Parameters
[in]_vthe Vec2 to set from
void ngl::Vec2::set ( const Vec2 _v)
noexcept

set from another Vec2

Parameters
[in]_vthe Vec2 to set from

Definition at line 42 of file Vec2.cpp.

Member Data Documentation

std::array<Real,2> ngl::Vec2::m_openGL

array of four floats mapped to the x,y,z,w components of the Vec2 useful for openGL fv data types this is mapped as a union to the following
m_x == m_openGL[0]
m_y == m_openGL[1]

Definition at line 273 of file Vec2.h.

Real ngl::Vec2::m_x

x component of the Vec2

Note
I've made this public as some compilers automatically make the anonymous unions public whereas clang++ complains see this post http://jonmacey.blogspot.com/2011/03/anonymous-union-struct-weirdness.html

Definition at line 256 of file Vec2.h.

Real ngl::Vec2::m_y

y component of the Vec2

Definition at line 260 of file Vec2.h.


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