From 9a38d47b0d46b05ba000cbfa292c1d9c79ed2fa0 Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 4 May 2025 19:13:26 +0300 Subject: [PATCH 1/5] added noexcept for vector types --- include/omath/vector2.hpp | 56 ++++++++++++++++---------------- include/omath/vector3.hpp | 68 +++++++++++++++++++-------------------- include/omath/vector4.hpp | 46 +++++++++++++------------- 3 files changed, 85 insertions(+), 85 deletions(-) diff --git a/include/omath/vector2.hpp b/include/omath/vector2.hpp index 915b1d3..03a98cc 100644 --- a/include/omath/vector2.hpp +++ b/include/omath/vector2.hpp @@ -24,25 +24,25 @@ namespace omath // Constructors constexpr Vector2() = default; - constexpr Vector2(const Type& x, const Type& y): x(x), y(y) + constexpr Vector2(const Type& x, const Type& y) noexcept: x(x), y(y) { } // Equality operators [[nodiscard]] - constexpr bool operator==(const Vector2& src) const + constexpr bool operator==(const Vector2& src) const noexcept { return x == src.x && y == src.y; } [[nodiscard]] - constexpr bool operator!=(const Vector2& src) const + constexpr bool operator!=(const Vector2& src) const noexcept { return !(*this == src); } // Compound assignment operators - constexpr Vector2& operator+=(const Vector2& v) + constexpr Vector2& operator+=(const Vector2& v) noexcept { x += v.x; y += v.y; @@ -50,7 +50,7 @@ namespace omath return *this; } - constexpr Vector2& operator-=(const Vector2& v) + constexpr Vector2& operator-=(const Vector2& v) noexcept { x -= v.x; y -= v.y; @@ -58,7 +58,7 @@ namespace omath return *this; } - constexpr Vector2& operator*=(const Vector2& v) + constexpr Vector2& operator*=(const Vector2& v) noexcept { x *= v.x; y *= v.y; @@ -66,7 +66,7 @@ namespace omath return *this; } - constexpr Vector2& operator/=(const Vector2& v) + constexpr Vector2& operator/=(const Vector2& v) noexcept { x /= v.x; y /= v.y; @@ -74,7 +74,7 @@ namespace omath return *this; } - constexpr Vector2& operator*=(const Type& fl) + constexpr Vector2& operator*=(const Type& fl) noexcept { x *= fl; y *= fl; @@ -82,7 +82,7 @@ namespace omath return *this; } - constexpr Vector2& operator/=(const Type& fl) + constexpr Vector2& operator/=(const Type& fl) noexcept { x /= fl; y /= fl; @@ -90,7 +90,7 @@ namespace omath return *this; } - constexpr Vector2& operator+=(const Type& fl) + constexpr Vector2& operator+=(const Type& fl) noexcept { x += fl; y += fl; @@ -98,7 +98,7 @@ namespace omath return *this; } - constexpr Vector2& operator-=(const Type& fl) + constexpr Vector2& operator-=(const Type& fl) noexcept { x -= fl; y -= fl; @@ -107,50 +107,50 @@ namespace omath } // Basic vector operations - [[nodiscard]] Type distance_to(const Vector2& other) const + [[nodiscard]] Type distance_to(const Vector2& other) const noexcept { return std::sqrt(distance_to_sqr(other)); } - [[nodiscard]] constexpr Type distance_to_sqr(const Vector2& other) const + [[nodiscard]] constexpr Type distance_to_sqr(const Vector2& other) const noexcept { return (x - other.x) * (x - other.x) + (y - other.y) * (y - other.y); } - [[nodiscard]] constexpr Type dot(const Vector2& other) const + [[nodiscard]] constexpr Type dot(const Vector2& other) const noexcept { return x * other.x + y * other.y; } #ifndef _MSC_VER - [[nodiscard]] constexpr Type length() const + [[nodiscard]] constexpr Type length() const noexcept { return std::hypot(this->x, this->y); } - [[nodiscard]] constexpr Vector2 normalized() const + [[nodiscard]] constexpr Vector2 normalized() const noexcept { const Type len = length(); return len > 0.f ? *this / len : *this; } #else - [[nodiscard]] Type length() const + [[nodiscard]] Type length() const noexcept { return std::hypot(x, y); } - [[nodiscard]] Vector2 normalized() const + [[nodiscard]] Vector2 normalized() const noexcept { const Type len = length(); return len > 0.f ? *this / len : *this; } #endif - [[nodiscard]] constexpr Type length_sqr() const + [[nodiscard]] constexpr Type length_sqr() const noexcept { return x * x + y * y; } - constexpr Vector2& abs() + constexpr Vector2& abs() noexcept { // FIXME: Replace with std::abs, if it will become constexprable x = x < 0 ? -x : x; @@ -158,47 +158,47 @@ namespace omath return *this; } - [[nodiscard]] constexpr Vector2 operator-() const + [[nodiscard]] constexpr Vector2 operator-() const noexcept { return {-x, -y}; } // Binary arithmetic operators - [[nodiscard]] constexpr Vector2 operator+(const Vector2& v) const + [[nodiscard]] constexpr Vector2 operator+(const Vector2& v) const noexcept { return {x + v.x, y + v.y}; } - [[nodiscard]] constexpr Vector2 operator-(const Vector2& v) const + [[nodiscard]] constexpr Vector2 operator-(const Vector2& v) const noexcept { return {x - v.x, y - v.y}; } - [[nodiscard]] constexpr Vector2 operator*(const float fl) const + [[nodiscard]] constexpr Vector2 operator*(const float fl) const noexcept { return {x * fl, y * fl}; } - [[nodiscard]] constexpr Vector2 operator/(const float fl) const + [[nodiscard]] constexpr Vector2 operator/(const float fl) const noexcept { return {x / fl, y / fl}; } // Sum of elements - [[nodiscard]] constexpr Type sum() const + [[nodiscard]] constexpr Type sum() const noexcept { return x + y; } [[nodiscard]] - constexpr std::tuple as_tuple() const + constexpr std::tuple as_tuple() const noexcept { return std::make_tuple(x, y); } #ifdef OMATH_IMGUI_INTEGRATION [[nodiscard]] - ImVec2 to_im_vec2() const + ImVec2 to_im_vec2() const noexcept { return {static_cast(this->x), static_cast(this->y)}; } diff --git a/include/omath/vector3.hpp b/include/omath/vector3.hpp index d535168..fc30297 100644 --- a/include/omath/vector3.hpp +++ b/include/omath/vector3.hpp @@ -24,22 +24,22 @@ namespace omath { public: Type z = static_cast(0); - constexpr Vector3(const Type& x, const Type& y, const Type& z): Vector2(x, y), z(z) + constexpr Vector3(const Type& x, const Type& y, const Type& z) noexcept: Vector2(x, y), z(z) { } - constexpr Vector3(): Vector2() {}; + constexpr Vector3() noexcept: Vector2() {}; - [[nodiscard]] constexpr bool operator==(const Vector3& src) const + [[nodiscard]] constexpr bool operator==(const Vector3& src) const noexcept { return Vector2::operator==(src) && (src.z == z); } - [[nodiscard]] constexpr bool operator!=(const Vector3& src) const + [[nodiscard]] constexpr bool operator!=(const Vector3& src) const noexcept { return !(*this == src); } - constexpr Vector3& operator+=(const Vector3& v) + constexpr Vector3& operator+=(const Vector3& v) noexcept { Vector2::operator+=(v); z += v.z; @@ -47,7 +47,7 @@ namespace omath return *this; } - constexpr Vector3& operator-=(const Vector3& v) + constexpr Vector3& operator-=(const Vector3& v) noexcept { Vector2::operator-=(v); z -= v.z; @@ -55,7 +55,7 @@ namespace omath return *this; } - constexpr Vector3& operator*=(const float fl) + constexpr Vector3& operator*=(const float fl) noexcept { Vector2::operator*=(fl); z *= fl; @@ -63,7 +63,7 @@ namespace omath return *this; } - constexpr Vector3& operator*=(const Vector3& v) + constexpr Vector3& operator*=(const Vector3& v) noexcept { Vector2::operator*=(v); z *= v.z; @@ -71,7 +71,7 @@ namespace omath return *this; } - constexpr Vector3& operator/=(const Vector3& v) + constexpr Vector3& operator/=(const Vector3& v) noexcept { Vector2::operator/=(v); z /= v.z; @@ -79,7 +79,7 @@ namespace omath return *this; } - constexpr Vector3& operator+=(const float fl) + constexpr Vector3& operator+=(const float fl) noexcept { Vector2::operator+=(fl); z += fl; @@ -87,7 +87,7 @@ namespace omath return *this; } - constexpr Vector3& operator/=(const float fl) + constexpr Vector3& operator/=(const float fl) noexcept { Vector2::operator/=(fl); z /= fl; @@ -95,7 +95,7 @@ namespace omath return *this; } - constexpr Vector3& operator-=(const float fl) + constexpr Vector3& operator-=(const float fl) noexcept { Vector2::operator-=(fl); z -= fl; @@ -103,7 +103,7 @@ namespace omath return *this; } - constexpr Vector3& abs() + constexpr Vector3& abs() noexcept { Vector2::abs(); z = z < 0.f ? -z : z; @@ -111,12 +111,12 @@ namespace omath return *this; } - [[nodiscard]] constexpr Type distance_to_sqr(const Vector3& other) const + [[nodiscard]] constexpr Type distance_to_sqr(const Vector3& other) const noexcept { return (*this - other).length_sqr(); } - [[nodiscard]] constexpr Type dot(const Vector3& other) const + [[nodiscard]] constexpr Type dot(const Vector3& other) const noexcept { return Vector2::dot(other) + z * other.z; } @@ -142,80 +142,80 @@ namespace omath return length_value != 0 ? *this / length_value : *this; } #else - [[nodiscard]] Type length() const + [[nodiscard]] Type length() const noexcept { return std::hypot(this->x, this->y, z); } - [[nodiscard]] Vector3 normalized() const + [[nodiscard]] Vector3 normalized() const noexcept { const Type len = this->length(); return len != 0 ? *this / len : *this; } - [[nodiscard]] Type length_2d() const + [[nodiscard]] Type length_2d() const noexcept { return Vector2::length(); } - [[nodiscard]] Type distance_to(const Vector3& vOther) const + [[nodiscard]] Type distance_to(const Vector3& vOther) const noexcept { return (*this - vOther).length(); } #endif - [[nodiscard]] constexpr Type length_sqr() const + [[nodiscard]] constexpr Type length_sqr() const noexcept { return Vector2::length_sqr() + z * z; } - [[nodiscard]] constexpr Vector3 operator-() const + [[nodiscard]] constexpr Vector3 operator-() const noexcept { return {-this->x, -this->y, -z}; } - [[nodiscard]] constexpr Vector3 operator+(const Vector3& v) const + [[nodiscard]] constexpr Vector3 operator+(const Vector3& v) const noexcept { return {this->x + v.x, this->y + v.y, z + v.z}; } - [[nodiscard]] constexpr Vector3 operator-(const Vector3& v) const + [[nodiscard]] constexpr Vector3 operator-(const Vector3& v) const noexcept { return {this->x - v.x, this->y - v.y, z - v.z}; } - [[nodiscard]] constexpr Vector3 operator*(const float fl) const + [[nodiscard]] constexpr Vector3 operator*(const float fl) const noexcept { return {this->x * fl, this->y * fl, z * fl}; } - [[nodiscard]] constexpr Vector3 operator*(const Vector3& v) const + [[nodiscard]] constexpr Vector3 operator*(const Vector3& v) const noexcept { return {this->x * v.x, this->y * v.y, z * v.z}; } - [[nodiscard]] constexpr Vector3 operator/(const float fl) const + [[nodiscard]] constexpr Vector3 operator/(const float fl) const noexcept { return {this->x / fl, this->y / fl, z / fl}; } - [[nodiscard]] constexpr Vector3 operator/(const Vector3& v) const + [[nodiscard]] constexpr Vector3 operator/(const Vector3& v) const noexcept { return {this->x / v.x, this->y / v.y, z / v.z}; } - [[nodiscard]] constexpr Vector3 cross(const Vector3& v) const + [[nodiscard]] constexpr Vector3 cross(const Vector3& v) const noexcept { return {this->y * v.z - z * v.y, z * v.x - this->x * v.z, this->x * v.y - this->y * v.x}; } - [[nodiscard]] constexpr Type sum() const + [[nodiscard]] constexpr Type sum() const noexcept { return sum_2d() + z; } [[nodiscard]] std::expected, Vector3Error> - angle_between(const Vector3& other) const + angle_between(const Vector3& other) const noexcept { const auto bottom = length() * other.length(); @@ -225,7 +225,7 @@ namespace omath return Angle::from_radians(std::acos(dot(other) / bottom)); } - [[nodiscard]] bool is_perpendicular(const Vector3& other) const + [[nodiscard]] bool is_perpendicular(const Vector3& other) const noexcept { if (const auto angle = angle_between(other)) return angle->as_degrees() == 90.f; @@ -233,17 +233,17 @@ namespace omath return false; } - [[nodiscard]] constexpr Type sum_2d() const + [[nodiscard]] constexpr Type sum_2d() const noexcept { return Vector2::sum(); } - [[nodiscard]] constexpr std::tuple as_tuple() const + [[nodiscard]] constexpr std::tuple as_tuple() const noexcept { return std::make_tuple(this->x, this->y, z); } - [[nodiscard]] Vector3 view_angle_to(const Vector3& other) const + [[nodiscard]] Vector3 view_angle_to(const Vector3& other) const noexcept { const float distance = distance_to(other); const auto delta = other - *this; diff --git a/include/omath/vector4.hpp b/include/omath/vector4.hpp index 36e0c0a..2f69989 100644 --- a/include/omath/vector4.hpp +++ b/include/omath/vector4.hpp @@ -17,21 +17,21 @@ namespace omath constexpr Vector4(const Type& x, const Type& y, const Type& z, const Type& w): Vector3(x, y, z), w(w) { } - constexpr Vector4(): Vector3(), w(0) {}; + constexpr Vector4() noexcept : Vector3(), w(0) {}; [[nodiscard]] - constexpr bool operator==(const Vector4& src) const + constexpr bool operator==(const Vector4& src) const noexcept { return Vector3::operator==(src) && w == src.w; } [[nodiscard]] - constexpr bool operator!=(const Vector4& src) const + constexpr bool operator!=(const Vector4& src) const noexcept { return !(*this == src); } - constexpr Vector4& operator+=(const Vector4& v) + constexpr Vector4& operator+=(const Vector4& v) noexcept { Vector3::operator+=(v); w += v.w; @@ -39,7 +39,7 @@ namespace omath return *this; } - constexpr Vector4& operator-=(const Vector4& v) + constexpr Vector4& operator-=(const Vector4& v) noexcept { Vector3::operator-=(v); w -= v.w; @@ -47,7 +47,7 @@ namespace omath return *this; } - constexpr Vector4& operator*=(const float scalar) + constexpr Vector4& operator*=(const float scalar) noexcept { Vector3::operator*=(scalar); w *= scalar; @@ -55,7 +55,7 @@ namespace omath return *this; } - constexpr Vector4& operator*=(const Vector4& v) + constexpr Vector4& operator*=(const Vector4& v) noexcept { Vector3::operator*=(v); w *= v.w; @@ -63,7 +63,7 @@ namespace omath return *this; } - constexpr Vector4& operator/=(const float scalar) + constexpr Vector4& operator/=(const float scalar) noexcept { Vector3::operator/=(scalar); w /= scalar; @@ -71,36 +71,36 @@ namespace omath return *this; } - constexpr Vector4& operator/=(const Vector4& v) + constexpr Vector4& operator/=(const Vector4& v) noexcept { Vector3::operator/=(v); w /= v.w; return *this; } - [[nodiscard]] constexpr Type length_sqr() const + [[nodiscard]] constexpr Type length_sqr() const noexcept { return Vector3::length_sqr() + w * w; } - [[nodiscard]] constexpr Type dot(const Vector4& other) const + [[nodiscard]] constexpr Type dot(const Vector4& other) const noexcept { return Vector3::dot(other) + w * other.w; } - [[nodiscard]] Vector3 length() const + [[nodiscard]] Vector3 length() const noexcept { return std::sqrt(length_sqr()); } - constexpr Vector4& abs() + constexpr Vector4& abs() noexcept { Vector3::abs(); w = w < 0.f ? -w : w; return *this; } - constexpr Vector4& clamp(const Type& min, const Type& max) + constexpr Vector4& clamp(const Type& min, const Type& max) noexcept { this->x = std::clamp(this->x, min, max); this->y = std::clamp(this->y, min, max); @@ -110,56 +110,56 @@ namespace omath } [[nodiscard]] - constexpr Vector4 operator-() const + constexpr Vector4 operator-() const noexcept { return {-this->x, -this->y, -this->z, -w}; } [[nodiscard]] - constexpr Vector4 operator+(const Vector4& v) const + constexpr Vector4 operator+(const Vector4& v) const noexcept { return {this->x + v.x, this->y + v.y, this->z + v.z, w + v.w}; } [[nodiscard]] - constexpr Vector4 operator-(const Vector4& v) const + constexpr Vector4 operator-(const Vector4& v) const noexcept { return {this->x - v.x, this->y - v.y, this->z - v.z, w - v.w}; } [[nodiscard]] - constexpr Vector4 operator*(const Type& scalar) const + constexpr Vector4 operator*(const Type& scalar) const noexcept { return {this->x * scalar, this->y * scalar, this->z * scalar, w * scalar}; } [[nodiscard]] - constexpr Vector4 operator*(const Vector4& v) const + constexpr Vector4 operator*(const Vector4& v) const noexcept { return {this->x * v.x, this->y * v.y, this->z * v.z, w * v.w}; } [[nodiscard]] - constexpr Vector4 operator/(const Type& scalar) const + constexpr Vector4 operator/(const Type& scalar) const noexcept { return {this->x / scalar, this->y / scalar, this->z / scalar, w / scalar}; } [[nodiscard]] - constexpr Vector4 operator/(const Vector4& v) const + constexpr Vector4 operator/(const Vector4& v) const noexcept { return {this->x / v.x, this->y / v.y, this->z / v.z, w / v.w}; } [[nodiscard]] - constexpr Type sum() const + constexpr Type sum() const noexcept { return Vector3::sum() + w; } #ifdef OMATH_IMGUI_INTEGRATION [[nodiscard]] - ImVec4 to_im_vec4() const + ImVec4 to_im_vec4() const noexcept { return { static_cast(this->x), From 6749f9f759cf908d835d5556d0c2afb555660b9a Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 4 May 2025 19:16:49 +0300 Subject: [PATCH 2/5] added noexcept for color and angles --- include/omath/angle.hpp | 36 ++++++++++++++++++------------------ include/omath/angles.hpp | 14 +++++++------- include/omath/color.hpp | 22 +++++++++++----------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/include/omath/angle.hpp b/include/omath/angle.hpp index e2949a3..e7d0879 100644 --- a/include/omath/angle.hpp +++ b/include/omath/angle.hpp @@ -20,7 +20,7 @@ namespace omath class Angle { Type m_angle; - constexpr explicit Angle(const Type& degrees) + constexpr explicit Angle(const Type& degrees) noexcept { if constexpr (flags == AngleFlags::Normalized) m_angle = angles::wrap_angle(degrees, min, max); @@ -36,68 +36,68 @@ namespace omath public: [[nodiscard]] - constexpr static Angle from_degrees(const Type& degrees) + constexpr static Angle from_degrees(const Type& degrees) noexcept { return Angle{degrees}; } - constexpr Angle(): m_angle(0) + constexpr Angle() noexcept: m_angle(0) { } [[nodiscard]] - constexpr static Angle from_radians(const Type& degrees) + constexpr static Angle from_radians(const Type& degrees) noexcept { return Angle{angles::radians_to_degrees(degrees)}; } [[nodiscard]] - constexpr const Type& operator*() const + constexpr const Type& operator*() const noexcept { return m_angle; } [[nodiscard]] - constexpr Type as_degrees() const + constexpr Type as_degrees() const noexcept { return m_angle; } [[nodiscard]] - constexpr Type as_radians() const + constexpr Type as_radians() const noexcept { return angles::degrees_to_radians(m_angle); } [[nodiscard]] - Type sin() const + Type sin() const noexcept { return std::sin(as_radians()); } [[nodiscard]] - Type cos() const + Type cos() const noexcept { return std::cos(as_radians()); } [[nodiscard]] - Type tan() const + Type tan() const noexcept { return std::tan(as_radians()); } [[nodiscard]] - Type atan() const + Type atan() const noexcept { return std::atan(as_radians()); } [[nodiscard]] - Type cot() const + Type cot() const noexcept { return cos() / sin(); } - constexpr Angle& operator+=(const Angle& other) + constexpr Angle& operator+=(const Angle& other) noexcept { if constexpr (flags == AngleFlags::Normalized) m_angle = angles::wrap_angle(m_angle + other.m_angle, min, max); @@ -114,15 +114,15 @@ namespace omath } [[nodiscard]] - constexpr std::partial_ordering operator<=>(const Angle& other) const = default; + constexpr std::partial_ordering operator<=>(const Angle& other) const noexcept = default; - constexpr Angle& operator-=(const Angle& other) + constexpr Angle& operator-=(const Angle& other) noexcept { return operator+=(-other); } [[nodiscard]] - constexpr Angle& operator+(const Angle& other) + constexpr Angle& operator+(const Angle& other) noexcept { if constexpr (flags == AngleFlags::Normalized) return {angles::wrap_angle(m_angle + other.m_angle, min, max)}; @@ -137,13 +137,13 @@ namespace omath } [[nodiscard]] - constexpr Angle& operator-(const Angle& other) + constexpr Angle& operator-(const Angle& other) noexcept { return operator+(-other); } [[nodiscard]] - constexpr Angle operator-() const + constexpr Angle operator-() const noexcept { return Angle{-m_angle}; } diff --git a/include/omath/angles.hpp b/include/omath/angles.hpp index cafacbb..ce07dd8 100644 --- a/include/omath/angles.hpp +++ b/include/omath/angles.hpp @@ -10,21 +10,21 @@ namespace omath::angles { template requires std::is_floating_point_v - [[nodiscard]] constexpr Type radians_to_degrees(const Type& radians) + [[nodiscard]] constexpr Type radians_to_degrees(const Type& radians) noexcept { return radians * (static_cast(180) / std::numbers::pi_v); } template requires std::is_floating_point_v - [[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees) + [[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees) noexcept { return degrees * (std::numbers::pi_v / static_cast(180)); } template requires std::is_floating_point_v - [[nodiscard]] Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect) + [[nodiscard]] Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect) noexcept { const auto fov_rad = degrees_to_radians(horizontal_fov); @@ -35,19 +35,19 @@ namespace omath::angles template requires std::is_floating_point_v - [[nodiscard]] Type vertical_fov_to_horizontal(const Type& vertical_fov, const Type& aspect) + [[nodiscard]] Type vertical_fov_to_horizontal(const Type& vertical_fov, const Type& aspect) noexcept { const auto fov_as_radians = degrees_to_radians(vertical_fov); - const auto horizontal_fov - = static_cast(2) * std::atan(std::tan(fov_as_radians / static_cast(2)) * aspect); + const auto horizontal_fov = + static_cast(2) * std::atan(std::tan(fov_as_radians / static_cast(2)) * aspect); return radians_to_degrees(horizontal_fov); } template requires std::is_arithmetic_v - [[nodiscard]] Type wrap_angle(const Type& angle, const Type& min, const Type& max) + [[nodiscard]] Type wrap_angle(const Type& angle, const Type& min, const Type& max) noexcept { if (angle <= max && angle >= min) return angle; diff --git a/include/omath/color.hpp b/include/omath/color.hpp index e460059..3513e74 100644 --- a/include/omath/color.hpp +++ b/include/omath/color.hpp @@ -28,20 +28,20 @@ namespace omath class Color final : public Vector4 { public: - constexpr Color(const float r, const float g, const float b, const float a): Vector4(r, g, b, a) + constexpr Color(const float r, const float g, const float b, const float a) noexcept: Vector4(r, g, b, a) { clamp(0.f, 1.f); } - constexpr explicit Color() = default; + constexpr explicit Color() noexcept = default; [[nodiscard]] - constexpr static Color from_rgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a) + constexpr static Color from_rgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a) noexcept { return Color{Vector4(r, g, b, a) / 255.f}; } [[nodiscard]] - constexpr static Color from_hsv(float hue, const float saturation, const float value) + constexpr static Color from_hsv(float hue, const float saturation, const float value) noexcept { float r{}, g{}, b{}; @@ -82,13 +82,13 @@ namespace omath } [[nodiscard]] - constexpr static Color from_hsv(const Hsv& hsv) + constexpr static Color from_hsv(const Hsv& hsv) noexcept { return from_hsv(hsv.hue, hsv.saturation, hsv.value); } [[nodiscard]] - constexpr Hsv to_hsv() const + constexpr Hsv to_hsv() const noexcept { Hsv hsv_data; @@ -120,11 +120,11 @@ namespace omath return hsv_data; } - constexpr explicit Color(const Vector4& vec): Vector4(vec) + constexpr explicit Color(const Vector4& vec) noexcept: Vector4(vec) { clamp(0.f, 1.f); } - constexpr void set_hue(const float hue) + constexpr void set_hue(const float hue) noexcept { auto hsv = to_hsv(); hsv.hue = hue; @@ -132,7 +132,7 @@ namespace omath *this = from_hsv(hsv); } - constexpr void set_saturation(const float saturation) + constexpr void set_saturation(const float saturation) noexcept { auto hsv = to_hsv(); hsv.saturation = saturation; @@ -140,7 +140,7 @@ namespace omath *this = from_hsv(hsv); } - constexpr void set_value(const float value) + constexpr void set_value(const float value) noexcept { auto hsv = to_hsv(); hsv.value = value; @@ -148,7 +148,7 @@ namespace omath *this = from_hsv(hsv); } [[nodiscard]] - constexpr Color blend(const Color& other, float ratio) const + constexpr Color blend(const Color& other, float ratio) const noexcept { ratio = std::clamp(ratio, 0.f, 1.f); return Color(*this * (1.f - ratio) + other * ratio); From a6e4c0461d72fa45be296be16729eda55e7f6e5d Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 5 May 2025 01:16:12 +0300 Subject: [PATCH 3/5] added noexcept --- include/omath/projection/camera.hpp | 39 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index 93f956a..be9a9f8 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -32,7 +32,7 @@ namespace omath::projection public: virtual ~Camera() = default; Camera(const Vector3& position, const ViewAnglesType& view_angles, const ViewPort& view_port, - const FieldOfView& fov, const float near, const float far) + const FieldOfView& fov, const float near, const float far) noexcept : m_view_port(view_port), m_field_of_view(fov), m_far_plane_distance(far), m_near_plane_distance(near), m_view_angles(view_angles), m_origin(position) { @@ -45,13 +45,13 @@ namespace omath::projection [[nodiscard]] virtual Mat4X4Type calc_projection_matrix() const = 0; - [[nodiscard]] Mat4X4Type calc_view_projection_matrix() const + [[nodiscard]] Mat4X4Type calc_view_projection_matrix() const noexcept { return calc_projection_matrix() * calc_view_matrix(); } public: - [[nodiscard]] const Mat4X4Type& get_view_projection_matrix() const + [[nodiscard]] const Mat4X4Type& get_view_projection_matrix() const noexcept { if (!m_view_projection_matrix.has_value()) m_view_projection_matrix = calc_view_projection_matrix(); @@ -59,68 +59,69 @@ namespace omath::projection return m_view_projection_matrix.value(); } - void set_field_of_view(const FieldOfView& fov) + void set_field_of_view(const FieldOfView& fov) noexcept { m_field_of_view = fov; m_view_projection_matrix = std::nullopt; } - void set_near_plane(const float near) + void set_near_plane(const float near) noexcept { m_near_plane_distance = near; m_view_projection_matrix = std::nullopt; } - void set_far_plane(const float far) + void set_far_plane(const float far) noexcept { m_far_plane_distance = far; m_view_projection_matrix = std::nullopt; } - void set_view_angles(const ViewAnglesType& view_angles) + void set_view_angles(const ViewAnglesType& view_angles) noexcept { m_view_angles = view_angles; m_view_projection_matrix = std::nullopt; } - void set_origin(const Vector3& origin) + void set_origin(const Vector3& origin) noexcept { m_origin = origin; m_view_projection_matrix = std::nullopt; } - void set_view_port(const ViewPort& view_port) + void set_view_port(const ViewPort& view_port) noexcept { m_view_port = view_port; m_view_projection_matrix = std::nullopt; } - [[nodiscard]] const FieldOfView& get_field_of_view() const + [[nodiscard]] const FieldOfView& get_field_of_view() const noexcept { return m_field_of_view; } - [[nodiscard]] const float& get_near_plane() const + [[nodiscard]] const float& get_near_plane() const noexcept { return m_near_plane_distance; } - [[nodiscard]] const float& get_far_plane() const + [[nodiscard]] const float& get_far_plane() const noexcept { return m_far_plane_distance; } - [[nodiscard]] const ViewAnglesType& get_view_angles() const + [[nodiscard]] const ViewAnglesType& get_view_angles() const noexcept { return m_view_angles; } - [[nodiscard]] const Vector3& get_origin() const + [[nodiscard]] const Vector3& get_origin() const noexcept { return m_origin; } - [[nodiscard]] std::expected, Error> world_to_screen(const Vector3& world_position) const + [[nodiscard]] std::expected, Error> + world_to_screen(const Vector3& world_position) const noexcept { auto normalized_cords = world_to_view_port(world_position); @@ -131,7 +132,7 @@ namespace omath::projection } [[nodiscard]] std::expected, Error> - world_to_view_port(const Vector3& world_position) const + world_to_view_port(const Vector3& world_position) const noexcept { auto projected = get_view_projection_matrix() * mat_column_from_vector(world_position); @@ -160,13 +161,13 @@ namespace omath::projection Vector3 m_origin; private: - template [[nodiscard]] - constexpr static bool is_ndc_out_of_bounds(const Type& ndc) + template + [[nodiscard]] constexpr static bool is_ndc_out_of_bounds(const Type& ndc) noexcept { return std::ranges::any_of(ndc.raw_array(), [](const auto& val) { return val < -1 || val > 1; }); } - [[nodiscard]] Vector3 ndc_to_screen_position(const Vector3& ndc) const + [[nodiscard]] Vector3 ndc_to_screen_position(const Vector3& ndc) const noexcept { return {(ndc.x + 1.f) / 2.f * m_view_port.m_width, (1.f - ndc.y) / 2.f * m_view_port.m_height, ndc.z}; } From 50ddf2d31e9a285e1c3f61152c4d76459a14ef43 Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 5 May 2025 01:46:50 +0300 Subject: [PATCH 4/5] added more noexcept --- include/omath/3d_primitives/box.hpp | 2 +- include/omath/collision/line_tracer.hpp | 8 ++++---- include/omath/engines/iw_engine/camera.hpp | 4 ++-- include/omath/engines/opengl_engine/camera.hpp | 4 ++-- include/omath/engines/opengl_engine/formulas.hpp | 12 ++++++------ include/omath/engines/source_engine/camera.hpp | 4 ++-- include/omath/engines/source_engine/formulas.hpp | 12 ++++++------ include/omath/engines/unity_engine/camera.hpp | 4 ++-- include/omath/engines/unity_engine/formulas.hpp | 12 ++++++------ .../projectile_prediction/proj_pred_engine_avx2.hpp | 6 +++--- .../proj_pred_engine_legacy.hpp | 7 ++++--- include/omath/projectile_prediction/projectile.hpp | 2 +- include/omath/projectile_prediction/target.hpp | 2 +- include/omath/projection/camera.hpp | 4 ++-- source/3d_primitives/box.cpp | 2 +- source/collision/line_tracer.cpp | 8 ++++---- source/engines/iw_engine/camera.cpp | 4 ++-- source/engines/opengl_engine/camera.cpp | 4 ++-- source/engines/opengl_engine/formulas.cpp | 12 ++++++------ source/engines/source_engine/camera.cpp | 4 ++-- source/engines/source_engine/formulas.cpp | 12 ++++++------ source/engines/unity_engine/camera.cpp | 4 ++-- source/engines/unity_engine/formulas.cpp | 12 ++++++------ .../proj_pred_engine_legacy.cpp | 11 +++++------ source/projectile_prediction/projectile.cpp | 2 +- 25 files changed, 79 insertions(+), 79 deletions(-) diff --git a/include/omath/3d_primitives/box.hpp b/include/omath/3d_primitives/box.hpp index 23a5967..49cc475 100644 --- a/include/omath/3d_primitives/box.hpp +++ b/include/omath/3d_primitives/box.hpp @@ -13,5 +13,5 @@ namespace omath::primitives [[nodiscard]] std::array>, 12> create_box(const Vector3& top, const Vector3& bottom, const Vector3& dir_forward, const Vector3& dir_right, - float ratio = 4.f); + float ratio = 4.f) noexcept; } diff --git a/include/omath/collision/line_tracer.hpp b/include/omath/collision/line_tracer.hpp index 6a655b0..a79a3cf 100644 --- a/include/omath/collision/line_tracer.hpp +++ b/include/omath/collision/line_tracer.hpp @@ -16,10 +16,10 @@ namespace omath::collision bool infinite_length = false; [[nodiscard]] - Vector3 direction_vector() const; + Vector3 direction_vector() const noexcept; [[nodiscard]] - Vector3 direction_vector_normalized() const; + Vector3 direction_vector_normalized() const noexcept; }; class LineTracer { @@ -27,11 +27,11 @@ namespace omath::collision LineTracer() = delete; [[nodiscard]] - static bool can_trace_line(const Ray& ray, const Triangle>& triangle); + static bool can_trace_line(const Ray& ray, const Triangle>& triangle) noexcept; // Realization of Möller–Trumbore intersection algorithm // https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm [[nodiscard]] - static Vector3 get_ray_hit_point(const Ray& ray, const Triangle>& triangle); + static Vector3 get_ray_hit_point(const Ray& ray, const Triangle>& triangle) noexcept; }; } // namespace omath::collision diff --git a/include/omath/engines/iw_engine/camera.hpp b/include/omath/engines/iw_engine/camera.hpp index ea59474..2f530e1 100644 --- a/include/omath/engines/iw_engine/camera.hpp +++ b/include/omath/engines/iw_engine/camera.hpp @@ -16,7 +16,7 @@ namespace omath::iw_engine void look_at(const Vector3& target) override; protected: - [[nodiscard]] Mat4X4 calc_view_matrix() const override; - [[nodiscard]] Mat4X4 calc_projection_matrix() const override; + [[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override; + [[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override; }; } // namespace omath::iw_engine \ No newline at end of file diff --git a/include/omath/engines/opengl_engine/camera.hpp b/include/omath/engines/opengl_engine/camera.hpp index 605ee44..b4cdd21 100644 --- a/include/omath/engines/opengl_engine/camera.hpp +++ b/include/omath/engines/opengl_engine/camera.hpp @@ -13,7 +13,7 @@ namespace omath::opengl_engine Camera(const Vector3& position, const ViewAngles& view_angles, const projection::ViewPort& view_port, const Angle& fov, float near, float far); void look_at(const Vector3& target) override; - [[nodiscard]] Mat4X4 calc_view_matrix() const override; - [[nodiscard]] Mat4X4 calc_projection_matrix() const override; + [[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override; + [[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override; }; } // namespace omath::opengl_engine \ No newline at end of file diff --git a/include/omath/engines/opengl_engine/formulas.hpp b/include/omath/engines/opengl_engine/formulas.hpp index dc6ae64..31714f5 100644 --- a/include/omath/engines/opengl_engine/formulas.hpp +++ b/include/omath/engines/opengl_engine/formulas.hpp @@ -8,19 +8,19 @@ namespace omath::opengl_engine { [[nodiscard]] - Vector3 forward_vector(const ViewAngles& angles); + Vector3 forward_vector(const ViewAngles& angles) noexcept; [[nodiscard]] - Vector3 right_vector(const ViewAngles& angles); + Vector3 right_vector(const ViewAngles& angles) noexcept; [[nodiscard]] - Vector3 up_vector(const ViewAngles& angles); + Vector3 up_vector(const ViewAngles& angles) noexcept; - [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin); + [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept; [[nodiscard]] - Mat4X4 rotation_matrix(const ViewAngles& angles); + Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; [[nodiscard]] - Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far); + Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept; } // namespace omath::opengl_engine diff --git a/include/omath/engines/source_engine/camera.hpp b/include/omath/engines/source_engine/camera.hpp index 0ea1112..cba5c43 100644 --- a/include/omath/engines/source_engine/camera.hpp +++ b/include/omath/engines/source_engine/camera.hpp @@ -15,7 +15,7 @@ namespace omath::source_engine void look_at(const Vector3& target) override; protected: - [[nodiscard]] Mat4X4 calc_view_matrix() const override; - [[nodiscard]] Mat4X4 calc_projection_matrix() const override; + [[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override; + [[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override; }; } // namespace omath::source_engine \ No newline at end of file diff --git a/include/omath/engines/source_engine/formulas.hpp b/include/omath/engines/source_engine/formulas.hpp index 2b651e0..a51a633 100644 --- a/include/omath/engines/source_engine/formulas.hpp +++ b/include/omath/engines/source_engine/formulas.hpp @@ -7,19 +7,19 @@ namespace omath::source_engine { [[nodiscard]] - Vector3 forward_vector(const ViewAngles& angles); + Vector3 forward_vector(const ViewAngles& angles) noexcept; [[nodiscard]] - Mat4X4 rotation_matrix(const ViewAngles& angles); + Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; [[nodiscard]] - Vector3 right_vector(const ViewAngles& angles); + Vector3 right_vector(const ViewAngles& angles) noexcept; [[nodiscard]] - Vector3 up_vector(const ViewAngles& angles); + Vector3 up_vector(const ViewAngles& angles) noexcept; - [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin); + [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept; [[nodiscard]] - Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far); + Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept; } // namespace omath::source_engine diff --git a/include/omath/engines/unity_engine/camera.hpp b/include/omath/engines/unity_engine/camera.hpp index 7a96757..568b2a7 100644 --- a/include/omath/engines/unity_engine/camera.hpp +++ b/include/omath/engines/unity_engine/camera.hpp @@ -16,7 +16,7 @@ namespace omath::unity_engine void look_at(const Vector3& target) override; protected: - [[nodiscard]] Mat4X4 calc_view_matrix() const override; - [[nodiscard]] Mat4X4 calc_projection_matrix() const override; + [[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override; + [[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override; }; } // namespace omath::unity_engine \ No newline at end of file diff --git a/include/omath/engines/unity_engine/formulas.hpp b/include/omath/engines/unity_engine/formulas.hpp index db691d5..be07136 100644 --- a/include/omath/engines/unity_engine/formulas.hpp +++ b/include/omath/engines/unity_engine/formulas.hpp @@ -8,19 +8,19 @@ namespace omath::unity_engine { [[nodiscard]] - Vector3 forward_vector(const ViewAngles& angles); + Vector3 forward_vector(const ViewAngles& angles) noexcept; [[nodiscard]] - Vector3 right_vector(const ViewAngles& angles); + Vector3 right_vector(const ViewAngles& angles) noexcept; [[nodiscard]] - Vector3 up_vector(const ViewAngles& angles); + Vector3 up_vector(const ViewAngles& angles) noexcept; - [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin); + [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept; [[nodiscard]] - Mat4X4 rotation_matrix(const ViewAngles& angles); + Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; [[nodiscard]] - Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far); + Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept; } // namespace omath::unity_engine diff --git a/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp b/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp index 85e3fc5..59d0592 100644 --- a/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp +++ b/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp @@ -9,8 +9,8 @@ namespace omath::projectile_prediction class ProjPredEngineAvx2 final : public ProjPredEngine { public: - [[nodiscard]] std::optional> maybe_calculate_aim_point(const Projectile& projectile, - const Target& target) const override; + [[nodiscard]] std::optional> + maybe_calculate_aim_point(const Projectile& projectile, const Target& target) const override; ProjPredEngineAvx2(float gravity_constant, float simulation_time_step, float maximum_simulation_time); ~ProjPredEngineAvx2() override = default; @@ -18,7 +18,7 @@ namespace omath::projectile_prediction private: [[nodiscard]] static std::optional calculate_pitch(const Vector3& proj_origin, const Vector3& target_pos, - float bullet_gravity, float v0, float time); + float bullet_gravity, float v0, float time) ; // We use [[maybe_unused]] here since AVX2 is not available for ARM and ARM64 CPU [[maybe_unused]] const float m_gravity_constant; diff --git a/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp b/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp index caa5cf5..44eec14 100644 --- a/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp +++ b/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp @@ -29,11 +29,12 @@ namespace omath::projectile_prediction const float m_distance_tolerance; [[nodiscard]] - std::optional maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile, - const Vector3& target_position) const; + std::optional + maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile, + const Vector3& target_position) const noexcept; [[nodiscard]] bool is_projectile_reached_target(const Vector3& target_position, const Projectile& projectile, - float pitch, float time) const; + float pitch, float time) const noexcept; }; } // namespace omath::projectile_prediction diff --git a/include/omath/projectile_prediction/projectile.hpp b/include/omath/projectile_prediction/projectile.hpp index d1188c5..ee0cafd 100644 --- a/include/omath/projectile_prediction/projectile.hpp +++ b/include/omath/projectile_prediction/projectile.hpp @@ -11,7 +11,7 @@ namespace omath::projectile_prediction { public: [[nodiscard]] - Vector3 predict_position(float pitch, float yaw, float time, float gravity) const; + Vector3 predict_position(float pitch, float yaw, float time, float gravity) const noexcept; Vector3 m_origin; float m_launch_speed{}; diff --git a/include/omath/projectile_prediction/target.hpp b/include/omath/projectile_prediction/target.hpp index 7470717..4dd38b0 100644 --- a/include/omath/projectile_prediction/target.hpp +++ b/include/omath/projectile_prediction/target.hpp @@ -11,7 +11,7 @@ namespace omath::projectile_prediction { public: [[nodiscard]] - constexpr Vector3 predict_position(const float time, const float gravity) const + constexpr Vector3 predict_position(const float time, const float gravity) const noexcept { auto predicted = m_origin + m_velocity * time; diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index be9a9f8..cf93a78 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -41,9 +41,9 @@ namespace omath::projection protected: virtual void look_at(const Vector3& target) = 0; - [[nodiscard]] virtual Mat4X4Type calc_view_matrix() const = 0; + [[nodiscard]] virtual Mat4X4Type calc_view_matrix() const noexcept = 0; - [[nodiscard]] virtual Mat4X4Type calc_projection_matrix() const = 0; + [[nodiscard]] virtual Mat4X4Type calc_projection_matrix() const noexcept = 0; [[nodiscard]] Mat4X4Type calc_view_projection_matrix() const noexcept { diff --git a/source/3d_primitives/box.cpp b/source/3d_primitives/box.cpp index 81da0bb..9c251b9 100644 --- a/source/3d_primitives/box.cpp +++ b/source/3d_primitives/box.cpp @@ -7,7 +7,7 @@ namespace omath::primitives { std::array>, 12> create_box(const Vector3& top, const Vector3& bottom, const Vector3& dir_forward, - const Vector3& dir_right, const float ratio) + const Vector3& dir_right, const float ratio) noexcept { const auto height = top.distance_to(bottom); const auto side_size = height / ratio; diff --git a/source/collision/line_tracer.cpp b/source/collision/line_tracer.cpp index e60c0de..311c99a 100644 --- a/source/collision/line_tracer.cpp +++ b/source/collision/line_tracer.cpp @@ -5,21 +5,21 @@ namespace omath::collision { - bool LineTracer::can_trace_line(const Ray& ray, const Triangle>& triangle) + bool LineTracer::can_trace_line(const Ray& ray, const Triangle>& triangle) noexcept { return get_ray_hit_point(ray, triangle) == ray.end; } - Vector3 Ray::direction_vector() const + Vector3 Ray::direction_vector() const noexcept { return end - start; } - Vector3 Ray::direction_vector_normalized() const + Vector3 Ray::direction_vector_normalized() const noexcept { return direction_vector().normalized(); } - Vector3 LineTracer::get_ray_hit_point(const Ray& ray, const Triangle>& triangle) + Vector3 LineTracer::get_ray_hit_point(const Ray& ray, const Triangle>& triangle) noexcept { constexpr float k_epsilon = std::numeric_limits::epsilon(); diff --git a/source/engines/iw_engine/camera.cpp b/source/engines/iw_engine/camera.cpp index 77aaf20..27d8ae7 100644 --- a/source/engines/iw_engine/camera.cpp +++ b/source/engines/iw_engine/camera.cpp @@ -21,11 +21,11 @@ namespace omath::iw_engine m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x)); m_view_angles.roll = RollAngle::from_radians(0.f); } - Mat4X4 Camera::calc_view_matrix() const + Mat4X4 Camera::calc_view_matrix() const noexcept { return iw_engine::calc_view_matrix(m_view_angles, m_origin); } - Mat4X4 Camera::calc_projection_matrix() const + Mat4X4 Camera::calc_projection_matrix() const noexcept { return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(), m_near_plane_distance, m_far_plane_distance); diff --git a/source/engines/opengl_engine/camera.cpp b/source/engines/opengl_engine/camera.cpp index 4b69410..269974c 100644 --- a/source/engines/opengl_engine/camera.cpp +++ b/source/engines/opengl_engine/camera.cpp @@ -21,11 +21,11 @@ namespace omath::opengl_engine m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x)); m_view_angles.roll = RollAngle::from_radians(0.f); } - Mat4X4 Camera::calc_view_matrix() const + Mat4X4 Camera::calc_view_matrix() const noexcept { return opengl_engine::calc_view_matrix(m_view_angles, m_origin); } - Mat4X4 Camera::calc_projection_matrix() const + Mat4X4 Camera::calc_projection_matrix() const noexcept { return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(), m_near_plane_distance, m_far_plane_distance); diff --git a/source/engines/opengl_engine/formulas.cpp b/source/engines/opengl_engine/formulas.cpp index 79868b5..4a14ab2 100644 --- a/source/engines/opengl_engine/formulas.cpp +++ b/source/engines/opengl_engine/formulas.cpp @@ -6,39 +6,39 @@ namespace omath::opengl_engine { - Vector3 forward_vector(const ViewAngles& angles) + Vector3 forward_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Vector3 right_vector(const ViewAngles& angles) + Vector3 right_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Vector3 up_vector(const ViewAngles& angles) + Vector3 up_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) + Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept { return mat_camera_view(-forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin); } - Mat4X4 rotation_matrix(const ViewAngles& angles) + Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept { return mat_rotation_axis_x(-angles.pitch) * mat_rotation_axis_y(-angles.yaw) * mat_rotation_axis_z(angles.roll); } Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near, - const float far) + const float far) noexcept { const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f); diff --git a/source/engines/source_engine/camera.cpp b/source/engines/source_engine/camera.cpp index 3b550f5..edd4c52 100644 --- a/source/engines/source_engine/camera.cpp +++ b/source/engines/source_engine/camera.cpp @@ -22,12 +22,12 @@ namespace omath::source_engine m_view_angles.roll = RollAngle::from_radians(0.f); } - Mat4X4 Camera::calc_view_matrix() const + Mat4X4 Camera::calc_view_matrix() const noexcept { return source_engine::calc_view_matrix(m_view_angles, m_origin); } - Mat4X4 Camera::calc_projection_matrix() const + Mat4X4 Camera::calc_projection_matrix() const noexcept { return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(), m_near_plane_distance, m_far_plane_distance); diff --git a/source/engines/source_engine/formulas.cpp b/source/engines/source_engine/formulas.cpp index fe869e4..326507e 100644 --- a/source/engines/source_engine/formulas.cpp +++ b/source/engines/source_engine/formulas.cpp @@ -5,38 +5,38 @@ namespace omath::source_engine { - Vector3 forward_vector(const ViewAngles& angles) + Vector3 forward_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Mat4X4 rotation_matrix(const ViewAngles& angles) + Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept { return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll); } - Vector3 right_vector(const ViewAngles& angles) + Vector3 right_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Vector3 up_vector(const ViewAngles& angles) + Vector3 up_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) + Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept { return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin); } Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near, - const float far) + const float far) noexcept { // NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation constexpr auto k_multiply_factor = 0.75f; diff --git a/source/engines/unity_engine/camera.cpp b/source/engines/unity_engine/camera.cpp index f06304d..5455c76 100644 --- a/source/engines/unity_engine/camera.cpp +++ b/source/engines/unity_engine/camera.cpp @@ -15,11 +15,11 @@ namespace omath::unity_engine { throw std::runtime_error("Not implemented"); } - Mat4X4 Camera::calc_view_matrix() const + Mat4X4 Camera::calc_view_matrix() const noexcept { return unity_engine::calc_view_matrix(m_view_angles, m_origin); } - Mat4X4 Camera::calc_projection_matrix() const + Mat4X4 Camera::calc_projection_matrix() const noexcept { return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(), m_near_plane_distance, m_far_plane_distance); diff --git a/source/engines/unity_engine/formulas.cpp b/source/engines/unity_engine/formulas.cpp index ed6579f..4560e27 100644 --- a/source/engines/unity_engine/formulas.cpp +++ b/source/engines/unity_engine/formulas.cpp @@ -5,37 +5,37 @@ namespace omath::unity_engine { - Vector3 forward_vector(const ViewAngles& angles) + Vector3 forward_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Vector3 right_vector(const ViewAngles& angles) + Vector3 right_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Vector3 up_vector(const ViewAngles& angles) + Vector3 up_vector(const ViewAngles& angles) noexcept { const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; } - Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) + Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept { return mat_camera_view(forward_vector(angles), -right_vector(angles), up_vector(angles), cam_origin); } - Mat4X4 rotation_matrix(const ViewAngles& angles) + Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept { return mat_rotation_axis_x(angles.pitch) * mat_rotation_axis_y(angles.yaw) * mat_rotation_axis_z(angles.roll); } Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near, - const float far) + const float far) noexcept { const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f); diff --git a/source/projectile_prediction/proj_pred_engine_legacy.cpp b/source/projectile_prediction/proj_pred_engine_legacy.cpp index 5d3c041..b2f5c7d 100644 --- a/source/projectile_prediction/proj_pred_engine_legacy.cpp +++ b/source/projectile_prediction/proj_pred_engine_legacy.cpp @@ -18,8 +18,8 @@ namespace omath::projectile_prediction { const auto predicted_target_position = target.predict_position(time, m_gravity_constant); - const auto projectile_pitch - = maybe_calculate_projectile_launch_pitch_angle(projectile, predicted_target_position); + const auto projectile_pitch = + maybe_calculate_projectile_launch_pitch_angle(projectile, predicted_target_position); if (!projectile_pitch.has_value()) [[unlikely]] continue; @@ -35,9 +35,8 @@ namespace omath::projectile_prediction return std::nullopt; } - std::optional - ProjPredEngineLegacy::maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile, - const Vector3& target_position) const + std::optional ProjPredEngineLegacy::maybe_calculate_projectile_launch_pitch_angle( + const Projectile& projectile, const Vector3& target_position) const noexcept { const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale; const auto delta = target_position - projectile.m_origin; @@ -60,7 +59,7 @@ namespace omath::projectile_prediction bool ProjPredEngineLegacy::is_projectile_reached_target(const Vector3& target_position, const Projectile& projectile, const float pitch, - const float time) const + const float time) const noexcept { const auto yaw = projectile.m_origin.view_angle_to(target_position).y; const auto projectile_position = projectile.predict_position(pitch, yaw, time, m_gravity_constant); diff --git a/source/projectile_prediction/projectile.cpp b/source/projectile_prediction/projectile.cpp index 30202db..c37151f 100644 --- a/source/projectile_prediction/projectile.cpp +++ b/source/projectile_prediction/projectile.cpp @@ -8,7 +8,7 @@ namespace omath::projectile_prediction { Vector3 Projectile::predict_position(const float pitch, const float yaw, const float time, - const float gravity) const + const float gravity) const noexcept { auto current_pos = m_origin + source_engine::forward_vector({source_engine::PitchAngle::from_degrees(-pitch), From 5489c296e9342717d2134c445f045a6a0dc23b3e Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 5 May 2025 02:24:23 +0300 Subject: [PATCH 5/5] added more noexcept --- include/omath/pathfinding/a_star.hpp | 6 +++--- include/omath/pathfinding/navigation_mesh.hpp | 8 ++++---- source/pathfinding/a_star.cpp | 6 +++--- source/pathfinding/navigation_mesh.cpp | 9 +++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/omath/pathfinding/a_star.hpp b/include/omath/pathfinding/a_star.hpp index ba5041d..d894e76 100644 --- a/include/omath/pathfinding/a_star.hpp +++ b/include/omath/pathfinding/a_star.hpp @@ -15,16 +15,16 @@ namespace omath::pathfinding public: [[nodiscard]] static std::vector> find_path(const Vector3& start, const Vector3& end, - const NavigationMesh& nav_mesh); + const NavigationMesh& nav_mesh) noexcept; private: [[nodiscard]] static std::vector> reconstruct_final_path(const std::unordered_map, PathNode>& closed_list, - const Vector3& current); + const Vector3& current) noexcept; [[nodiscard]] static auto get_perfect_node(const std::unordered_map, PathNode>& open_list, - const Vector3& end_vertex); + const Vector3& end_vertex) noexcept; }; } // namespace omath::pathfinding diff --git a/include/omath/pathfinding/navigation_mesh.hpp b/include/omath/pathfinding/navigation_mesh.hpp index 588681b..75ba634 100644 --- a/include/omath/pathfinding/navigation_mesh.hpp +++ b/include/omath/pathfinding/navigation_mesh.hpp @@ -20,17 +20,17 @@ namespace omath::pathfinding { public: [[nodiscard]] - std::expected, std::string> get_closest_vertex(const Vector3& point) const; + std::expected, std::string> get_closest_vertex(const Vector3& point) const noexcept; [[nodiscard]] - const std::vector>& get_neighbors(const Vector3& vertex) const; + const std::vector>& get_neighbors(const Vector3& vertex) const noexcept; [[nodiscard]] bool empty() const; - [[nodiscard]] std::vector serialize() const; + [[nodiscard]] std::vector serialize() const noexcept; - void deserialize(const std::vector& raw); + void deserialize(const std::vector& raw) noexcept; std::unordered_map, std::vector>> m_vertex_map; }; diff --git a/source/pathfinding/a_star.cpp b/source/pathfinding/a_star.cpp index 593c907..bcd7348 100644 --- a/source/pathfinding/a_star.cpp +++ b/source/pathfinding/a_star.cpp @@ -17,7 +17,7 @@ namespace omath::pathfinding std::vector> Astar::reconstruct_final_path(const std::unordered_map, PathNode>& closed_list, - const Vector3& current) + const Vector3& current) noexcept { std::vector> path; std::optional current_opt = current; @@ -38,7 +38,7 @@ namespace omath::pathfinding return path; } auto Astar::get_perfect_node(const std::unordered_map, PathNode>& open_list, - const Vector3& end_vertex) + const Vector3& end_vertex) noexcept { return std::ranges::min_element(open_list, [&end_vertex](const auto& a, const auto& b) @@ -50,7 +50,7 @@ namespace omath::pathfinding } std::vector> Astar::find_path(const Vector3& start, const Vector3& end, - const NavigationMesh& nav_mesh) + const NavigationMesh& nav_mesh) noexcept { std::unordered_map, PathNode> closed_list; std::unordered_map, PathNode> open_list; diff --git a/source/pathfinding/navigation_mesh.cpp b/source/pathfinding/navigation_mesh.cpp index 97c7dc1..b2a831b 100644 --- a/source/pathfinding/navigation_mesh.cpp +++ b/source/pathfinding/navigation_mesh.cpp @@ -6,7 +6,8 @@ #include namespace omath::pathfinding { - std::expected, std::string> NavigationMesh::get_closest_vertex(const Vector3& point) const + std::expected, std::string> + NavigationMesh::get_closest_vertex(const Vector3& point) const noexcept { const auto res = std::ranges::min_element(m_vertex_map, [&point](const auto& a, const auto& b) { return a.first.distance_to(point) < b.first.distance_to(point); }); @@ -17,7 +18,7 @@ namespace omath::pathfinding return res->first; } - const std::vector>& NavigationMesh::get_neighbors(const Vector3& vertex) const + const std::vector>& NavigationMesh::get_neighbors(const Vector3& vertex) const noexcept { return m_vertex_map.at(vertex); } @@ -27,7 +28,7 @@ namespace omath::pathfinding return m_vertex_map.empty(); } - std::vector NavigationMesh::serialize() const + std::vector NavigationMesh::serialize() const noexcept { auto dump_to_vector = [](const T& t, std::vector& vec) { @@ -50,7 +51,7 @@ namespace omath::pathfinding return raw; } - void NavigationMesh::deserialize(const std::vector& raw) + void NavigationMesh::deserialize(const std::vector& raw) noexcept { auto load_from_vector = [](const std::vector& vec, size_t& offset, auto& value) {