From ec9af8478919c08988de0c88021a8f6a4e545a1b Mon Sep 17 00:00:00 2001 From: Borealis Date: Fri, 20 Dec 2024 19:08:38 +0000 Subject: [PATCH] Auto-update from libvoxelstorm: latest vectorstorm improvements from Armchair Engine: switchable sqrt modes and removing older deprecated functions and aliases (6c2fde6) --- vectorstorm/aabb/aabb2.h | 3 - vectorstorm/aabb/aabb2_types.h | 8 -- vectorstorm/aabb/aabb3.h | 3 - vectorstorm/aabb/aabb3_types.h | 8 -- vectorstorm/matrix/matrix3.h | 43 --------- vectorstorm/matrix/matrix3_types.h | 8 -- vectorstorm/matrix/matrix4.h | 56 ------------ vectorstorm/matrix/matrix4_types.h | 8 -- vectorstorm/quat/quat.h | 135 +++++++++++++---------------- vectorstorm/quat/quat_types.h | 9 -- vectorstorm/sqrt_fast.h | 34 ++++---- vectorstorm/vector/vector2.h | 129 +++++++++++---------------- vectorstorm/vector/vector2_types.h | 8 -- vectorstorm/vector/vector3.h | 124 ++++++++++++-------------- vectorstorm/vector/vector3_types.h | 8 -- vectorstorm/vector/vector4.h | 120 ++++++++++++------------- vectorstorm/vector/vector4_types.h | 8 -- 17 files changed, 238 insertions(+), 474 deletions(-) diff --git a/vectorstorm/aabb/aabb2.h b/vectorstorm/aabb/aabb2.h index e84259a..c00d637 100644 --- a/vectorstorm/aabb/aabb2.h +++ b/vectorstorm/aabb/aabb2.h @@ -280,9 +280,6 @@ class aabb2 { inline constexpr vector2 centre() const noexcept __attribute__((__always_inline__)) { return (min + max) / static_cast(2); } - inline vector2 constexpr center() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return centre(); - } /** * Gets extent of bounding-box. diff --git a/vectorstorm/aabb/aabb2_types.h b/vectorstorm/aabb/aabb2_types.h index 0d84d88..5cced8a 100644 --- a/vectorstorm/aabb/aabb2_types.h +++ b/vectorstorm/aabb/aabb2_types.h @@ -15,14 +15,6 @@ using aabb2i = aabb2; /// 2D axis-aligned bounding box of unsigned integers using aabb2ui = aabb2; -// deprecated transitional declarations -template -using Aabb2 __attribute__((deprecated("Use aabb2 instead."))) = aabb2; -using Aabb2f __attribute__((deprecated("Use aabb2 instead."))) = aabb2f; -using Aabb2d __attribute__((deprecated("Use aabb2 instead."))) = aabb2d; -using Aabb2ld __attribute__((deprecated("Use aabb2 instead."))) = aabb2ld; -using Aabb2i __attribute__((deprecated("Use aabb2 instead."))) = aabb2i; - #ifdef VECTORSTORM_NAMESPACE } #endif //VECTORSTORM_NAMESPACE diff --git a/vectorstorm/aabb/aabb3.h b/vectorstorm/aabb/aabb3.h index 1c176cd..59be4f0 100644 --- a/vectorstorm/aabb/aabb3.h +++ b/vectorstorm/aabb/aabb3.h @@ -296,9 +296,6 @@ class aabb3 { inline vector3 constexpr centre() const noexcept __attribute__((__always_inline__)) { return (min + max) / static_cast(2); } - inline vector3 constexpr center() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return centre(); - } /** * Gets extent of bounding-box. diff --git a/vectorstorm/aabb/aabb3_types.h b/vectorstorm/aabb/aabb3_types.h index 6fdd2be..e0ec457 100644 --- a/vectorstorm/aabb/aabb3_types.h +++ b/vectorstorm/aabb/aabb3_types.h @@ -15,14 +15,6 @@ using aabb3i = aabb3; /// 2D axis-aligned bounding box of unsigned integers using aabb3ui = aabb3; -// deprecated transitional declarations -template -using Aabb3 __attribute__((deprecated("Use aabb3 instead."))) = aabb3; -using Aabb3f __attribute__((deprecated("Use aabb3 instead."))) = aabb3f; -using Aabb3d __attribute__((deprecated("Use aabb3 instead."))) = aabb3d; -using Aabb3ld __attribute__((deprecated("Use aabb3 instead."))) = aabb3ld; -using Aabb3i __attribute__((deprecated("Use aabb3 instead."))) = aabb3i; - #ifdef VECTORSTORM_NAMESPACE } #endif //VECTORSTORM_NAMESPACE diff --git a/vectorstorm/matrix/matrix3.h b/vectorstorm/matrix/matrix3.h index 0e7d090..f45e9c6 100644 --- a/vectorstorm/matrix/matrix3.h +++ b/vectorstorm/matrix/matrix3.h @@ -141,12 +141,6 @@ class matrix3 { inline static matrix3 constexpr create_rotation_from_euler_angles(T xDeg, T yDeg, T zDeg) noexcept __attribute__((__always_inline__)) { return create_rotation_from_euler_angles_rad(deg2rad(xDeg), deg2rad(yDeg), deg2rad(zDeg)); } - inline static matrix3 constexpr create_rotation_around_axis(T xDeg, T yDeg, T zDeg) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_from_euler_angles()"))) { - return create_rotation_from_euler_angles(xDeg, yDeg, zDeg); - } - inline static matrix3 constexpr createRotationAroundAxis(T xDeg, T yDeg, T zDeg) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_from_euler_angles()"))) { - return create_rotation_from_euler_angles(xDeg, yDeg, zDeg); - } /** * Creates rotation matrix by rotation around three axes, radian version. @@ -183,12 +177,6 @@ class matrix3 { temp_cos_z_cos_y * sin_xRads, temp_cos_z_cos_y * cos_xRads); } - inline static matrix3 constexpr create_rotation_around_axis_rad(T xRads, T yRads, T zRads) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_from_euler_angles_rad()"))) { - return create_rotation_from_euler_angles_rad(xRads, yRads, zRads); - } - inline static matrix3 constexpr createRotationAroundAxis_rad(T xRads, T yRads, T zRads) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_from_euler_angles_rad()"))) { - return create_rotation_from_euler_angles_rad(xRads, yRads, zRads); - } /** * Creates rotation matrix by rotation around an axis. @@ -198,9 +186,6 @@ class matrix3 { inline static matrix3 constexpr create_rotation_around_axis(vector3 const &axis, T angle) noexcept __attribute__((__always_inline__)) { return create_rotation_around_axis_rad(axis, deg2rad(angle)); } - inline static matrix3 constexpr createRotationAroundAxis(vector3 const &axis, T angle) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_around_axis()"))) { - return create_rotation_around_axis(axis, angle); - } /** * Creates rotation matrix by rotation around an axis, radian version. @@ -227,9 +212,6 @@ class matrix3 { axis.y * axis.z * cos_a_inv + sin_a * axis.x, axis.z * axis.z * cos_a_inv + cos_a); } - inline static matrix3 constexpr createRotationAroundAxis_rad(vector3 const &axis, T angle) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_around_axis_rad()"))) { - return create_rotation_around_axis_rad(axis, angle); - } /** * Creates rotation matrix by aligning one vector to another. @@ -260,9 +242,6 @@ class matrix3 { cross.z * cross.z * temp_k + dot); } - inline static matrix3 constexpr createRotationBetweenVectors(vector3 const &from, vector3 const &to) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_between_vectors()"))) { - return create_rotation_between_vectors(from, to); - } /** * Creates a rotation matrix to align with a target vector direction @a target @@ -297,10 +276,6 @@ class matrix3 { static_cast(mat[1]), static_cast(mat[5]), static_cast(mat[9]), static_cast(mat[2]), static_cast(mat[6]), static_cast(mat[10])); } - template __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_ode()"))) - inline static matrix3 constexpr fromOde(It const *mat) noexcept { - return from_ode(mat); - } /** * Creates new matrix 3x3 from array that represents such matrix 3x3 @@ -314,10 +289,6 @@ class matrix3 { static_cast(arr[1]), static_cast(arr[4]), static_cast(arr[7]), static_cast(arr[2]), static_cast(arr[5]), static_cast(arr[8])); } - template __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_row_major_array()"))) - inline static matrix3 constexpr fromRowMajorArray(FromT const *arr) noexcept { - return from_row_major_array(arr); - } /** * Creates new matrix 3x3 from array that represents such matrix 3x3 @@ -331,10 +302,6 @@ class matrix3 { static_cast(arr[3]), static_cast(arr[4]), static_cast(arr[5]), static_cast(arr[6]), static_cast(arr[7]), static_cast(arr[8])); } - template __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_column_major_array()"))) - inline static matrix3 constexpr fromColumnMajorArray(FromT const *arr) noexcept { - return from_column_major_array(arr); - } //---------------------[ equality operators ]------------------------------ /** @@ -427,9 +394,6 @@ class matrix3 { data[6], data[7], data[8], static_cast(0), static_cast(0), static_cast(0), static_cast(0), static_cast(1)); } - inline matrix4 constexpr getTranslation() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use get_transform()"))) { - return get_transform(); - } /** * Copy operator @@ -719,10 +683,6 @@ class matrix3 { data[4] = data[8] * data[0] - data[2] * data[6]; data[5] = data[6] * data[1] - data[0] * data[7]; } - [[deprecated("Proper English, please!")]] - inline void constexpr orthonormalize() noexcept __attribute__((__always_inline__)) { - orthonormalise(); - } /** * Returns a quaternion such that its corresponding matrix can be used to diagonalise the input matrix. @@ -815,9 +775,6 @@ class matrix3 { oss << *this; return oss.str(); } - inline std::string CONSTEXPR_IF_NO_CLANG toString() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use to_string()"))) { - return to_string(); - } }; /** diff --git a/vectorstorm/matrix/matrix3_types.h b/vectorstorm/matrix/matrix3_types.h index ba5001e..b93f3c8 100644 --- a/vectorstorm/matrix/matrix3_types.h +++ b/vectorstorm/matrix/matrix3_types.h @@ -30,14 +30,6 @@ using mat3ui = matrix3ui; // Special WebGPU padded 3x3 matrix - only float is needed using mat3fwgpu = matrix3wgpu; -// deprecated transitional declarations -template -using Matrix3 __attribute__((deprecated("Use matrix3 or mat3 instead."))) = matrix3; -using Matrix3f __attribute__((deprecated("Use matrix3 or mat3 instead."))) = matrix3f; -using Matrix3d __attribute__((deprecated("Use matrix3 or mat3 instead."))) = matrix3d; -using Matrix3ld __attribute__((deprecated("Use matrix3 or mat3 instead."))) = matrix3ld; -using Matrix3i __attribute__((deprecated("Use matrix3 or mat3 instead."))) = matrix3i; - #ifdef VECTORSTORM_NAMESPACE } #endif //VECTORSTORM_NAMESPACE diff --git a/vectorstorm/matrix/matrix4.h b/vectorstorm/matrix/matrix4.h index 43e771b..86bdd8b 100644 --- a/vectorstorm/matrix/matrix4.h +++ b/vectorstorm/matrix/matrix4.h @@ -194,12 +194,6 @@ class matrix4 { inline static matrix4 constexpr create_rotation_from_euler_angles(T xDeg, T yDeg, T zDeg) noexcept __attribute__((__always_inline__)) { return create_rotation_from_euler_angles_rad(deg2rad(xDeg), deg2rad(yDeg), deg2rad(zDeg)); } - inline static matrix4 constexpr create_rotation_around_axis(T xDeg, T yDeg, T zDeg) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_from_euler_angles()"))) { - return create_rotation_from_euler_angles(xDeg, yDeg, zDeg); - } - inline static matrix4 constexpr createRotationAroundAxis(T xDeg, T yDeg, T zDeg) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_from_euler_angles()"))) { - return create_rotation_from_euler_angles(xDeg, yDeg, zDeg); - } /** * Creates rotation matrix by rotation around three axes, radian version. @@ -210,12 +204,6 @@ class matrix4 { inline static matrix4 constexpr create_rotation_from_euler_angles_rad(T xRads, T yRads, T zRads) noexcept __attribute__((__always_inline__)) { return matrix3::create_rotation_from_euler_angles_rad(xRads, yRads, zRads).get_transform(); } - inline static matrix4 constexpr create_rotation_around_axis_rad(T xRads, T yRads, T zRads) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_from_euler_angles_rad()"))) { - return create_rotation_from_euler_angles_rad(xRads, yRads, zRads); - } - inline static matrix4 constexpr createRotationAroundAxis_rad(T xRads, T yRads, T zRads) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_from_euler_angles_rad()"))) { - return create_rotation_from_euler_angles_rad(xRads, yRads, zRads); - } /** * Creates rotation matrix by rotation around an axis. @@ -225,9 +213,6 @@ class matrix4 { inline static matrix4 constexpr create_rotation_around_axis(vector3 const &axis, T angle) noexcept __attribute__((__always_inline__)) { return create_rotation_around_axis_rad(axis, deg2rad(angle)); } - inline static matrix4 constexpr createRotationAroundAxis(vector3 const &axis, T angle) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_around_axis()"))) { - return create_rotation_around_axis(axis, angle); - } /** * Creates rotation matrix by rotation around an axis, radian version. @@ -237,9 +222,6 @@ class matrix4 { inline static matrix4 constexpr create_rotation_around_axis_rad(vector3 const &axis, T angle) noexcept __attribute__((__always_inline__)) { return matrix3::create_rotation_around_axis_rad(axis, angle).get_transform(); } - inline static matrix4 constexpr createRotationAroundAxis_rad(vector3 const &axis, T angle) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_rotation_around_axis_rad()"))) { - return create_rotation_around_axis_rad(axis, angle); - } /// Creates translation matrix /** @@ -255,9 +237,6 @@ class matrix4 { static_cast(0), static_cast(0), static_cast(1), static_cast(0), x, y, z, w); } - inline static matrix4 constexpr createTranslation(T x, T y, T z, T w = 1) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_translation()"))) { - return create_translation(x, y, z, w); - } /** * Creates translation matrix from a vector3 @@ -291,9 +270,6 @@ class matrix4 { static_cast(0), static_cast(0), sz, static_cast(0), static_cast(0), static_cast(0), static_cast(0), static_cast(1)); } - inline static matrix4 constexpr createScale(T sx, T sy, T sz) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_scale()"))) { - return create_scale(sx, sy, sz); - } /** * Creates rotation matrix by aligning one vector to another. @@ -347,9 +323,6 @@ class matrix4 { static_cast(0), static_cast(1)) * matrix4::create_translation(-eye_pos.x, -eye_pos.y, -eye_pos.z); } - inline static matrix4 constexpr createLookAt(vector3 const &eye_pos, vector3 const ¢re_pos, vector3 const &up_dir) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_look_at()"))) { - return create_look_at(eye_pos, centre_pos, up_dir); - } /** * Creates OpenGL compatible perspective projection according to specified frustum parameters. @@ -401,9 +374,6 @@ class matrix4 { (static_cast(-2) * far_plane * near_plane) / (far_plane - near_plane), static_cast(0)); } - inline static matrix4 constexpr createFrustum(T left, T right, T bottom, T top, T near_plane, T far_plane) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_frustum()"))) { - return create_frustum(left, right, bottom, top, near_plane, far_plane); - } /** * Creates OpenGL compatible orthographic projection matrix. @@ -452,9 +422,6 @@ class matrix4 { -(far_plane + near_plane) / (far_plane - near_plane), static_cast(1)); } - inline static matrix4 constexpr createOrtho(T left, T right, T bottom, T top, T near_plane, T far_plane) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use create_ortho()"))) { - return create_ortho(left, right, bottom, top, near_plane, far_plane); - } /** * Creates new matrix 4x4 from array that represents such matrix 4x4 @@ -469,10 +436,6 @@ class matrix4 { static_cast(arr[2]), static_cast(arr[6]), static_cast(arr[10]), static_cast(arr[14]), static_cast(arr[3]), static_cast(arr[7]), static_cast(arr[11]), static_cast(arr[15])); } - template __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_row_major_array()"))) - inline static matrix4 constexpr fromRowMajorArray(FromT const *arr) noexcept { - return from_row_major_array(arr); - } /** * Creates new matrix 4x4 from array that represents such matrix 4x4 @@ -487,10 +450,6 @@ class matrix4 { static_cast(arr[ 8]), static_cast(arr[ 9]), static_cast(arr[10]), static_cast(arr[11]), static_cast(arr[12]), static_cast(arr[13]), static_cast(arr[14]), static_cast(arr[15])); } - template __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_column_major_array()"))) - inline static matrix4 constexpr fromColumnMajorArray(FromT const *arr) noexcept { - return from_column_major_array(arr); - } /** * Creates new matrix 4x4 from array that represents such matrix 3x4 @@ -613,9 +572,6 @@ class matrix4 { data[14] = v.z; data[15] = 1; } - inline void constexpr setTranslation(vector3 const &v) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use set_translation()"))) { - set_translation(v); - } /** * Returns translation part of matrix. @@ -623,9 +579,6 @@ class matrix4 { inline vector3 constexpr get_translation() const noexcept __attribute__((__always_inline__)) { return vector3(data[12], data[13], data[14]); } - inline vector3 constexpr getTranslation() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use get_translation()"))) { - return get_translation(); - } /** * Sets rotation part (matrix 3x3) of matrix. @@ -643,9 +596,6 @@ class matrix4 { data[ 9] = m.data[7]; data[10] = m.data[8]; } - inline void constexpr setRotation(matrix3 const &m) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use set_rotation()"))) { - set_rotation(m); - } /** * Returns rotation (matrix 3x3) part of matrix. @@ -655,9 +605,6 @@ class matrix4 { data[ 4], data[ 5], data[ 6], data[ 8], data[ 9], data[10]); } - inline matrix3 constexpr getRotation() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use get_rotation()"))) { - return get_rotation(); - } /** * Sets scale part of matrix. @@ -1058,9 +1005,6 @@ class matrix4 { oss << *this; return oss.str(); } - inline std::string CONSTEXPR_IF_NO_CLANG toString() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use to_string()"))) { - return to_string(); - } }; #ifdef VECTORSTORM_NAMESPACE diff --git a/vectorstorm/matrix/matrix4_types.h b/vectorstorm/matrix/matrix4_types.h index f02c263..8b4d83d 100644 --- a/vectorstorm/matrix/matrix4_types.h +++ b/vectorstorm/matrix/matrix4_types.h @@ -27,14 +27,6 @@ using mat4ld = matrix4ld; using mat4i = matrix4i; using mat4ui = matrix4ui; -// deprecated transitional declarations -template -using Matrix4 __attribute__((deprecated("Use matrix4 or mat4 instead."))) = matrix4; -using Matrix4f __attribute__((deprecated("Use matrix4 or mat4 instead."))) = matrix4f; -using Matrix4d __attribute__((deprecated("Use matrix4 or mat4 instead."))) = matrix4d; -using Matrix4ld __attribute__((deprecated("Use matrix4 or mat4 instead."))) = matrix4ld; -using Matrix4i __attribute__((deprecated("Use matrix4 or mat4 instead."))) = matrix4i; - #ifdef VECTORSTORM_NAMESPACE } #endif //VECTORSTORM_NAMESPACE diff --git a/vectorstorm/quat/quat.h b/vectorstorm/quat/quat.h index 972d1f3..c1a84a2 100644 --- a/vectorstorm/quat/quat.h +++ b/vectorstorm/quat/quat.h @@ -50,6 +50,25 @@ class quaternion { vector3 vector; }; + /** + * What square root mode to use, passed as a template parameter to functions like length() + */ + enum class sqrt_mode { + /** + * Use standard library std::sqrt + */ + std, + /** + * Use fast approximation from sqrt_fast.h + */ + fast, + /** + * Use rough version of fast approximation from sqrt_fast.h, with one step instead of two + */ + coarse, + }; + + /** * quaternion constructor, sets quaternion to (0 + 0i + 0j + 0k). */ @@ -387,89 +406,76 @@ class quaternion { return quaternion(w, -v); } + /** + * Return square of length. + * @return length ^ 2 + * @note This method is faster then length(). For comparison + * of length of two quaternion can be used just this value, instead + * of more expensive length() method. + */ + inline T constexpr length_sq() const noexcept __attribute__((__always_inline__)) { + return w * w + v.length_sq(); + } + /** * Get length of quaternion. * @return Length of quaternion. */ + template inline T constexpr length() const noexcept __attribute__((__always_inline__)) { - return static_cast(std::sqrt(length_sq())); + if constexpr(mode == sqrt_mode::std) { + return std::sqrt(length_sq()); + } else if constexpr(mode == sqrt_mode::fast) { + return sqrt_fast(length_sq()); + } else if constexpr(mode == sqrt_mode::coarse) { + return sqrt_coarse(length_sq()); + } else { + static_assert(always_false_v, "Unsupported sqrt_mode"); + } } /** * Get length of quaternion, fast approximation. * @return Length of quaternion. */ + [[deprecated("Use length::sqrt_mode::fast>()")]] inline T constexpr length_fast() const noexcept __attribute__((__always_inline__)) { - return static_cast(sqrt_fast(length_sq())); + return length(); } /** * Get length of quaternion, rougher fast approximation. * @return Length of quaternion. */ + [[deprecated("Use length::sqrt_mode::coarse>()")]] inline T constexpr length_faster() const noexcept __attribute__((__always_inline__)) { - return static_cast(sqrt_faster(length_sq())); - } - - /** - * Return square of length. - * @return length ^ 2 - * @note This method is faster then length(). For comparison - * of length of two quaternion can be used just this value, instead - * of more expensive length() method. - */ - inline T constexpr length_sq() const noexcept __attribute__((__always_inline__)) { - return w * w + v.length_sq(); - } - inline T constexpr lengthSq() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use length_sq()"))) { - return length_sq(); + return length(); } /** * normalise quaternion */ + template inline void constexpr normalise() noexcept __attribute__((__always_inline__)) { - T const len = length(); - w /= len; - v /= len; + *this /= length(); } + [[deprecated("Use normalise::sqrt_mode::fast>()")]] inline void constexpr normalise_fast() noexcept __attribute__((__always_inline__)) { - T const len = length_fast(); - w /= len; - v /= len; + normalise(); } + [[deprecated("Use normalise::sqrt_mode::coarse>()")]] inline void constexpr normalise_faster() noexcept __attribute__((__always_inline__)) { - T const len = length_faster(); - w /= len; - v /= len; - } - inline void constexpr normalize() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise(); - } - inline void constexpr normalize_fast() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise_fast(); - } - inline void constexpr normalize_faster() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise_faster(); + normalise(); } + template inline quaternion constexpr normalise_copy() const noexcept __attribute__((__always_inline__)) { - T const len(length()); - return {w / len, v / len}; + return *this / length(); } + [[deprecated("Use normalise_copy::sqrt_mode::fast>()")]] inline quaternion constexpr normalise_copy_fast() const noexcept __attribute__((__always_inline__)) { - T const len(length_fast()); - return {w / len, v / len}; + return normalise_copy(); } + [[deprecated("Use normalise_copy::sqrt_mode::coarse>()")]] inline quaternion constexpr normalise_copy_faster() const noexcept __attribute__((__always_inline__)) { - T const len(length_faster()); - return {w / len, v / len}; - } - inline quaternion constexpr normalize_copy() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy(); - } - inline quaternion constexpr normalize_copy_fast() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy_fast(); - } - inline quaternion constexpr normalize_copy_faster() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy_faster(); + return normalise_copy(); } inline void constexpr conjugate() noexcept __attribute__((__always_inline__)) { @@ -493,7 +499,7 @@ class quaternion { inline void constexpr invert() noexcept __attribute__((__always_inline__)) { T l = length(); conjugate(); - (*this) /= l; + *this /= l; } inline quaternion constexpr invert_copy() const noexcept __attribute__((__always_inline__)) { @@ -512,9 +518,6 @@ class quaternion { from_axis_rot(vector3(0, 1, 0), y) * from_axis_rot(vector3(0, 0, 1), z)); } - inline static quaternion constexpr fromEulerAngles(T x, T y, T z) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_euler_angles()"))) { - return from_euler_angles(x, y, z); - } /** * Creates quaternion for Euler angles, rad version. @@ -528,9 +531,6 @@ class quaternion { from_axis_rot_rad(vector3(0, 1, 0), y) * from_axis_rot_rad(vector3(0, 0, 1), z)); } - inline static quaternion constexpr fromEulerAngles_rad(T x, T y, T z) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_euler_angles_rad()"))) { - return from_euler_angles_rad(x, y, z); - } /** * Creates quaternion as rotation around axis. @@ -540,9 +540,6 @@ class quaternion { inline static quaternion constexpr from_axis_rot(vector3 const &axis, T angleDeg) noexcept __attribute__((__always_inline__)) { return from_axis_rot_rad(axis, deg2rad(angleDeg)); } - inline static quaternion constexpr fromAxisRot(vector3 const &axis, T angleDeg) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_axis_rot()"))) { - return from_axis_rot(axis, angleDeg); - } /** * Creates quaternion as rotation around axis, rad version. @@ -555,9 +552,6 @@ class quaternion { sincos_any(angleRad / static_cast(2.0), temp_sin, temp_cos); return quaternion(temp_cos, axis * temp_sin); } - inline static quaternion constexpr fromAxisRot_rad(vector3 const &axis, T angleRad) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_axis_rot_rad()"))) { - return from_axis_rot_rad(axis, angleRad); - } /** * Converts this quaternion to an axis and angle combination @@ -574,9 +568,6 @@ class quaternion { axis.assign(static_cast(1), static_cast(0), static_cast(0)); } } - inline void constexpr toAngleAxis(T &angle, vector3 &axis) const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use to_angle_axis()"))) { - to_angle_axis(angle, axis); - } /** * Converts quaternion into rotation matrix. @@ -689,9 +680,6 @@ class quaternion { oss << *this; return oss.str(); } - inline std::string CONSTEXPR_IF_NO_CLANG toString() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use to_string()"))) { - return to_string(); - } /** * Creates quaternion from transform matrix. @@ -704,9 +692,6 @@ class quaternion { inline static quaternion constexpr from_matrix(matrix4 const &m) noexcept __attribute__((__always_inline__)) { return from_matrix(m.get_rotation()); } - inline static quaternion constexpr fromMatrix(matrix4 const &m) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_matrix()"))) { - return from_matrix(m); - } */ /** @@ -748,9 +733,9 @@ class quaternion { static_cast(0.25) * s); } } - inline static quaternion constexpr fromMatrix(matrix3 const &m) noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use from_matrix()"))) { - return from_matrix(m); - } + +private: + template static constexpr bool always_false_v{false}; }; #ifdef VECTORSTORM_NAMESPACE diff --git a/vectorstorm/quat/quat_types.h b/vectorstorm/quat/quat_types.h index 4b74dd2..6769044 100644 --- a/vectorstorm/quat/quat_types.h +++ b/vectorstorm/quat/quat_types.h @@ -21,15 +21,6 @@ using quatf = quaternionf; using quatd = quaterniond; using quatld = quaternionld; -// deprecated transitional declarations -template -using Quaternion __attribute__((deprecated("Use quaternion or quat instead."))) = quaternion; -template -using Quat __attribute__((deprecated("Use quaternion or quat instead."))) = quaternion; -using Quatf __attribute__((deprecated("Use quaternion or quat instead."))) = quaternionf; -using Quatd __attribute__((deprecated("Use quaternion or quat instead."))) = quaterniond; -using Quatld __attribute__((deprecated("Use quaternion or quat instead."))) = quaternionld; - #ifdef VECTORSTORM_NAMESPACE } #endif //VECTORSTORM_NAMESPACE diff --git a/vectorstorm/sqrt_fast.h b/vectorstorm/sqrt_fast.h index 85d2d2b..8a2fceb 100644 --- a/vectorstorm/sqrt_fast.h +++ b/vectorstorm/sqrt_fast.h @@ -38,7 +38,7 @@ inline static float CONSTEXPR_IF_NO_CLANG sqrt_inv_fast(float number) noexcept { i = 0x5f375a84 - (i >> 1); // improved magic number from http://jheriko-rtw.blogspot.co.uk/2009/04/understanding-and-improving-fast.html y = *reinterpret_cast(&i); y = y * (threehalfs - (x * y * y)); // 1st iteration - y = y * (threehalfs - (x * y * y)); // 2nd iteration, this can be removed + y = y * (threehalfs - (x * y * y)); // 2nd iteration, this can be removed - see sqrt_inv_coarse below return y; } inline static double CONSTEXPR_IF_NO_CLANG sqrt_inv_fast(double number) noexcept __attribute__((__always_inline__)) OPTIMISE_NO_STRICT_ALIASING; @@ -54,7 +54,7 @@ inline static double CONSTEXPR_IF_NO_CLANG sqrt_inv_fast(double number) noexcept i = magic - (i >> 1); y = *reinterpret_cast(&i); y = y * (threehalfs - (x * y * y)); // 1st iteration - y = y * (threehalfs - (x * y * y)); // 2nd iteration, this can be removed + y = y * (threehalfs - (x * y * y)); // 2nd iteration, this can be removed - see sqrt_inv_coarse below return y; } #pragma GCC diagnostic pop @@ -80,8 +80,8 @@ inline static int constexpr sqrt_fast(int number) noexcept { #ifdef __clang__ #pragma GCC diagnostic ignored "-Wundefined-reinterpret-cast" #endif // __clang__ -inline static float CONSTEXPR_IF_NO_CLANG sqrt_inv_faster(float number) noexcept __attribute__((__always_inline__)) OPTIMISE_NO_STRICT_ALIASING; -inline static float CONSTEXPR_IF_NO_CLANG sqrt_inv_faster(float number) noexcept { +inline static float CONSTEXPR_IF_NO_CLANG sqrt_inv_coarse(float number) noexcept __attribute__((__always_inline__)) OPTIMISE_NO_STRICT_ALIASING; +inline static float CONSTEXPR_IF_NO_CLANG sqrt_inv_coarse(float number) noexcept { /// Adapted from Quake III's fast inverse square root approximation - one iteration version float constexpr threehalfs = 1.5f; @@ -92,11 +92,11 @@ inline static float CONSTEXPR_IF_NO_CLANG sqrt_inv_faster(float number) noexcept i = 0x5f375a84 - (i >> 1); // improved magic number from http://jheriko-rtw.blogspot.co.uk/2009/04/understanding-and-improving-fast.html y = *reinterpret_cast(&i); y = y * (threehalfs - (x * y * y)); // 1st iteration - //y = y * (threehalfs - (x * y * y)); // 2nd iteration, this can be removed + // 2nd iteration omitted return y; } -inline static double CONSTEXPR_IF_NO_CLANG sqrt_inv_faster(double number) noexcept __attribute__((__always_inline__)) OPTIMISE_NO_STRICT_ALIASING; -inline static double CONSTEXPR_IF_NO_CLANG sqrt_inv_faster(double number) noexcept { +inline static double CONSTEXPR_IF_NO_CLANG sqrt_inv_coarse(double number) noexcept __attribute__((__always_inline__)) OPTIMISE_NO_STRICT_ALIASING; +inline static double CONSTEXPR_IF_NO_CLANG sqrt_inv_coarse(double number) noexcept { /// Similar to the Quake III fast inverse square root but for doubles double constexpr threehalfs = 1.5; @@ -108,25 +108,25 @@ inline static double CONSTEXPR_IF_NO_CLANG sqrt_inv_faster(double number) noexce i = magic - (i >> 1); y = *reinterpret_cast(&i); y = y * (threehalfs - (x * y * y)); // 1st iteration - //y = y * (threehalfs - (x * y * y)); // 2nd iteration, this can be removed + // 2nd iteration omitted return y; } #pragma GCC diagnostic pop template -inline static T constexpr sqrt_faster(T number) noexcept __attribute__((__always_inline__)); +inline static T constexpr sqrt_coarse(T number) noexcept __attribute__((__always_inline__)); template -inline static T constexpr sqrt_faster(T number) noexcept { - return sqrt_inv_faster(number) * number; +inline static T constexpr sqrt_coarse(T number) noexcept { + return sqrt_inv_coarse(number) * number; } -inline static long double constexpr sqrt_faster(long double number) __attribute__((__always_inline__)); -inline static long double constexpr sqrt_faster(long double number) { +inline static long double constexpr sqrt_coarse(long double number) __attribute__((__always_inline__)); +inline static long double constexpr sqrt_coarse(long double number) { // we don't have a way to handle long doubles with the fast approximation, so just cast to double - return static_cast(sqrt_inv_faster(static_cast(number))) * number; + return static_cast(sqrt_inv_coarse(static_cast(number))) * number; } -inline static int constexpr sqrt_faster(int number) noexcept __attribute__((__always_inline__)); -inline static int constexpr sqrt_faster(int number) noexcept { +inline static int constexpr sqrt_coarse(int number) noexcept __attribute__((__always_inline__)); +inline static int constexpr sqrt_coarse(int number) noexcept { // convert ints to floats and back - return static_cast(sqrt_inv_faster(static_cast(number)) * static_cast(number)); + return static_cast(sqrt_inv_coarse(static_cast(number)) * static_cast(number)); } #ifdef __SSE__ diff --git a/vectorstorm/vector/vector2.h b/vectorstorm/vector/vector2.h index 05630b0..8aaa57c 100644 --- a/vectorstorm/vector/vector2.h +++ b/vectorstorm/vector/vector2.h @@ -67,6 +67,24 @@ class vector2 { T t; }; + /** + * What square root mode to use, passed as a template parameter to functions like length() + */ + enum class sqrt_mode { + /** + * Use standard library std::sqrt + */ + std, + /** + * Use fast approximation from sqrt_fast.h + */ + fast, + /** + * Use rough version of fast approximation from sqrt_fast.h, with one step instead of two + */ + coarse, + }; + //----------------[ constructors ]-------------------------- /** * Creates and sets to (0,0) @@ -354,10 +372,6 @@ class vector2 { return (x * rhs.x) + (y * rhs.y); } - [[deprecated("Use dot()")]] - inline T constexpr dotProduct(vector2 const &rhs) const noexcept __attribute__((__always_inline__)) { - return dot(rhs); - } /** * Cross product of two vectors @@ -367,10 +381,6 @@ class vector2 { return (x * rhs.y) - (y * rhs.x); } - [[deprecated("Use cross()")]] - inline T constexpr crossProduct(vector2 const &rhs) const noexcept __attribute__((__always_inline__)) { - return cross(rhs); - } //--------------[ scalar vector operator ]-------------------- /** @@ -573,31 +583,38 @@ class vector2 { inline T constexpr length_sq() const noexcept __attribute__((__always_inline__)) { return x * x + y * y; } - [[deprecated("Use length_sq()")]] - inline T constexpr lengthSq() const noexcept __attribute__((__always_inline__)) { - return length_sq(); - } /** * Get length of vector. * @return length of vector */ + template inline T constexpr length() const noexcept __attribute__((__always_inline__)) { - return static_cast(std::sqrt(length_sq())); + if constexpr(mode == sqrt_mode::std) { + return std::sqrt(length_sq()); + } else if constexpr(mode == sqrt_mode::fast) { + return sqrt_fast(length_sq()); + } else if constexpr(mode == sqrt_mode::coarse) { + return sqrt_coarse(length_sq()); + } else { + static_assert(always_false_v, "Unsupported sqrt_mode"); + } } /** * Get length of vector, fast approximation. * @return length of vector */ + [[deprecated("Use length::sqrt_mode::fast>()")]] inline T constexpr length_fast() const noexcept __attribute__((__always_inline__)) __attribute__((__pure__)) { - return static_cast(sqrt_fast(length_sq())); + return length(); } /** * Get length of vector, rougher fast approximation. * @return length of vector */ + [[deprecated("Use length::sqrt_mode::coarse>()")]] inline T constexpr length_faster() const noexcept __attribute__((__always_inline__)) __attribute__((__pure__)) { - return static_cast(sqrt_faster(length_sq())); + return length(); } /** * Return whether the vector is zero length - this is much faster than a full length calculation @@ -616,82 +633,49 @@ class vector2 { /** * normalise vector */ + template inline void constexpr normalise() noexcept __attribute__((__always_inline__)) { - T const temp = length(); - x /= temp; - y /= temp; + *this /= length(); } + [[deprecated("Use normalise::sqrt_mode::fast>()")]] inline void constexpr normalise_fast() noexcept __attribute__((__always_inline__)) { - T const temp = length_fast(); - x /= temp; - y /= temp; + normalise(); } + [[deprecated("Use normalise::sqrt_mode::coarse>()")]] inline void constexpr normalise_faster() noexcept __attribute__((__always_inline__)) { - T const temp = length_faster(); - x /= temp; - y /= temp; - } - [[deprecated("Proper English, please!")]] - inline void constexpr normalize() noexcept __attribute__((__always_inline__)) { - normalise(); - } - [[deprecated("Proper English, please!")]] - inline void constexpr normalize_fast() noexcept __attribute__((__always_inline__)) { - normalise_fast(); - } - [[deprecated("Proper English, please!")]] - inline void constexpr normalize_faster() noexcept __attribute__((__always_inline__)) { - normalise_faster(); + normalise(); } + template inline vector2 constexpr normalise_copy() const noexcept __attribute__((__always_inline__)) { - T const temp(length()); - return vector2(x / temp, y / temp); + return *this / length(); } + [[deprecated("Use normalise_copy::sqrt_mode::fast>()")]] inline vector2 constexpr normalise_copy_fast() const noexcept __attribute__((__always_inline__)) { - T const temp(length_fast()); - return vector2(x / temp, y / temp); + return normalise_copy(); } + [[deprecated("Use normalise_copy::sqrt_mode::coarse>()")]] inline vector2 constexpr normalise_copy_faster() const noexcept __attribute__((__always_inline__)) { - T const temp(length_faster()); - return vector2(x / temp, y / temp); - } - [[deprecated("Proper English, please!")]] - inline vector2 constexpr normalize_copy() const noexcept __attribute__((__always_inline__)) { - return normalise_copy(); - } - [[deprecated("Proper English, please!")]] - inline vector2 constexpr normalize_copy_fast() const noexcept __attribute__((__always_inline__)) { - return normalise_copy_fast(); - } - [[deprecated("Proper English, please!")]] - inline vector2 constexpr normalize_copy_faster() const noexcept __attribute__((__always_inline__)) { - return normalise_copy_faster(); + return normalise_copy(); } /** - * normalise vector. with added zero safety check + * normalise vector, with added zero safety check */ + template inline void constexpr normalise_safe() noexcept __attribute__((__always_inline__)) { if(length_zero()) { assign(); } else { - *this /= length(); + normalise(); } } - [[deprecated("Proper English, please!")]] - inline void constexpr normalize_safe() noexcept __attribute__((__always_inline__)) { - normalise_safe(); - } + template inline vector2 constexpr normalise_safe_copy() const noexcept __attribute__((__always_inline__)) { if(length_zero()) { - return vector2(); + return {}; } else { - return *this / length(); + return normalise_copy(); } } - [[deprecated("Proper English, please!")]] - inline vector2 constexpr normalize_safe_copy() const noexcept __attribute__((__always_inline__)) { - return normalise_safe_copy(); - } /** * Absolute vector (make all values positive) @@ -778,9 +762,6 @@ class vector2 { oss << *this; return oss.str(); } - inline std::string CONSTEXPR_IF_NO_CLANG toString() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use to_string()"))) { - return to_string(); - } /** * Check whether two lines intersect, and if so obtain the intersection point @@ -839,10 +820,6 @@ class vector2 { inline vector3 constexpr to_3d_xy() const noexcept __attribute__((__always_inline__)) { return vector3(x, y, 0); } - [[deprecated("Use lowercase version.")]] - inline vector3 constexpr to_3D_XY() const noexcept __attribute__((__always_inline__)) { - return to_3d_xy(); - } /** * Gets a 3D vector equivalent populating the X and Z axes @@ -850,10 +827,8 @@ class vector2 { inline vector3 constexpr to_3d_xz() const noexcept __attribute__((__always_inline__)) { return vector3(x, 0, z); } - [[deprecated("Use lowercase version.")]] - inline vector3 constexpr to_3D_XZ() const noexcept __attribute__((__always_inline__)) { - return to_3d_xz(); - } +private: + template static constexpr bool always_false_v{false}; }; #ifdef VECTORSTORM_NAMESPACE diff --git a/vectorstorm/vector/vector2_types.h b/vectorstorm/vector/vector2_types.h index 69c5728..de47524 100644 --- a/vectorstorm/vector/vector2_types.h +++ b/vectorstorm/vector/vector2_types.h @@ -27,14 +27,6 @@ using vec2ld = vector2ld; using vec2i = vector2i; using vec2ui = vector2ui; -// deprecated transitional declarations -template -using Vector2 __attribute__((deprecated("Use vector2 or vec2 instead."))) = vector2; -using Vector2f __attribute__((deprecated("Use vector2 or vec2 instead."))) = vector2f; -using Vector2d __attribute__((deprecated("Use vector2 or vec2 instead."))) = vector2d; -using Vector2ld __attribute__((deprecated("Use vector2 or vec2 instead."))) = vector2ld; -using Vector2i __attribute__((deprecated("Use vector2 or vec2 instead."))) = vector2i; - #ifdef VECTORSTORM_NAMESPACE } #endif //VECTORSTORM_NAMESPACE diff --git a/vectorstorm/vector/vector3.h b/vectorstorm/vector/vector3.h index ebece45..6ad2f28 100644 --- a/vectorstorm/vector/vector3.h +++ b/vectorstorm/vector/vector3.h @@ -97,6 +97,24 @@ class vector3 { T b; }; + /** + * What square root mode to use, passed as a template parameter to functions like length() + */ + enum class sqrt_mode { + /** + * Use standard library std::sqrt + */ + std, + /** + * Use fast approximation from sqrt_fast.h + */ + fast, + /** + * Use rough version of fast approximation from sqrt_fast.h, with one step instead of two + */ + coarse, + }; + //----------------[ constructors ]-------------------------- /** * Creates and sets to (0,0,0) @@ -540,9 +558,6 @@ class vector3 { (y * rhs.y) + (z * rhs.z); } - inline T constexpr dotProduct(vector3 const &rhs) const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use dot()"))) { - return dot(rhs); - } /** * Cross product of two vectors @@ -553,9 +568,6 @@ class vector3 { (z * rhs.x) - (rhs.z * x), (x * rhs.y) - (rhs.x * y)}; } - inline vector3 constexpr crossProduct(vector3 const &rhs) const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use cross()"))) { - return cross(rhs); - } //--------------[ rotation with quaternions ]----------------- // see http://mollyrocket.com/forums/viewtopic.php?t=833&sid=3a84e00a70ccb046cfc87ac39881a3d0 @@ -786,30 +798,38 @@ class vector3 { inline T constexpr length_sq() const noexcept __attribute__((__always_inline__)) { return x * x + y * y + z * z; } - inline T constexpr lengthSq() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use length_sq()"))) { - return length_sq(); - } /** * Get length of vector. * @return length of vector */ + template inline T constexpr length() const noexcept __attribute__((__always_inline__)) { - return static_cast(std::sqrt(length_sq())); + if constexpr(mode == sqrt_mode::std) { + return std::sqrt(length_sq()); + } else if constexpr(mode == sqrt_mode::fast) { + return sqrt_fast(length_sq()); + } else if constexpr(mode == sqrt_mode::coarse) { + return sqrt_coarse(length_sq()); + } else { + static_assert(always_false_v, "Unsupported sqrt_mode"); + } } /** * Get length of vector, fast approximation. * @return length of vector */ + [[deprecated("Use length::sqrt_mode::fast>()")]] inline T constexpr length_fast() const noexcept __attribute__((__always_inline__)) __attribute__((__pure__)) { - return static_cast(sqrt_fast(length_sq())); + return length(); } /** * Get length of vector, rougher fast approximation. * @return length of vector */ + [[deprecated("Use length::sqrt_mode::coarse>()")]] inline T constexpr length_faster() const noexcept __attribute__((__always_inline__)) __attribute__((__pure__)) { - return static_cast(sqrt_faster(length_sq())); + return length(); } /** * Return whether the vector is zero length - this is much faster than a full length calculation @@ -818,89 +838,59 @@ class vector3 { inline bool constexpr length_zero() const noexcept __attribute__((__always_inline__)) { /* return x == static_cast(0) && - y == static_cast(0) && - z == static_cast(0); + y == static_cast(0); */ // the above may fail to detect cases where the sqrt of three tiny numbers would be zero return std::abs(x) < epsilon && - std::abs(y) < epsilon && - std::abs(z) < epsilon; + std::abs(y) < epsilon; } /** * normalise vector */ + template inline void constexpr normalise() noexcept __attribute__((__always_inline__)) { - T const temp = length(); - x /= temp; - y /= temp; - z /= temp; + *this /= length(); } + [[deprecated("Use normalise::sqrt_mode::fast>()")]] inline void constexpr normalise_fast() noexcept __attribute__((__always_inline__)) { - T const temp = length_fast(); - x /= temp; - y /= temp; - z /= temp; + normalise(); } + [[deprecated("Use normalise::sqrt_mode::coarse>()")]] inline void constexpr normalise_faster() noexcept __attribute__((__always_inline__)) { - T const temp = length_faster(); - x /= temp; - y /= temp; - z /= temp; - } - inline void constexpr normalize() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise(); - } - inline void constexpr normalize_fast() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise_fast(); - } - inline void constexpr normalize_faster() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise_faster(); + normalise(); } + template inline vector3 constexpr normalise_copy() const noexcept __attribute__((__always_inline__)) { - T const temp(length()); - return vector3(x / temp, y / temp, z / temp); + return *this / length(); } + [[deprecated("Use normalise_copy::sqrt_mode::fast>()")]] inline vector3 constexpr normalise_copy_fast() const noexcept __attribute__((__always_inline__)) { - T const temp(length_fast()); - return vector3(x / temp, y / temp, z / temp); + return normalise_copy(); } + [[deprecated("Use normalise_copy::sqrt_mode::coarse>()")]] inline vector3 constexpr normalise_copy_faster() const noexcept __attribute__((__always_inline__)) { - T const temp(length_faster()); - return vector3(x / temp, y / temp, z / temp); - } - inline vector3 constexpr normalize_copy() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy(); - } - inline vector3 constexpr normalize_copy_fast() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy_fast(); - } - inline vector3 constexpr normalize_copy_faster() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy_faster(); + return normalise_copy(); } /** - * normalise vector. with added zero safety check + * normalise vector, with added zero safety check */ + template inline void constexpr normalise_safe() noexcept __attribute__((__always_inline__)) { if(length_zero()) { assign(); } else { - *this /= length(); + normalise(); } } - inline void constexpr normalize_safe() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise_safe(); - } + template inline vector3 constexpr normalise_safe_copy() const noexcept __attribute__((__always_inline__)) { if(length_zero()) { return {}; } else { - return *this / length(); + return normalise_copy(); } } - inline vector3 constexpr normalize_safe_copy() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_safe_copy(); - } /** * Absolute vector (make all values positive) @@ -1068,9 +1058,6 @@ class vector3 { oss << *this; return oss.str(); } - inline std::string CONSTEXPR_IF_NO_CLANG toString() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use to_string()"))) { - return to_string(); - } /** * Gets a 2D vector equivalent using the X and Y axes @@ -1078,9 +1065,6 @@ class vector3 { inline vector2 constexpr to_2d_xy() const noexcept __attribute__((__always_inline__)) { return vector2(x, y); } - inline vector2 constexpr to_2D_XY() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use lowercase version."))) { - return to_2d_xy(); - } /** * Gets a 2D vector equivalent using the X and Z axes @@ -1088,9 +1072,9 @@ class vector3 { inline vector2 constexpr to_2d_xz() const noexcept __attribute__((__always_inline__)) { return vector2(x, z); } - inline vector2 constexpr to_2D_XZ() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use lowercase version."))) { - return to_2d_xz(); - } + +private: + template static constexpr bool always_false_v{false}; }; #ifdef VECTORSTORM_NAMESPACE diff --git a/vectorstorm/vector/vector3_types.h b/vectorstorm/vector/vector3_types.h index a6bc784..fb42572 100644 --- a/vectorstorm/vector/vector3_types.h +++ b/vectorstorm/vector/vector3_types.h @@ -27,14 +27,6 @@ using vec3ld = vector3ld; using vec3i = vector3i; using vec3ui = vector3ui; -// deprecated transitional declarations -template -using Vector3 __attribute__((deprecated("Use vector3 or vec3 instead."))) = vector3; -using Vector3f __attribute__((deprecated("Use vector3 or vec3 instead."))) = vector3f; -using Vector3d __attribute__((deprecated("Use vector3 or vec3 instead."))) = vector3d; -using Vector3ld __attribute__((deprecated("Use vector3 or vec3 instead."))) = vector3ld; -using Vector3i __attribute__((deprecated("Use vector3 or vec3 instead."))) = vector3i; - #ifdef VECTORSTORM_NAMESPACE } #endif //VECTORSTORM_NAMESPACE diff --git a/vectorstorm/vector/vector4.h b/vectorstorm/vector/vector4.h index 6646741..22b2751 100644 --- a/vectorstorm/vector/vector4.h +++ b/vectorstorm/vector/vector4.h @@ -90,6 +90,24 @@ class vector4 { T w; }; + /** + * What square root mode to use, passed as a template parameter to functions like length() + */ + enum class sqrt_mode { + /** + * Use standard library std::sqrt + */ + std, + /** + * Use fast approximation from sqrt_fast.h + */ + fast, + /** + * Use rough version of fast approximation from sqrt_fast.h, with one step instead of two + */ + coarse, + }; + //----------------[ constructors ]-------------------------- /** * Creates and sets to (0,0,0,0) @@ -904,32 +922,39 @@ class vector4 { inline T constexpr length_sq() const noexcept __attribute__((__always_inline__)) { return x * x + y * y + z * z + w * w; } - inline T constexpr lengthSq() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use length_sq()"))) { - return length_sq(); - } /** * Get length of vector. * @return length of vector */ + template inline T constexpr length() const noexcept __attribute__((__always_inline__)) { - return static_cast(std::sqrt(length_sq())); + if constexpr(mode == sqrt_mode::std) { + return std::sqrt(length_sq()); + } else if constexpr(mode == sqrt_mode::fast) { + return sqrt_fast(length_sq()); + } else if constexpr(mode == sqrt_mode::coarse) { + return sqrt_coarse(length_sq()); + } else { + static_assert(always_false_v, "Unsupported sqrt_mode"); + } } /** * Get length of vector, fast approximation. * @return length of vector */ + [[deprecated("Use length::sqrt_mode::fast>()")]] inline T constexpr length_fast() const noexcept __attribute__((__always_inline__)) __attribute__((__pure__)) { - return static_cast(sqrt_fast(length_sq())); + return length(); } /** * Get length of vector, rougher fast approximation. * @return length of vector */ + [[deprecated("Use length::sqrt_mode::coarse>()")]] inline T constexpr length_faster() const noexcept __attribute__((__always_inline__)) __attribute__((__pure__)) { - return static_cast(sqrt_faster(length_sq())); + return length(); } - /** * Return whether the vector is zero length - this is much faster than a full length calculation * @return whether vector is zero length @@ -937,94 +962,59 @@ class vector4 { inline bool constexpr length_zero() const noexcept __attribute__((__always_inline__)) { /* return x == static_cast(0) && - y == static_cast(0) && - z == static_cast(0) && - w == static_cast(0); + y == static_cast(0); */ // the above may fail to detect cases where the sqrt of three tiny numbers would be zero return std::abs(x) < epsilon && - std::abs(y) < epsilon && - std::abs(z) < epsilon && - std::abs(w) < epsilon; + std::abs(y) < epsilon; } /** * normalise vector */ + template inline void constexpr normalise() noexcept __attribute__((__always_inline__)) { - T const temp = length(); - x /= temp; - y /= temp; - z /= temp; - w /= temp; + *this /= length(); } + [[deprecated("Use normalise::sqrt_mode::fast>()")]] inline void constexpr normalise_fast() noexcept __attribute__((__always_inline__)) { - T const temp = length_fast(); - x /= temp; - y /= temp; - z /= temp; - w /= temp; + normalise(); } + [[deprecated("Use normalise::sqrt_mode::coarse>()")]] inline void constexpr normalise_faster() noexcept __attribute__((__always_inline__)) { - T const temp = length_faster(); - x /= temp; - y /= temp; - z /= temp; - w /= temp; - } - inline void constexpr normalize() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise(); - } - inline void constexpr normalize_fast() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise_fast(); - } - inline void constexpr normalize_faster() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise_faster(); + normalise(); } + template inline vector4 constexpr normalise_copy() const noexcept __attribute__((__always_inline__)) { - T const temp(length()); - return vector4(x / temp, y / temp, z / temp, w / temp); + return *this / length(); } + [[deprecated("Use normalise_copy::sqrt_mode::fast>()")]] inline vector4 constexpr normalise_copy_fast() const noexcept __attribute__((__always_inline__)) { - T const temp(length_fast()); - return vector4(x / temp, y / temp, z / temp, w / temp); + return normalise_copy(); } + [[deprecated("Use normalise_copy::sqrt_mode::coarse>()")]] inline vector4 constexpr normalise_copy_faster() const noexcept __attribute__((__always_inline__)) { - T const temp(length_faster()); - return vector4(x / temp, y / temp, z / temp, w / temp); - } - inline vector4 constexpr normalize_copy() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy(); - } - inline vector4 constexpr normalize_copy_fast() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy_fast(); - } - inline vector4 constexpr normalize_copy_faster() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_copy_faster(); + return normalise_copy(); } /** - * normalise vector. with added zero safety check + * normalise vector, with added zero safety check */ + template inline void constexpr normalise_safe() noexcept __attribute__((__always_inline__)) { if(length_zero()) { assign(); } else { - *this /= length(); + normalise(); } } - inline void constexpr normalize_safe() noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - normalise_safe(); - } + template inline vector4 constexpr normalise_safe_copy() const noexcept __attribute__((__always_inline__)) { if(length_zero()) { - return vector4(); + return {}; } else { - return *this / length(); + return normalise_copy(); } } - inline vector4 constexpr normalize_safe_copy() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Proper English, please!"))) { - return normalise_safe_copy(); - } /** * Absolute vector (make all values positive) @@ -1102,9 +1092,6 @@ class vector4 { oss << *this; return oss.str(); } - inline std::string CONSTEXPR_IF_NO_CLANG toString() const noexcept __attribute__((__always_inline__)) __attribute__((__deprecated__("Use to_string()"))) { - return to_string(); - } /** * Gets a 3D vector subset. @@ -1112,6 +1099,9 @@ class vector4 { inline vector3 constexpr to_3d() const noexcept __attribute__((__always_inline__)) { return vector3(x, y, z); } + +private: + template static constexpr bool always_false_v{false}; }; #ifdef VECTORSTORM_NAMESPACE diff --git a/vectorstorm/vector/vector4_types.h b/vectorstorm/vector/vector4_types.h index 9fc7d74..385ba87 100644 --- a/vectorstorm/vector/vector4_types.h +++ b/vectorstorm/vector/vector4_types.h @@ -27,14 +27,6 @@ using vec4ld = vector4ld; using vec4i = vector4i; using vec4ui = vector4ui; -// deprecated transitional declarations -template -using Vector4 __attribute__((deprecated("Use vector4 or vec4 instead."))) = vector4; -using Vector4f __attribute__((deprecated("Use vector4 or vec4 instead."))) = vector4f; -using Vector4d __attribute__((deprecated("Use vector4 or vec4 instead."))) = vector4d; -using Vector4ld __attribute__((deprecated("Use vector4 or vec4 instead."))) = vector4ld; -using Vector4i __attribute__((deprecated("Use vector4 or vec4 instead."))) = vector4i; - #ifdef VECTORSTORM_NAMESPACE } #endif //VECTORSTORM_NAMESPACE