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);