cglm 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/Gemfile.lock +18 -16
  4. data/README.md +2 -0
  5. data/cglm.gemspec +3 -3
  6. data/ext/cglm/cglm-0.6.2/include/cglm/affine-mat.h +168 -0
  7. data/ext/cglm/cglm-0.6.2/include/cglm/affine.h +490 -0
  8. data/ext/cglm/cglm-0.6.2/include/cglm/applesimd.h +95 -0
  9. data/ext/cglm/cglm-0.6.2/include/cglm/bezier.h +154 -0
  10. data/ext/cglm/cglm-0.6.2/include/cglm/box.h +279 -0
  11. data/ext/cglm/cglm-0.6.2/include/cglm/call/affine.h +117 -0
  12. data/ext/cglm/cglm-0.6.2/include/cglm/call/bezier.h +31 -0
  13. data/ext/cglm/cglm-0.6.2/include/cglm/call/box.h +79 -0
  14. data/ext/cglm/cglm-0.6.2/include/cglm/call/cam.h +143 -0
  15. data/ext/cglm/cglm-0.6.2/include/cglm/call/curve.h +23 -0
  16. data/ext/cglm/cglm-0.6.2/include/cglm/call/ease.h +143 -0
  17. data/ext/cglm/cglm-0.6.2/include/cglm/call/euler.h +55 -0
  18. data/ext/cglm/cglm-0.6.2/include/cglm/call/frustum.h +41 -0
  19. data/ext/cglm/cglm-0.6.2/include/cglm/call/io.h +44 -0
  20. data/ext/cglm/cglm-0.6.2/include/cglm/call/mat3.h +86 -0
  21. data/ext/cglm/cglm-0.6.2/include/cglm/call/mat4.h +127 -0
  22. data/ext/cglm/cglm-0.6.2/include/cglm/call/plane.h +23 -0
  23. data/ext/cglm/cglm-0.6.2/include/cglm/call/project.h +33 -0
  24. data/ext/cglm/cglm-0.6.2/include/cglm/call/quat.h +159 -0
  25. data/ext/cglm/cglm-0.6.2/include/cglm/call/sphere.h +39 -0
  26. data/ext/cglm/cglm-0.6.2/include/cglm/call/vec3.h +312 -0
  27. data/ext/cglm/cglm-0.6.2/include/cglm/call/vec4.h +290 -0
  28. data/ext/cglm/cglm-0.6.2/include/cglm/call.h +36 -0
  29. data/ext/cglm/cglm-0.6.2/include/cglm/cam.h +585 -0
  30. data/ext/cglm/cglm-0.6.2/include/cglm/cglm.h +32 -0
  31. data/ext/cglm/cglm-0.6.2/include/cglm/color.h +26 -0
  32. data/ext/cglm/cglm-0.6.2/include/cglm/common.h +37 -0
  33. data/ext/cglm/cglm-0.6.2/include/cglm/curve.h +40 -0
  34. data/ext/cglm/cglm-0.6.2/include/cglm/ease.h +317 -0
  35. data/ext/cglm/cglm-0.6.2/include/cglm/euler.h +453 -0
  36. data/ext/cglm/cglm-0.6.2/include/cglm/frustum.h +255 -0
  37. data/ext/cglm/cglm-0.6.2/include/cglm/io.h +203 -0
  38. data/ext/cglm/cglm-0.6.2/include/cglm/mat3.h +422 -0
  39. data/ext/cglm/cglm-0.6.2/include/cglm/mat4.h +726 -0
  40. data/ext/cglm/cglm-0.6.2/include/cglm/plane.h +36 -0
  41. data/ext/cglm/cglm-0.6.2/include/cglm/project.h +118 -0
  42. data/ext/cglm/cglm-0.6.2/include/cglm/quat.h +828 -0
  43. data/ext/cglm/cglm-0.6.2/include/cglm/simd/arm.h +83 -0
  44. data/ext/cglm/cglm-0.6.2/include/cglm/simd/avx/affine.h +66 -0
  45. data/ext/cglm/cglm-0.6.2/include/cglm/simd/avx/mat4.h +66 -0
  46. data/ext/cglm/cglm-0.6.2/include/cglm/simd/intrin.h +90 -0
  47. data/ext/cglm/cglm-0.6.2/include/cglm/simd/neon/mat4.h +57 -0
  48. data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/affine.h +111 -0
  49. data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/mat3.h +59 -0
  50. data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/mat4.h +405 -0
  51. data/ext/cglm/cglm-0.6.2/include/cglm/simd/sse2/quat.h +46 -0
  52. data/ext/cglm/cglm-0.6.2/include/cglm/simd/x86.h +192 -0
  53. data/ext/cglm/cglm-0.6.2/include/cglm/sphere.h +99 -0
  54. data/ext/cglm/cglm-0.6.2/include/cglm/struct/affine.h +337 -0
  55. data/ext/cglm/cglm-0.6.2/include/cglm/struct/box.h +256 -0
  56. data/ext/cglm/cglm-0.6.2/include/cglm/struct/cam.h +451 -0
  57. data/ext/cglm/cglm-0.6.2/include/cglm/struct/color.h +27 -0
  58. data/ext/cglm/cglm-0.6.2/include/cglm/struct/curve.h +40 -0
  59. data/ext/cglm/cglm-0.6.2/include/cglm/struct/euler.h +152 -0
  60. data/ext/cglm/cglm-0.6.2/include/cglm/struct/frustum.h +155 -0
  61. data/ext/cglm/cglm-0.6.2/include/cglm/struct/io.h +82 -0
  62. data/ext/cglm/cglm-0.6.2/include/cglm/struct/mat3.h +285 -0
  63. data/ext/cglm/cglm-0.6.2/include/cglm/struct/mat4.h +459 -0
  64. data/ext/cglm/cglm-0.6.2/include/cglm/struct/plane.h +40 -0
  65. data/ext/cglm/cglm-0.6.2/include/cglm/struct/project.h +104 -0
  66. data/ext/cglm/cglm-0.6.2/include/cglm/struct/quat.h +532 -0
  67. data/ext/cglm/cglm-0.6.2/include/cglm/struct/sphere.h +93 -0
  68. data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec3-ext.h +257 -0
  69. data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec3.h +970 -0
  70. data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec4-ext.h +257 -0
  71. data/ext/cglm/cglm-0.6.2/include/cglm/struct/vec4.h +814 -0
  72. data/ext/cglm/cglm-0.6.2/include/cglm/struct.h +36 -0
  73. data/ext/cglm/cglm-0.6.2/include/cglm/types-struct.h +129 -0
  74. data/ext/cglm/cglm-0.6.2/include/cglm/types.h +76 -0
  75. data/ext/cglm/cglm-0.6.2/include/cglm/util.h +328 -0
  76. data/ext/cglm/cglm-0.6.2/include/cglm/vec3-ext.h +272 -0
  77. data/ext/cglm/cglm-0.6.2/include/cglm/vec3.h +1078 -0
  78. data/ext/cglm/cglm-0.6.2/include/cglm/vec4-ext.h +315 -0
  79. data/ext/cglm/cglm-0.6.2/include/cglm/vec4.h +1078 -0
  80. data/ext/cglm/cglm-0.6.2/include/cglm/version.h +15 -0
  81. data/ext/cglm/extconf.rb +2 -3
  82. data/ext/cglm/rb_cglm.h +5 -3
  83. data/ext/cglm/rb_cglm_mat3.c +3 -3
  84. data/ext/cglm/rb_cglm_mat4.c +3 -3
  85. data/ext/cglm/rb_cglm_quat.c +2 -2
  86. data/ext/cglm/rb_cglm_vec3.c +63 -61
  87. data/ext/cglm/rb_cglm_vec4.c +2 -0
  88. data/ext/cglm/ruby_pre27.h +35 -0
  89. data/lib/cglm/vec3.rb +2 -2
  90. data/lib/cglm/vec4.rb +2 -2
  91. data/lib/cglm/vector_type.rb +15 -0
  92. data/lib/cglm/version.rb +1 -1
  93. metadata +89 -13
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c), Recep Aslantas.
3
+ *
4
+ * MIT License (MIT), http://opensource.org/licenses/MIT
5
+ * Full license can be found in the LICENSE file
6
+ */
7
+
8
+ #ifndef cglm_structs_h
9
+ #define cglm_structs_h
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+
14
+ #include "cglm.h"
15
+ #include "types-struct.h"
16
+ #include "struct/vec3.h"
17
+ #include "struct/vec4.h"
18
+ #include "struct/mat3.h"
19
+ #include "struct/mat4.h"
20
+ #include "struct/affine.h"
21
+ #include "struct/frustum.h"
22
+ #include "struct/plane.h"
23
+ #include "struct/box.h"
24
+ #include "struct/color.h"
25
+ #include "struct/io.h"
26
+ #include "struct/cam.h"
27
+ #include "struct/quat.h"
28
+ #include "struct/euler.h"
29
+ #include "struct/project.h"
30
+ #include "struct/sphere.h"
31
+ #include "struct/curve.h"
32
+
33
+ #ifdef __cplusplus
34
+ }
35
+ #endif
36
+ #endif /* cglm_structs_h */
@@ -0,0 +1,129 @@
1
+ /*
2
+ * Copyright (c), Recep Aslantas.
3
+ *
4
+ * MIT License (MIT), http://opensource.org/licenses/MIT
5
+ * Full license can be found in the LICENSE file
6
+ */
7
+
8
+ #ifndef cglm_types_struct_h
9
+ #define cglm_types_struct_h
10
+
11
+ #include "types.h"
12
+
13
+ /*
14
+ * Anonymous structs are available since C11, but we'd like to be compatible
15
+ * with C99 and C89 too. So let's figure out if we should be using them or not.
16
+ * It's simply a convenience feature, you can e.g. build the library with
17
+ * anonymous structs and your application without them and they'll still be
18
+ * compatible, cglm doesn't use the anonymous structs internally.
19
+ */
20
+ #ifndef CGLM_USE_ANONYMOUS_STRUCT
21
+ /* If the user doesn't explicitly specify if they want anonymous structs or
22
+ * not, then we'll try to intuit an appropriate choice. */
23
+ # if defined(CGLM_NO_ANONYMOUS_STRUCT)
24
+ /* The user has defined CGLM_NO_ANONYMOUS_STRUCT. This used to be the
25
+ * only #define governing the use of anonymous structs, so for backward
26
+ * compatibility, we still honor that choice and disable them. */
27
+ # define CGLM_USE_ANONYMOUS_STRUCT 0
28
+ # elif __STDC_VERSION__ >= 20112L || defined(_MSVC_VER)
29
+ /* We're compiling for C11 or this is the MSVC compiler. In either
30
+ * case, anonymous structs are available, so use them. */
31
+ # define CGLM_USE_ANONYMOUS_STRUCT 1
32
+ # elif defined(_MSC_VER) && (_MSC_VER >= 1900) /* Visual Studio 2015 */
33
+ /* We can support anonymous structs
34
+ * since Visual Studio 2015 or 2017 (1910) maybe? */
35
+ # define CGLM_USE_ANONYMOUS_STRUCT 1
36
+ # else
37
+ /* Otherwise, we're presumably building for C99 or C89 and can't rely
38
+ * on anonymous structs being available. Turn them off. */
39
+ # define CGLM_USE_ANONYMOUS_STRUCT 0
40
+ # endif
41
+ #endif
42
+
43
+ typedef union vec2s {
44
+ vec2 raw;
45
+ #if CGLM_USE_ANONYMOUS_STRUCT
46
+ struct {
47
+ float x;
48
+ float y;
49
+ };
50
+ #endif
51
+ } vec2s;
52
+
53
+ typedef union vec3s {
54
+ vec3 raw;
55
+ #if CGLM_USE_ANONYMOUS_STRUCT
56
+ struct {
57
+ float x;
58
+ float y;
59
+ float z;
60
+ };
61
+ #endif
62
+ } vec3s;
63
+
64
+ typedef union ivec3s {
65
+ ivec3 raw;
66
+ #if CGLM_USE_ANONYMOUS_STRUCT
67
+ struct {
68
+ int x;
69
+ int y;
70
+ int z;
71
+ };
72
+ #endif
73
+ } ivec3s;
74
+
75
+ typedef union CGLM_ALIGN_IF(16) vec4s {
76
+ vec4 raw;
77
+ #if CGLM_USE_ANONYMOUS_STRUCT
78
+ struct {
79
+ float x;
80
+ float y;
81
+ float z;
82
+ float w;
83
+ };
84
+ #endif
85
+ } vec4s;
86
+
87
+ typedef union CGLM_ALIGN_IF(16) versors {
88
+ vec4 raw;
89
+ #if CGLM_USE_ANONYMOUS_STRUCT
90
+ struct {
91
+ float x;
92
+ float y;
93
+ float z;
94
+ float w;
95
+ };
96
+
97
+ struct {
98
+ vec3s imag;
99
+ float real;
100
+ };
101
+ #endif
102
+ } versors;
103
+
104
+ typedef union mat3s {
105
+ mat3 raw;
106
+ vec3s col[3];
107
+ #if CGLM_USE_ANONYMOUS_STRUCT
108
+ struct {
109
+ float m00, m01, m02;
110
+ float m10, m11, m12;
111
+ float m20, m21, m22;
112
+ };
113
+ #endif
114
+ } mat3s;
115
+
116
+ typedef union CGLM_ALIGN_MAT mat4s {
117
+ mat4 raw;
118
+ vec4s col[4];
119
+ #if CGLM_USE_ANONYMOUS_STRUCT
120
+ struct {
121
+ float m00, m01, m02, m03;
122
+ float m10, m11, m12, m13;
123
+ float m20, m21, m22, m23;
124
+ float m30, m31, m32, m33;
125
+ };
126
+ #endif
127
+ } mat4s;
128
+
129
+ #endif /* cglm_types_struct_h */
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright (c), Recep Aslantas.
3
+ *
4
+ * MIT License (MIT), http://opensource.org/licenses/MIT
5
+ * Full license can be found in the LICENSE file
6
+ */
7
+
8
+ #ifndef cglm_types_h
9
+ #define cglm_types_h
10
+
11
+ #if defined(_MSC_VER)
12
+ /* do not use alignment for older visual studio versions */
13
+ # if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */
14
+ # define CGLM_ALL_UNALIGNED
15
+ # define CGLM_ALIGN(X) /* no alignment */
16
+ # else
17
+ # define CGLM_ALIGN(X) __declspec(align(X))
18
+ # endif
19
+ #else
20
+ # define CGLM_ALIGN(X) __attribute((aligned(X)))
21
+ #endif
22
+
23
+ #ifndef CGLM_ALL_UNALIGNED
24
+ # define CGLM_ALIGN_IF(X) CGLM_ALIGN(X)
25
+ #else
26
+ # define CGLM_ALIGN_IF(X) /* no alignment */
27
+ #endif
28
+
29
+ #ifdef __AVX__
30
+ # define CGLM_ALIGN_MAT CGLM_ALIGN(32)
31
+ #else
32
+ # define CGLM_ALIGN_MAT CGLM_ALIGN(16)
33
+ #endif
34
+
35
+ typedef float vec2[2];
36
+ typedef float vec3[3];
37
+ typedef int ivec3[3];
38
+ typedef CGLM_ALIGN_IF(16) float vec4[4];
39
+ typedef vec4 versor;
40
+ typedef vec3 mat3[3];
41
+ typedef CGLM_ALIGN_MAT vec4 mat4[4];
42
+
43
+ #define GLM_E 2.71828182845904523536028747135266250 /* e */
44
+ #define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */
45
+ #define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */
46
+ #define GLM_LN2 0.693147180559945309417232121458176568 /* loge(2) */
47
+ #define GLM_LN10 2.30258509299404568401799145468436421 /* loge(10) */
48
+ #define GLM_PI 3.14159265358979323846264338327950288 /* pi */
49
+ #define GLM_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
50
+ #define GLM_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
51
+ #define GLM_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
52
+ #define GLM_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
53
+ #define GLM_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */
54
+ #define GLM_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */
55
+ #define GLM_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */
56
+
57
+ #define GLM_Ef ((float)GLM_E)
58
+ #define GLM_LOG2Ef ((float)GLM_LOG2E)
59
+ #define GLM_LOG10Ef ((float)GLM_LOG10E)
60
+ #define GLM_LN2f ((float)GLM_LN2)
61
+ #define GLM_LN10f ((float)GLM_LN10)
62
+ #define GLM_PIf ((float)GLM_PI)
63
+ #define GLM_PI_2f ((float)GLM_PI_2)
64
+ #define GLM_PI_4f ((float)GLM_PI_4)
65
+ #define GLM_1_PIf ((float)GLM_1_PI)
66
+ #define GLM_2_PIf ((float)GLM_2_PI)
67
+ #define GLM_2_SQRTPIf ((float)GLM_2_SQRTPI)
68
+ #define GLM_SQRT2f ((float)GLM_SQRT2)
69
+ #define GLM_SQRT1_2f ((float)GLM_SQRT1_2)
70
+
71
+ /* DEPRECATED! use GLM_PI and friends */
72
+ #define CGLM_PI GLM_PIf
73
+ #define CGLM_PI_2 GLM_PI_2f
74
+ #define CGLM_PI_4 GLM_PI_4f
75
+
76
+ #endif /* cglm_types_h */
@@ -0,0 +1,328 @@
1
+ /*
2
+ * Copyright (c), Recep Aslantas.
3
+ *
4
+ * MIT License (MIT), http://opensource.org/licenses/MIT
5
+ * Full license can be found in the LICENSE file
6
+ */
7
+
8
+ /*
9
+ Functions:
10
+ CGLM_INLINE int glm_sign(int val);
11
+ CGLM_INLINE float glm_signf(float val);
12
+ CGLM_INLINE float glm_rad(float deg);
13
+ CGLM_INLINE float glm_deg(float rad);
14
+ CGLM_INLINE void glm_make_rad(float *deg);
15
+ CGLM_INLINE void glm_make_deg(float *rad);
16
+ CGLM_INLINE float glm_pow2(float x);
17
+ CGLM_INLINE float glm_min(float a, float b);
18
+ CGLM_INLINE float glm_max(float a, float b);
19
+ CGLM_INLINE float glm_clamp(float val, float minVal, float maxVal);
20
+ CGLM_INLINE float glm_clamp_zo(float val, float minVal, float maxVal);
21
+ CGLM_INLINE float glm_lerp(float from, float to, float t);
22
+ CGLM_INLINE float glm_lerpc(float from, float to, float t);
23
+ CGLM_INLINE float glm_step(float edge, float x);
24
+ CGLM_INLINE float glm_smooth(float t);
25
+ CGLM_INLINE float glm_smoothstep(float edge0, float edge1, float x);
26
+ CGLM_INLINE float glm_smoothinterp(float from, float to, float t);
27
+ CGLM_INLINE float glm_smoothinterpc(float from, float to, float t);
28
+ CGLM_INLINE bool glm_eq(float a, float b);
29
+ CGLM_INLINE float glm_percent(float from, float to, float current);
30
+ CGLM_INLINE float glm_percentc(float from, float to, float current);
31
+ */
32
+
33
+ #ifndef cglm_util_h
34
+ #define cglm_util_h
35
+
36
+ #include "common.h"
37
+
38
+ #define GLM_MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
39
+ #define GLM_MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
40
+
41
+ /*!
42
+ * @brief get sign of 32 bit integer as +1, -1, 0
43
+ *
44
+ * Important: It returns 0 for zero input
45
+ *
46
+ * @param val integer value
47
+ */
48
+ CGLM_INLINE
49
+ int
50
+ glm_sign(int val) {
51
+ return ((val >> 31) - (-val >> 31));
52
+ }
53
+
54
+ /*!
55
+ * @brief get sign of 32 bit float as +1, -1, 0
56
+ *
57
+ * Important: It returns 0 for zero/NaN input
58
+ *
59
+ * @param val float value
60
+ */
61
+ CGLM_INLINE
62
+ float
63
+ glm_signf(float val) {
64
+ return (float)((val > 0.0f) - (val < 0.0f));
65
+ }
66
+
67
+ /*!
68
+ * @brief convert degree to radians
69
+ *
70
+ * @param[in] deg angle in degrees
71
+ */
72
+ CGLM_INLINE
73
+ float
74
+ glm_rad(float deg) {
75
+ return deg * GLM_PIf / 180.0f;
76
+ }
77
+
78
+ /*!
79
+ * @brief convert radians to degree
80
+ *
81
+ * @param[in] rad angle in radians
82
+ */
83
+ CGLM_INLINE
84
+ float
85
+ glm_deg(float rad) {
86
+ return rad * 180.0f / GLM_PIf;
87
+ }
88
+
89
+ /*!
90
+ * @brief convert exsisting degree to radians. this will override degrees value
91
+ *
92
+ * @param[in, out] deg pointer to angle in degrees
93
+ */
94
+ CGLM_INLINE
95
+ void
96
+ glm_make_rad(float *deg) {
97
+ *deg = *deg * GLM_PIf / 180.0f;
98
+ }
99
+
100
+ /*!
101
+ * @brief convert exsisting radians to degree. this will override radians value
102
+ *
103
+ * @param[in, out] rad pointer to angle in radians
104
+ */
105
+ CGLM_INLINE
106
+ void
107
+ glm_make_deg(float *rad) {
108
+ *rad = *rad * 180.0f / GLM_PIf;
109
+ }
110
+
111
+ /*!
112
+ * @brief multiplies given parameter with itself = x * x or powf(x, 2)
113
+ *
114
+ * @param[in] x x
115
+ */
116
+ CGLM_INLINE
117
+ float
118
+ glm_pow2(float x) {
119
+ return x * x;
120
+ }
121
+
122
+ /*!
123
+ * @brief find minimum of given two values
124
+ *
125
+ * @param[in] a number 1
126
+ * @param[in] b number 2
127
+ */
128
+ CGLM_INLINE
129
+ float
130
+ glm_min(float a, float b) {
131
+ if (a < b)
132
+ return a;
133
+ return b;
134
+ }
135
+
136
+ /*!
137
+ * @brief find maximum of given two values
138
+ *
139
+ * @param[in] a number 1
140
+ * @param[in] b number 2
141
+ */
142
+ CGLM_INLINE
143
+ float
144
+ glm_max(float a, float b) {
145
+ if (a > b)
146
+ return a;
147
+ return b;
148
+ }
149
+
150
+ /*!
151
+ * @brief clamp a number between min and max
152
+ *
153
+ * @param[in] val value to clamp
154
+ * @param[in] minVal minimum value
155
+ * @param[in] maxVal maximum value
156
+ */
157
+ CGLM_INLINE
158
+ float
159
+ glm_clamp(float val, float minVal, float maxVal) {
160
+ return glm_min(glm_max(val, minVal), maxVal);
161
+ }
162
+
163
+ /*!
164
+ * @brief clamp a number to zero and one
165
+ *
166
+ * @param[in] val value to clamp
167
+ */
168
+ CGLM_INLINE
169
+ float
170
+ glm_clamp_zo(float val) {
171
+ return glm_clamp(val, 0.0f, 1.0f);
172
+ }
173
+
174
+ /*!
175
+ * @brief linear interpolation between two numbers
176
+ *
177
+ * formula: from + t * (to - from)
178
+ *
179
+ * @param[in] from from value
180
+ * @param[in] to to value
181
+ * @param[in] t interpolant (amount)
182
+ */
183
+ CGLM_INLINE
184
+ float
185
+ glm_lerp(float from, float to, float t) {
186
+ return from + t * (to - from);
187
+ }
188
+
189
+ /*!
190
+ * @brief clamped linear interpolation between two numbers
191
+ *
192
+ * formula: from + t * (to - from)
193
+ *
194
+ * @param[in] from from value
195
+ * @param[in] to to value
196
+ * @param[in] t interpolant (amount) clamped between 0 and 1
197
+ */
198
+ CGLM_INLINE
199
+ float
200
+ glm_lerpc(float from, float to, float t) {
201
+ return glm_lerp(from, to, glm_clamp_zo(t));
202
+ }
203
+
204
+ /*!
205
+ * @brief threshold function
206
+ *
207
+ * @param[in] edge threshold
208
+ * @param[in] x value to test against threshold
209
+ * @return returns 0.0 if x < edge, else 1.0
210
+ */
211
+ CGLM_INLINE
212
+ float
213
+ glm_step(float edge, float x) {
214
+ /* branching - no type conversion */
215
+ return (x < edge) ? 0.0f : 1.0f;
216
+ /*
217
+ * An alternative implementation without branching
218
+ * but with type conversion could be:
219
+ * return !(x < edge);
220
+ */
221
+ }
222
+
223
+ /*!
224
+ * @brief smooth Hermite interpolation
225
+ *
226
+ * formula: t^2 * (3-2t)
227
+ *
228
+ * @param[in] t interpolant (amount)
229
+ */
230
+ CGLM_INLINE
231
+ float
232
+ glm_smooth(float t) {
233
+ return t * t * (3.0f - 2.0f * t);
234
+ }
235
+
236
+ /*!
237
+ * @brief threshold function with a smooth transition (according to OpenCL specs)
238
+ *
239
+ * formula: t^2 * (3-2t)
240
+ *
241
+ * @param[in] edge0 low threshold
242
+ * @param[in] edge1 high threshold
243
+ * @param[in] x interpolant (amount)
244
+ */
245
+ CGLM_INLINE
246
+ float
247
+ glm_smoothstep(float edge0, float edge1, float x) {
248
+ float t;
249
+ t = glm_clamp_zo((x - edge0) / (edge1 - edge0));
250
+ return glm_smooth(t);
251
+ }
252
+
253
+ /*!
254
+ * @brief smoothstep interpolation between two numbers
255
+ *
256
+ * formula: from + smoothstep(t) * (to - from)
257
+ *
258
+ * @param[in] from from value
259
+ * @param[in] to to value
260
+ * @param[in] t interpolant (amount)
261
+ */
262
+ CGLM_INLINE
263
+ float
264
+ glm_smoothinterp(float from, float to, float t) {
265
+ return from + glm_smooth(t) * (to - from);
266
+ }
267
+
268
+ /*!
269
+ * @brief clamped smoothstep interpolation between two numbers
270
+ *
271
+ * formula: from + smoothstep(t) * (to - from)
272
+ *
273
+ * @param[in] from from value
274
+ * @param[in] to to value
275
+ * @param[in] t interpolant (amount) clamped between 0 and 1
276
+ */
277
+ CGLM_INLINE
278
+ float
279
+ glm_smoothinterpc(float from, float to, float t) {
280
+ return glm_smoothinterp(from, to, glm_clamp_zo(t));
281
+ }
282
+
283
+ /*!
284
+ * @brief check if two float equal with using EPSILON
285
+ *
286
+ * @param[in] a a
287
+ * @param[in] b b
288
+ */
289
+ CGLM_INLINE
290
+ bool
291
+ glm_eq(float a, float b) {
292
+ return fabsf(a - b) <= FLT_EPSILON;
293
+ }
294
+
295
+ /*!
296
+ * @brief percentage of current value between start and end value
297
+ *
298
+ * maybe fraction could be alternative name.
299
+ *
300
+ * @param[in] from from value
301
+ * @param[in] to to value
302
+ * @param[in] current current value
303
+ */
304
+ CGLM_INLINE
305
+ float
306
+ glm_percent(float from, float to, float current) {
307
+ float t;
308
+
309
+ if ((t = to - from) == 0.0f)
310
+ return 1.0f;
311
+
312
+ return (current - from) / t;
313
+ }
314
+
315
+ /*!
316
+ * @brief clamped percentage of current value between start and end value
317
+ *
318
+ * @param[in] from from value
319
+ * @param[in] to to value
320
+ * @param[in] current current value
321
+ */
322
+ CGLM_INLINE
323
+ float
324
+ glm_percentc(float from, float to, float current) {
325
+ return glm_clamp(glm_percent(from, to, current), 0.0f, 1.0f);
326
+ }
327
+
328
+ #endif /* cglm_util_h */