sculpto
Classes | Functions | Variables
scl::math Namespace Reference

Classes

struct  degrees
 
class  matr3
 
class  matr3_data
 
class  matr4
 
class  matr4_data
 
struct  radians
 
class  vec2
 
class  vec3
 
class  vec4
 

Functions

template<typename T >
void to_json (json &Json, const vec2< T > &Vector)
 
template<typename T >
void to_json (json &Json, const vec3< T > &Vector)
 
template<typename T >
void to_json (json &Json, const vec4< T > &Vector)
 
template<typename T >
void to_json (json &Json, const matr3< T > &Matrix)
 
template<typename T >
void to_json (json &Json, const matr4< T > &Matrix)
 
template<typename T >
void from_json (const json &Json, vec2< T > &Vector)
 
template<typename T >
void from_json (const json &Json, vec3< T > &Vector)
 
template<typename T >
void from_json (const json &Json, vec4< T > &Vector)
 
template<typename T >
void from_json (const json &Json, matr3< T > &Matrix)
 
template<typename T >
void from_json (const json &Json, matr4< T > &Matrix)
 
template<typename T >
Min (T Num1, T Num2)
 
template<typename T >
Max (T Num1, T Num2)
 
template<typename T >
Clamp (T Num, T Min=0, T Max=1)
 
template<typename T >
Lerp (T Start, T End, T Current)
 
template<typename T >
Rnd0 ()
 
template<typename T >
Rnd (T Min=0, T Max=1)
 

Variables

const float E = 2.7182818284590f
 
const float LOG2E = 1.4426950408889f
 
const float LOG10E = 0.4342944819032f
 
const float LN2 = 0.6931471805599f
 
const float LN10 = 2.3025850929940f
 
const float PI = 3.1415926535897f
 
const float PI_2 = 1.5707963267948f
 
const float PI_4 = 0.7853981633974f
 
const float REV_1_PI = 0.3183098861837f
 
const float REV_2_PI = 0.6366197723675f
 
const float REV_2_SQRTPI = 1.1283791670955f
 
const float SQRT2 = 1.4142135623730f
 
const float SQRT1_2 = 0.7071067811865f
 

Detailed Description


Common types serialization/deserialization to json format functions.

Function Documentation

◆ Clamp()

template<typename T >
T scl::math::Clamp ( Num,
Min = 0,
Max = 1 
)
  • Number clamping function. If number is higher then upper bound value returned. If number is lower then lower bound value returned.
Parameters
Num- number to be clamped.
Min- lower clipping limit.
Max- upper clipping limit.
Returns
clamped value.

Definition at line 77 of file math_common.h.

78 {
79 return Num < Min ? Min : Num > Max ? Max : Num;
80 }
T Max(T Num1, T Num2)
Definition: math_common.h:61

◆ from_json() [1/5]

template<typename T >
void scl::math::from_json ( const json Json,
matr3< T > &  Matrix 
)

Definition at line 47 of file scene_serializer.h.

48 {
49 if (!Json.is_array()) return;
50 for (int i = 0; i < 9 && i < Json.size(); i++) Matrix[i] = Json[i];
51 }

◆ from_json() [2/5]

template<typename T >
void scl::math::from_json ( const json Json,
matr4< T > &  Matrix 
)

Definition at line 52 of file scene_serializer.h.

53 {
54 if (!Json.is_array()) return;
55 for (int i = 0; i < 16 && i < Json.size(); i++) Matrix[i] = Json[i];
56 }

◆ from_json() [3/5]

template<typename T >
void scl::math::from_json ( const json Json,
vec2< T > &  Vector 
)

Definition at line 32 of file scene_serializer.h.

33 {
34 if (!Json.is_array()) return;
35 for (int i = 0; i < 2 && i < Json.size(); i++) Vector[i] = Json[i];
36 }

◆ from_json() [4/5]

template<typename T >
void scl::math::from_json ( const json Json,
vec3< T > &  Vector 
)

Definition at line 37 of file scene_serializer.h.

38 {
39 if (!Json.is_array()) return;
40 for (int i = 0; i < 3 && i < Json.size(); i++) Vector[i] = Json[i];
41 }

◆ from_json() [5/5]

template<typename T >
void scl::math::from_json ( const json Json,
vec4< T > &  Vector 
)

Definition at line 42 of file scene_serializer.h.

43 {
44 if (!Json.is_array()) return;
45 for (int i = 0; i < 4 && i < Json.size(); i++) Vector[i] = Json[i];
46 }

◆ Lerp()

template<typename T >
T scl::math::Lerp ( Start,
End,
Current 
)
  • Linear interpolation between two points function.
Parameters
Start- first point value.
End- second point value.
Current- interpolation value [0;1].
Returns
value.

Definition at line 91 of file math_common.h.

92 {
93 return Start + (End - Start) * Current;
94 }

◆ Max()

template<typename T >
T scl::math::Max ( Num1,
Num2 
)
  • Getting biggest number function.
Parameters
Num1,Num2- numbers to biggest one be chosen from.
Returns
smallest number from pair.

Definition at line 61 of file math_common.h.

62 {
63 return Num1 > Num2 ? Num1 : Num2;
64 }

◆ Min()

template<typename T >
T scl::math::Min ( Num1,
Num2 
)
  • Getting smallest number function.
Parameters
Num1,Num2- numbers to smallest one be chosen from.
Returns
smallest number from pair.

Definition at line 49 of file math_common.h.

50 {
51 return Num1 < Num2 ? Num1 : Num2;
52 }

◆ Rnd()

template<typename T >
T scl::math::Rnd ( Min = 0,
Max = 1 
)
  • Getting randow number function.
Parameters
min- lower bound of random number.
Max- upper bound of random number.
Returns
random number in range [Min; Max].

Definition at line 116 of file math_common.h.

117 {
118 return Min + Rnd0<T>() * (Max - Min + 1);
119 }
T Min(T Num1, T Num2)
Definition: math_common.h:49

◆ Rnd0()

template<typename T >
T scl::math::Rnd0 ( )
  • Getting random number function.
Parameters
None.
Returns
random number in range [0;1].

Definition at line 103 of file math_common.h.

104 {
105 return static_cast<T>(rand()) / RAND_MAX;
106 }

◆ to_json() [1/5]

template<typename T >
void scl::math::to_json ( json Json,
const matr3< T > &  Matrix 
)

Definition at line 29 of file scene_serializer.h.

29{ Json = { Matrix.A }; }

◆ to_json() [2/5]

template<typename T >
void scl::math::to_json ( json Json,
const matr4< T > &  Matrix 
)

Definition at line 30 of file scene_serializer.h.

30{ Json = { Matrix.A }; }

◆ to_json() [3/5]

template<typename T >
void scl::math::to_json ( json Json,
const vec2< T > &  Vector 
)

Definition at line 26 of file scene_serializer.h.

26{ Json = { Vector.X, Vector.Y }; }

◆ to_json() [4/5]

template<typename T >
void scl::math::to_json ( json Json,
const vec3< T > &  Vector 
)

Definition at line 27 of file scene_serializer.h.

27{ Json = { Vector.X, Vector.Y, Vector.Z }; }

◆ to_json() [5/5]

template<typename T >
void scl::math::to_json ( json Json,
const vec4< T > &  Vector 
)

Definition at line 28 of file scene_serializer.h.

28{ Json = { Vector.X, Vector.Y, Vector.Z, Vector.W }; }

Variable Documentation

◆ E

const float scl::math::E = 2.7182818284590f

Math common constants.

Definition at line 28 of file math_common.h.

◆ LN10

const float scl::math::LN10 = 2.3025850929940f

Definition at line 32 of file math_common.h.

◆ LN2

const float scl::math::LN2 = 0.6931471805599f

Definition at line 31 of file math_common.h.

◆ LOG10E

const float scl::math::LOG10E = 0.4342944819032f

Definition at line 30 of file math_common.h.

◆ LOG2E

const float scl::math::LOG2E = 1.4426950408889f

Definition at line 29 of file math_common.h.

◆ PI

const float scl::math::PI = 3.1415926535897f

Definition at line 33 of file math_common.h.

◆ PI_2

const float scl::math::PI_2 = 1.5707963267948f

Definition at line 34 of file math_common.h.

◆ PI_4

const float scl::math::PI_4 = 0.7853981633974f

Definition at line 35 of file math_common.h.

◆ REV_1_PI

const float scl::math::REV_1_PI = 0.3183098861837f

Definition at line 36 of file math_common.h.

◆ REV_2_PI

const float scl::math::REV_2_PI = 0.6366197723675f

Definition at line 37 of file math_common.h.

◆ REV_2_SQRTPI

const float scl::math::REV_2_SQRTPI = 1.1283791670955f

Definition at line 38 of file math_common.h.

◆ SQRT1_2

const float scl::math::SQRT1_2 = 0.7071067811865f

Definition at line 40 of file math_common.h.

◆ SQRT2

const float scl::math::SQRT2 = 1.4142135623730f

Definition at line 39 of file math_common.h.