ʻOhana
Population structure, admixture history, and selection using learning methods.
Public Types | Public Member Functions | Static Public Member Functions | Data Fields
jade::basic_vec2< TValue > Class Template Reference

A template for a class that implements rank-two vector operations. More...

#include <jade.vec2.hpp>

+ Inheritance diagram for jade::basic_vec2< TValue >:
+ Collaboration diagram for jade::basic_vec2< TValue >:

Public Types

typedef TValue value_type
 The value type. More...
 

Public Member Functions

 basic_vec2 ()
 Implements a new insatnce of the class. More...
 
 basic_vec2 (const value_type x_, const value_type y_)
 Implements a new insatnce of the class with the specified values. More...
 
value_type get_length () const
 
value_type get_length_squared () const
 
basic_vec2operator+= (const basic_vec2 &rhs)
 
basic_vec2operator+= (const value_type &rhs)
 
basic_vec2operator-= (const basic_vec2 &rhs)
 
basic_vec2operator-= (const value_type &rhs)
 
basic_vec2operator*= (const value_type &rhs)
 
basic_vec2operator/= (const value_type &rhs)
 
basic_vec2 operator+ (const value_type &rhs) const
 
basic_vec2 operator+ (const basic_vec2 &rhs) const
 
basic_vec2 operator- (const value_type &rhs) const
 
basic_vec2 operator- (const basic_vec2 &rhs) const
 
basic_vec2 operator* (const value_type &rhs) const
 
basic_vec2 operator/ (const value_type &rhs) const
 

Static Public Member Functions

static value_type cross (const basic_vec2 &lhs, const basic_vec2 &rhs)
 
static value_type distance (const basic_vec2 &a, const basic_vec2 &b)
 
static value_type distance_squared (const basic_vec2 &a, const basic_vec2 &b)
 
static basic_vec2 dot (const basic_vec2 &a, const basic_vec2 &b)
 
static basic_vec2 lerp (const basic_vec2 &src, const basic_vec2 &dst, const value_type percent)
 
static basic_vec2 max (const basic_vec2 &a, const basic_vec2 &b)
 
static basic_vec2 min (const basic_vec2 &a, const basic_vec2 &b)
 
static basic_vec2 normalize (const basic_vec2 &v)
 

Data Fields

value_type x
 The X coordinate. More...
 
value_type y
 The Y coordinate. More...
 

Detailed Description

template<typename TValue>
class jade::basic_vec2< TValue >

A template for a class that implements rank-two vector operations.

Definition at line 18 of file jade.vec2.hpp.

Member Typedef Documentation

◆ value_type

template<typename TValue >
typedef TValue jade::basic_vec2< TValue >::value_type

The value type.

Definition at line 21 of file jade.vec2.hpp.

Constructor & Destructor Documentation

◆ basic_vec2() [1/2]

template<typename TValue >
jade::basic_vec2< TValue >::basic_vec2 ( )
inline

Implements a new insatnce of the class.

Definition at line 29 of file jade.vec2.hpp.

30  : x (0)
31  , y (0)
32  {
33  }
+ Here is the caller graph for this function:

◆ basic_vec2() [2/2]

template<typename TValue >
jade::basic_vec2< TValue >::basic_vec2 ( const value_type  x_,
const value_type  y_ 
)
inline

Implements a new insatnce of the class with the specified values.

Parameters
x_The initial X coordinate.
y_The initial Y coordinate.

Definition at line 38 of file jade.vec2.hpp.

41  : x (x_)
42  , y (y_)
43  {
44  }

Member Function Documentation

◆ cross()

template<typename TValue >
static value_type jade::basic_vec2< TValue >::cross ( const basic_vec2< TValue > &  lhs,
const basic_vec2< TValue > &  rhs 
)
inlinestatic
Returns
The cross product for two vectors.
Parameters
lhsThe first vector.
rhsThe second vector.

Definition at line 49 of file jade.vec2.hpp.

52  {
53  return (lhs.x * rhs.y) - (lhs.y * rhs.x);
54  }

◆ distance()

template<typename TValue >
static value_type jade::basic_vec2< TValue >::distance ( const basic_vec2< TValue > &  a,
const basic_vec2< TValue > &  b 
)
inlinestatic
Returns
The distance between two vectors.
Parameters
aThe first vector.
bThe second vector.

Definition at line 59 of file jade.vec2.hpp.

62  {
63  return (a - b).get_length();
64  }

◆ distance_squared()

template<typename TValue >
static value_type jade::basic_vec2< TValue >::distance_squared ( const basic_vec2< TValue > &  a,
const basic_vec2< TValue > &  b 
)
inlinestatic
Returns
The distance between two vectors.
Parameters
aThe first vector.
bThe second vector.

Definition at line 69 of file jade.vec2.hpp.

72  {
73  return (a - b).get_length_squared();
74  }

◆ dot()

template<typename TValue >
static basic_vec2 jade::basic_vec2< TValue >::dot ( const basic_vec2< TValue > &  a,
const basic_vec2< TValue > &  b 
)
inlinestatic
Returns
The dot product of two vectors.
Parameters
aThe first vector.
bThe second vector.

Definition at line 79 of file jade.vec2.hpp.

82  {
83  return basic_vec2(a.x * b.x, a.y * b.y);
84  }

◆ get_length()

template<typename TValue >
value_type jade::basic_vec2< TValue >::get_length ( ) const
inline
Returns
The length of the vector.

Definition at line 89 of file jade.vec2.hpp.

90  {
91  return std::sqrt(get_length_squared());
92  }
+ Here is the caller graph for this function:

◆ get_length_squared()

template<typename TValue >
value_type jade::basic_vec2< TValue >::get_length_squared ( ) const
inline
Returns
The length of the vector.

Definition at line 97 of file jade.vec2.hpp.

98  {
99  return (x * x) + (y * y);
100  }
+ Here is the caller graph for this function:

◆ lerp()

template<typename TValue >
static basic_vec2 jade::basic_vec2< TValue >::lerp ( const basic_vec2< TValue > &  src,
const basic_vec2< TValue > &  dst,
const value_type  percent 
)
inlinestatic
Returns
A new vector from linearly interpolating between two other vectors.
Parameters
srcThe first vector.
dstThe second vector.
percentThe percentage.

Definition at line 106 of file jade.vec2.hpp.

110  {
111  return src + (dst - src) * percent;
112  }

◆ max()

template<typename TValue >
static basic_vec2 jade::basic_vec2< TValue >::max ( const basic_vec2< TValue > &  a,
const basic_vec2< TValue > &  b 
)
inlinestatic
Returns
The maximum of two vectors.
Parameters
aThe first vector.
bThe second vector.

Definition at line 117 of file jade.vec2.hpp.

120  {
121  return basic_vec2(std::max(a.x, b.x), std::max(a.y, b.y));
122  }

◆ min()

template<typename TValue >
static basic_vec2 jade::basic_vec2< TValue >::min ( const basic_vec2< TValue > &  a,
const basic_vec2< TValue > &  b 
)
inlinestatic
Returns
The minimum of two vectors.
Parameters
aThe first vector.
bThe second vector.

Definition at line 127 of file jade.vec2.hpp.

130  {
131  return basic_vec2(std::min(a.x, b.x), std::min(a.y, b.y));
132  }

◆ normalize()

template<typename TValue >
static basic_vec2 jade::basic_vec2< TValue >::normalize ( const basic_vec2< TValue > &  v)
inlinestatic
Returns
The normal for the specified vector.
Parameters
vThe vector.

Definition at line 137 of file jade.vec2.hpp.

139  {
140  return v / v.get_length();
141  }

◆ operator*()

template<typename TValue >
basic_vec2 jade::basic_vec2< TValue >::operator* ( const value_type rhs) const
inline
Returns
A new vector based on the specified operator.
Parameters
rhsThe right operand.

Definition at line 252 of file jade.vec2.hpp.

255  {
256  return basic_vec2(*this) *= rhs;
257  }

◆ operator*=()

template<typename TValue >
basic_vec2& jade::basic_vec2< TValue >::operator*= ( const value_type rhs)
inline
Returns
This instance after the operation with the specified value.
Parameters
rhsThe right operand.

Definition at line 190 of file jade.vec2.hpp.

192  {
193  x *= rhs;
194  y *= rhs;
195  return *this;
196  }

◆ operator+() [1/2]

template<typename TValue >
basic_vec2 jade::basic_vec2< TValue >::operator+ ( const basic_vec2< TValue > &  rhs) const
inline
Returns
A new vector based on the specified operator.
Parameters
rhsThe right operand.

Definition at line 222 of file jade.vec2.hpp.

225  {
226  return basic_vec2(*this) += rhs;
227  }

◆ operator+() [2/2]

template<typename TValue >
basic_vec2 jade::basic_vec2< TValue >::operator+ ( const value_type rhs) const
inline
Returns
A new vector based on the specified operator.
Parameters
rhsThe right operand.

Definition at line 212 of file jade.vec2.hpp.

215  {
216  return basic_vec2(*this) += rhs;
217  }

◆ operator+=() [1/2]

template<typename TValue >
basic_vec2& jade::basic_vec2< TValue >::operator+= ( const basic_vec2< TValue > &  rhs)
inline
Returns
This instance after the operation with the specified value.
Parameters
rhsThe right operand.

Definition at line 146 of file jade.vec2.hpp.

148  {
149  x += rhs.x;
150  y += rhs.y;
151  return *this;
152  }

◆ operator+=() [2/2]

template<typename TValue >
basic_vec2& jade::basic_vec2< TValue >::operator+= ( const value_type rhs)
inline
Returns
This instance after the operation with the specified value.
Parameters
rhsThe right operand.

Definition at line 157 of file jade.vec2.hpp.

159  {
160  x += rhs;
161  y += rhs;
162  return *this;
163  }

◆ operator-() [1/2]

template<typename TValue >
basic_vec2 jade::basic_vec2< TValue >::operator- ( const basic_vec2< TValue > &  rhs) const
inline
Returns
A new vector based on the specified operator.
Parameters
rhsThe right operand.

Definition at line 242 of file jade.vec2.hpp.

245  {
246  return basic_vec2(*this) -= rhs;
247  }

◆ operator-() [2/2]

template<typename TValue >
basic_vec2 jade::basic_vec2< TValue >::operator- ( const value_type rhs) const
inline
Returns
A new vector based on the specified operator.
Parameters
rhsThe right operand.

Definition at line 232 of file jade.vec2.hpp.

235  {
236  return basic_vec2(*this) -= rhs;
237  }

◆ operator-=() [1/2]

template<typename TValue >
basic_vec2& jade::basic_vec2< TValue >::operator-= ( const basic_vec2< TValue > &  rhs)
inline
Returns
This instance after the operation with the specified value.
Parameters
rhsThe right operand.

Definition at line 168 of file jade.vec2.hpp.

170  {
171  x -= rhs.x;
172  y -= rhs.y;
173  return *this;
174  }

◆ operator-=() [2/2]

template<typename TValue >
basic_vec2& jade::basic_vec2< TValue >::operator-= ( const value_type rhs)
inline
Returns
This instance after the operation with the specified value.
Parameters
rhsThe right operand.

Definition at line 179 of file jade.vec2.hpp.

181  {
182  x -= rhs;
183  y -= rhs;
184  return *this;
185  }

◆ operator/()

template<typename TValue >
basic_vec2 jade::basic_vec2< TValue >::operator/ ( const value_type rhs) const
inline
Returns
A new vector based on the specified operator.
Parameters
rhsThe right operand.

Definition at line 262 of file jade.vec2.hpp.

265  {
266  return basic_vec2(*this) /= rhs;
267  }

◆ operator/=()

template<typename TValue >
basic_vec2& jade::basic_vec2< TValue >::operator/= ( const value_type rhs)
inline
Returns
This instance after the operation with the specified value.
Parameters
rhsThe right operand.

Definition at line 201 of file jade.vec2.hpp.

203  {
204  x /= rhs;
205  y /= rhs;
206  return *this;
207  }

Field Documentation

◆ x

template<typename TValue >
value_type jade::basic_vec2< TValue >::x

The X coordinate.

Definition at line 23 of file jade.vec2.hpp.

◆ y

template<typename TValue >
value_type jade::basic_vec2< TValue >::y

The Y coordinate.

Definition at line 24 of file jade.vec2.hpp.


The documentation for this class was generated from the following file:
jade::basic_vec2::get_length_squared
value_type get_length_squared() const
Definition: jade.vec2.hpp:97
jade::basic_vec2::x
value_type x
The X coordinate.
Definition: jade.vec2.hpp:23
jade::basic_vec2::y
value_type y
The Y coordinate.
Definition: jade.vec2.hpp:24
jade::basic_vec2::basic_vec2
basic_vec2()
Implements a new insatnce of the class.
Definition: jade.vec2.hpp:29