sculpto
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
scl::math::vec2< T > Class Template Reference

#include <vec2.h>

Public Member Functions

SetX (T X)
 
SetY (T Y)
 
GetX () const
 
GetY () const
 
 vec2 ()=default
 
 vec2 (T A)
 
 vec2 (T X, T Y)
 
 vec2 (const vec2 &Other)
 
vec2operator= (const vec2 &Other)
 
Length2 () const
 
Length () const
 
Distacnce (const vec2 &Other) const
 
vec2 Normalized () const
 
vec2Normalize ()
 
Dot (const vec2 &Other) const
 
bool operator== (const vec2 &Other)
 
const vec2 operator- () const
 
const vec2 operator+ (const vec2 &Other) const
 
const vec2operator+= (const vec2 &Other)
 
const vec2 operator+ (float Scalar) const
 
const vec2operator+= (float Scalar)
 
const vec2 operator- (const vec2 &Other) const
 
const vec2operator-= (const vec2 &Other)
 
const vec2 operator- (float Scalar) const
 
const vec2operator-= (float Scalar)
 
const vec2 operator* (const vec2 &Other) const
 
const vec2operator*= (const vec2 &Other)
 
const vec2 operator* (float Scalar) const
 
const vec2operator*= (float Scalar)
 
const vec2 operator/ (const vec2 &Other) const
 
const vec2operator/= (const vec2 &Other)
 
const vec2 operator/ (float Scalar) const
 
const vec2operator/= (float Scalar)
 
 operator T* ()
 
T & operator[] (int Index)
 
operator[] (int Index) const
 

Static Public Member Functions

static vec2 Zero ()
 
static vec2 Rnd (T Min=0, T Max=1)
 
static vec2 Min (const vec2 &A, const vec2 &B)
 
static vec2 Max (const vec2 &A, const vec2 &B)
 

Public Attributes

X { 0 }
 
Y { 0 }
 

Detailed Description

template<typename T>
class scl::math::vec2< T >

Definition at line 25 of file vec2.h.

Constructor & Destructor Documentation

◆ vec2() [1/4]

template<typename T >
scl::math::vec2< T >::vec2 ( )
default

Vector construcotrs.

Default construcotr. All coodinates would ve set to zero.

◆ vec2() [2/4]

template<typename T >
scl::math::vec2< T >::vec2 ( A)
inlineexplicit
  • Vector constructor by one scalar. All corinates would be set to its value.
Parameters
A- scalar value of all cordinates.

Definition at line 52 of file vec2.h.

52: X(A), Y(A) {}

◆ vec2() [3/4]

template<typename T >
scl::math::vec2< T >::vec2 ( X,
Y 
)
inline
  • Vector constructor by three coordinates.
Parameters
X,Y- coordiantes of creating vector.

Definition at line 59 of file vec2.h.

59: X(X), Y(Y) {}

◆ vec2() [4/4]

template<typename T >
scl::math::vec2< T >::vec2 ( const vec2< T > &  Other)
inline
  • Vector copy constructor.
Parameters
Other- vector to copy from.

Definition at line 66 of file vec2.h.

67 {
68 if (this != &Other)
69 {
70 X = Other.X;
71 Y = Other.Y;
72 }
73 }

Member Function Documentation

◆ Distacnce()

template<typename T >
T scl::math::vec2< T >::Distacnce ( const vec2< T > &  Other) const
inline
  • Distance between two vectors getting function.
Parameters
Other- vector to get distance to.
Returns
distance between vectors.

Definition at line 154 of file vec2.h.

155 {
156 return (*this - Other).Length();
157 }

◆ Dot()

template<typename T >
T scl::math::vec2< T >::Dot ( const vec2< T > &  Other) const
inline
  • Vectors dot product function.
Parameters
Other- vector to multiply
Returns
value of vectors dot product.

Definition at line 188 of file vec2.h.

189 {
190 return X * Other.X + Y * Other.Y;
191 }

◆ GetX()

template<typename T >
T scl::math::vec2< T >::GetX ( ) const
inline

X vector component getter function.

Definition at line 38 of file vec2.h.

38{ return X; }

◆ GetY()

template<typename T >
T scl::math::vec2< T >::GetY ( ) const
inline

Y vector component getter function.

Definition at line 40 of file vec2.h.

40{ return Y; }

◆ Length()

template<typename T >
T scl::math::vec2< T >::Length ( ) const
inline
  • Vector length getting function.
Parameters
None.
Returns
length of vector.

Definition at line 143 of file vec2.h.

144 {
145 return sqrt(Length2());
146 }
T Length2() const
Definition: vec2.h:132

◆ Length2()

template<typename T >
T scl::math::vec2< T >::Length2 ( ) const
inline

Vector methods.

  • Vector squared length getting function.
Parameters
None.
Returns
length of vector.

Definition at line 132 of file vec2.h.

133 {
134 return X * X + Y * Y;
135 }

◆ Max()

template<typename T >
static vec2 scl::math::vec2< T >::Max ( const vec2< T > &  A,
const vec2< T > &  B 
)
inlinestatic
  • Vector with compund of maximums of specified vectors components.
Parameters
A,B- vectors to take maximums of components.
Returns
minimum vector.

Definition at line 123 of file vec2.h.

123{ return vec2(math::Max(A.X, B.X), math::Max(A.Y, B.Y)); }
vec2()=default
T Max(T Num1, T Num2)
Definition: math_common.h:61

◆ Min()

template<typename T >
static vec2 scl::math::vec2< T >::Min ( const vec2< T > &  A,
const vec2< T > &  B 
)
inlinestatic
  • Vector with compund of minimums of specified vectors components.
Parameters
A,B- vectors to take minimums of components.
Returns
minimum vector.

Definition at line 115 of file vec2.h.

115{ return vec2(math::Min(A.X, B.X), math::Min(A.Y, B.Y)); }
T Min(T Num1, T Num2)
Definition: math_common.h:49

◆ Normalize()

template<typename T >
vec2 & scl::math::vec2< T >::Normalize ( )
inline
  • Normalize vector function.
Parameters
None.
Returns
normalized vector.

Definition at line 176 of file vec2.h.

177 {
178 *this /= Length();
179 return *this;
180 }
T Length() const
Definition: vec2.h:143

◆ Normalized()

template<typename T >
vec2 scl::math::vec2< T >::Normalized ( ) const
inline
  • Normalized vector getting function.
Parameters
None.
Returns
normalized vector.

Definition at line 165 of file vec2.h.

166 {
167 return *this / Length();
168 }

◆ operator T*()

template<typename T >
scl::math::vec2< T >::operator T* ( )
inline
  • Getting pointer to first component of vector operator. Need to pass vector to shader.
Returns
pointer to first component of vector.

Definition at line 417 of file vec2.h.

418 {
419 return &X;
420 }

◆ operator*() [1/2]

template<typename T >
const vec2 scl::math::vec2< T >::operator* ( const vec2< T > &  Other) const
inline
  • Vectors multiplying operator overloading.
Parameters
Other- vector to multiply.
Returns
vector with multiplied coordinates.

Definition at line 319 of file vec2.h.

320 {
321 return vec2(X * Other.X, Y * Other.Y);
322 }

◆ operator*() [2/2]

template<typename T >
const vec2 scl::math::vec2< T >::operator* ( float  Scalar) const
inline
  • Vectors multiplying operator overloading.
Parameters
Scalar- scalar value to add to all vetcors components
Returns
vector with added coordinates.

Definition at line 343 of file vec2.h.

344 {
345 return vec2(X * Scalar,
346 Y * Scalar);
347 }

◆ operator*=() [1/2]

template<typename T >
const vec2 & scl::math::vec2< T >::operator*= ( const vec2< T > &  Other)
inline
  • Vectors multiplying with assigments operator overlaoding.
Parameters
Other- vector to multiply.
Returns
self reference.

Definition at line 330 of file vec2.h.

331 {
332 X *= Other.X;
333 Y *= Other.Y;
334 return *this;
335 }

◆ operator*=() [2/2]

template<typename T >
const vec2 & scl::math::vec2< T >::operator*= ( float  Scalar)
inline
  • Vectors multiplying with assigments operator overlaoding.
Parameters
Other- vector to add.
Returns
self reference

Definition at line 355 of file vec2.h.

356 {
357 X *= Scalar;
358 Y *= Scalar;
359 return *this;
360 }

◆ operator+() [1/2]

template<typename T >
const vec2 scl::math::vec2< T >::operator+ ( const vec2< T > &  Other) const
inline
  • Vectors addition operator overloading.
Parameters
Other- vector to add.
Returns
vector with added coordinates.

Definition at line 222 of file vec2.h.

223 {
224 return vec2(X + Other.X, Y + Other.Y);
225 }

◆ operator+() [2/2]

template<typename T >
const vec2 scl::math::vec2< T >::operator+ ( float  Scalar) const
inline
  • Vectors addition operator overloading.
Parameters
Scalar- scalar value to add to all vetcors components
Returns
vector with added coordinates.

Definition at line 246 of file vec2.h.

247 {
248 return vec2(X + Scalar, Y + Scalar);
249 }

◆ operator+=() [1/2]

template<typename T >
const vec2 & scl::math::vec2< T >::operator+= ( const vec2< T > &  Other)
inline
  • Vectors addition with assigments operator overlaoding.
Parameters
Other- vector to add.
Returns
self reference

Definition at line 233 of file vec2.h.

234 {
235 X += Other.X;
236 Y += Other.Y;
237 return *this;
238 }

◆ operator+=() [2/2]

template<typename T >
const vec2 & scl::math::vec2< T >::operator+= ( float  Scalar)
inline
  • Vectors addition with assigments operator overlaoding.
Parameters
Other- vector to add.
Returns
self reference

Definition at line 257 of file vec2.h.

258 {
259 X += Scalar;
260 Y += Scalar;
261 return *this;
262 }

◆ operator-() [1/3]

template<typename T >
const vec2 scl::math::vec2< T >::operator- ( ) const
inline
  • Getting negative vector operation.
Parameters
None.
Returns
negative vector.

Definition at line 211 of file vec2.h.

212 {
213 return vec2(-X, -Y);
214 }

◆ operator-() [2/3]

template<typename T >
const vec2 scl::math::vec2< T >::operator- ( const vec2< T > &  Other) const
inline
  • Vectors subtraction operator overloading.
Parameters
Other- vector to subtract.
Returns
vector with subtract coordinates.

Definition at line 270 of file vec2.h.

271 {
272 return vec2(X - Other.X, Y - Other.Y);
273 }

◆ operator-() [3/3]

template<typename T >
const vec2 scl::math::vec2< T >::operator- ( float  Scalar) const
inline
  • Vectors subtraction operator overloading.
Parameters
Scalar- scalar value to add to all vetcors components
Returns
vector with added coordinates.

Definition at line 294 of file vec2.h.

295 {
296 return vec2(X - Scalar,
297 Y - Scalar);
298 }

◆ operator-=() [1/2]

template<typename T >
const vec2 & scl::math::vec2< T >::operator-= ( const vec2< T > &  Other)
inline
  • Vectors subtraction with assigments operator overlaoding.
Parameters
Other- vector to subtract.
Returns
self reference.

Definition at line 281 of file vec2.h.

282 {
283 X -= Other.X;
284 Y -= Other.Y;
285 return *this;
286 }

◆ operator-=() [2/2]

template<typename T >
const vec2 & scl::math::vec2< T >::operator-= ( float  Scalar)
inline
  • Vectors subtraction with assigments operator overlaoding.
Parameters
Other- vector to add.
Returns
self reference

Definition at line 306 of file vec2.h.

307 {
308 X -= Scalar;
309 Y -= Scalar;
310 return *this;
311 }

◆ operator/() [1/2]

template<typename T >
const vec2 scl::math::vec2< T >::operator/ ( const vec2< T > &  Other) const
inline
  • Vectors dividing operator overloading.
Parameters
Other- vector to devide.
Returns
vector with devided coordinates.

Definition at line 368 of file vec2.h.

369 {
370 return vec2(X / Other.X, Y / Other.Y);
371 }

◆ operator/() [2/2]

template<typename T >
const vec2 scl::math::vec2< T >::operator/ ( float  Scalar) const
inline
  • Vectors dividing operator overloading.
Parameters
Scalar- scalar value to add to all vetcors components
Returns
vector with added coordinates.

Definition at line 392 of file vec2.h.

393 {
394 return vec2(X / Scalar,
395 Y / Scalar);
396 }

◆ operator/=() [1/2]

template<typename T >
const vec2 & scl::math::vec2< T >::operator/= ( const vec2< T > &  Other)
inline
  • Vectors dividing with assigments operator overlaoding.
Parameters
Other- vector to devide.
Returns
self reference.

Definition at line 379 of file vec2.h.

380 {
381 X /= Other.X;
382 Y /= Other.Y;
383 return *this;
384 }

◆ operator/=() [2/2]

template<typename T >
const vec2 & scl::math::vec2< T >::operator/= ( float  Scalar)
inline
  • Vectors dividing with assigments operator overlaoding.
Parameters
Other- vector to add.
Returns
self reference

Definition at line 404 of file vec2.h.

405 {
406 X /= Scalar;
407 Y /= Scalar;
408 return *this;
409 }

◆ operator=()

template<typename T >
vec2 & scl::math::vec2< T >::operator= ( const vec2< T > &  Other)
inline
  • Vector assigments operator overloading.
Parameters
Other- vector to copy from.
Returns
self reference.

Definition at line 81 of file vec2.h.

82 {
83 if (this != &Other)
84 {
85 X = Other.X;
86 Y = Other.Y;
87 }
88 return *this;
89 }

◆ operator==()

template<typename T >
bool scl::math::vec2< T >::operator== ( const vec2< T > &  Other)
inline

Operators overloading.

  • Vector compare function.
Parameters
Other- vector to compare with.
Returns
is vectors equal flag.

Definition at line 200 of file vec2.h.

201 {
202 return X == Other.X && Y == Other.Y;
203 }

◆ operator[]() [1/2]

template<typename T >
T & scl::math::vec2< T >::operator[] ( int  Index)
inline
  • Getting coordinate operator overloading.
Parameters
Index- coordinate index.
Returns
vector cartesian coordinate.

Definition at line 428 of file vec2.h.

429 {
430 switch (Index)
431 {
432 case 0: return X;
433 default:
434 case 1: return Y;
435 }
436 }

◆ operator[]() [2/2]

template<typename T >
T scl::math::vec2< T >::operator[] ( int  Index) const
inline
  • Getting coordinate operator overloading.
Parameters
Index- coordinate index.
Returns
vector cartesian coordinate.

Definition at line 444 of file vec2.h.

445 {
446 switch (Index)
447 {
448 case 0: return X;
449 default:
450 case 1: return Y;
451 }
452 }

◆ Rnd()

template<typename T >
static vec2 scl::math::vec2< T >::Rnd ( Min = 0,
Max = 1 
)
inlinestatic
  • Vector with all components set to random value in range [Min;Max] creation function.
Parameters
min- lower bound of random number.
Max- upper bound of random number.
Returns
random number in range [Min; Max].

Definition at line 107 of file vec2.h.

107{ return vec2(Rnd(Min, Max)); }
static vec2 Min(const vec2 &A, const vec2 &B)
Definition: vec2.h:115
static vec2 Max(const vec2 &A, const vec2 &B)
Definition: vec2.h:123
static vec2 Rnd(T Min=0, T Max=1)
Definition: vec2.h:107

◆ SetX()

template<typename T >
T scl::math::vec2< T >::SetX ( X)
inline

Public coordinates setters and getters. On coordinate change vector's length calculation state set to false.

X vector component setter function.

Definition at line 34 of file vec2.h.

34{ this->X = X; }

◆ SetY()

template<typename T >
T scl::math::vec2< T >::SetY ( Y)
inline

Y vector component setter function.

Definition at line 36 of file vec2.h.

36{ this->Y = Y; }

◆ Zero()

template<typename T >
static vec2 scl::math::vec2< T >::Zero ( )
inlinestatic

Common vectors creation functinos.

  • Vector with all components set to 0 creation function.
Parameters
None.
Returns
zero vector.

Definition at line 98 of file vec2.h.

98{ return vec2(0); }

Member Data Documentation

◆ X

template<typename T >
T scl::math::vec2< T >::X { 0 }

Vector data.

Cartesian coordinates.

Definition at line 29 of file vec2.h.

◆ Y

template<typename T >
T scl::math::vec2< T >::Y { 0 }

Definition at line 29 of file vec2.h.


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