diff options
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | include/math/vec2.h | 3 | ||||
| -rw-r--r-- | include/math/vec3.h | 14 | ||||
| -rw-r--r-- | include/math/vec4.h | 4 |
4 files changed, 10 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 916dbfa..cf50661 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.0) | 1 | cmake_minimum_required(VERSION 3.5) |
| 2 | 2 | ||
| 3 | project(math) | 3 | project(math) |
| 4 | 4 | ||
diff --git a/include/math/vec2.h b/include/math/vec2.h index 5a56a94..7898edf 100644 --- a/include/math/vec2.h +++ b/include/math/vec2.h | |||
| @@ -91,8 +91,7 @@ static inline R vec2_dist(vec2 a, vec2 b) { return sqrt(vec2_dist2(a, b)); } | |||
| 91 | /// Return the given vector divided by its magnitude. | 91 | /// Return the given vector divided by its magnitude. |
| 92 | static inline vec2 vec2_normalize(vec2 v) { | 92 | static inline vec2 vec2_normalize(vec2 v) { |
| 93 | const R n = vec2_norm(v); | 93 | const R n = vec2_norm(v); |
| 94 | assert(n > 0); | 94 | return (n > 0) ? (vec2){v.x / n, v.y / n} : (vec2){0, 0}; |
| 95 | return (vec2){v.x / n, v.y / n}; | ||
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | /// Return the dot product of two vectors. | 97 | /// Return the dot product of two vectors. |
diff --git a/include/math/vec3.h b/include/math/vec3.h index ee6d460..bb53cfb 100644 --- a/include/math/vec3.h +++ b/include/math/vec3.h | |||
| @@ -99,8 +99,7 @@ static inline R vec3_dist(vec3 a, vec3 b) { return sqrt(vec3_dist2(a, b)); } | |||
| 99 | /// Return the given vector divided by its magnitude. | 99 | /// Return the given vector divided by its magnitude. |
| 100 | static inline vec3 vec3_normalize(vec3 v) { | 100 | static inline vec3 vec3_normalize(vec3 v) { |
| 101 | const R n = vec3_norm(v); | 101 | const R n = vec3_norm(v); |
| 102 | assert(n > 0); | 102 | return (n > 0) ? (vec3){v.x / n, v.y / n, v.z / n} : (vec3){0, 0, 0}; |
| 103 | return (vec3){v.x / n, v.y / n, v.z / n}; | ||
| 104 | } | 103 | } |
| 105 | 104 | ||
| 106 | /// Return the dot product of two vectors. | 105 | /// Return the dot product of two vectors. |
| @@ -110,8 +109,8 @@ static inline R vec3_dot(vec3 a, vec3 b) { | |||
| 110 | 109 | ||
| 111 | /// Return the cross product of two vectors. | 110 | /// Return the cross product of two vectors. |
| 112 | static inline vec3 vec3_cross(vec3 a, vec3 b) { | 111 | static inline vec3 vec3_cross(vec3 a, vec3 b) { |
| 113 | return (vec3){ | 112 | return (vec3){a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, |
| 114 | a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; | 113 | a.x * b.y - a.y * b.x}; |
| 115 | } | 114 | } |
| 116 | 115 | ||
| 117 | /// Reflect the vector about the normal. | 116 | /// Reflect the vector about the normal. |
| @@ -137,10 +136,9 @@ static inline vec3 vec3_pow(vec3 v, R p) { | |||
| 137 | 136 | ||
| 138 | /// Linearly interpolate two vectors. | 137 | /// Linearly interpolate two vectors. |
| 139 | static inline vec3 vec3_lerp(vec3 a, vec3 b, R t) { | 138 | static inline vec3 vec3_lerp(vec3 a, vec3 b, R t) { |
| 140 | return (vec3){ | 139 | return (vec3){.x = a.x + t * (b.x - a.x), |
| 141 | .x = a.x + t * (b.x - a.x), | 140 | .y = a.y + t * (b.y - a.y), |
| 142 | .y = a.y + t * (b.y - a.y), | 141 | .z = a.z + t * (b.z - a.z)}; |
| 143 | .z = a.z + t * (b.z - a.z)}; | ||
| 144 | } | 142 | } |
| 145 | 143 | ||
| 146 | /// Interpolate two unit vectors using spherical linear interpolation. | 144 | /// Interpolate two unit vectors using spherical linear interpolation. |
diff --git a/include/math/vec4.h b/include/math/vec4.h index 5a797f6..0e29807 100644 --- a/include/math/vec4.h +++ b/include/math/vec4.h | |||
| @@ -91,8 +91,8 @@ static inline R vec4_dist(vec4 a, vec4 b) { return sqrt(vec4_dist2(a, b)); } | |||
| 91 | /// Return the given vector divided by its magnitude. | 91 | /// Return the given vector divided by its magnitude. |
| 92 | static inline vec4 vec4_normalize(vec4 v) { | 92 | static inline vec4 vec4_normalize(vec4 v) { |
| 93 | const R n = vec4_norm(v); | 93 | const R n = vec4_norm(v); |
| 94 | assert(n > 0); | 94 | return (n > 0) ? (vec4){v.x / n, v.y / n, v.z / n, v.w / n} |
| 95 | return (vec4){v.x / n, v.y / n, v.z / n, v.w / n}; | 95 | : (vec4){0, 0, 0, 0}; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | /// Return the dot product of two vectors. | 98 | /// Return the dot product of two vectors. |
