Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/omath/3d_primitives/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ namespace omath::primitives
[[nodiscard]]
std::array<Triangle<Vector3<float>>, 12> create_box(const Vector3<float>& top, const Vector3<float>& bottom,
const Vector3<float>& dir_forward, const Vector3<float>& dir_right,
float ratio = 4.f);
float ratio = 4.f) noexcept;
}
36 changes: 18 additions & 18 deletions include/omath/angle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Type>(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);
Expand All @@ -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)};
Expand All @@ -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};
}
Expand Down
14 changes: 7 additions & 7 deletions include/omath/angles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ namespace omath::angles
{
template<class Type>
requires std::is_floating_point_v<Type>
[[nodiscard]] constexpr Type radians_to_degrees(const Type& radians)
[[nodiscard]] constexpr Type radians_to_degrees(const Type& radians) noexcept
{
return radians * (static_cast<Type>(180) / std::numbers::pi_v<Type>);
}

template<class Type>
requires std::is_floating_point_v<Type>
[[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<Type> / static_cast<Type>(180));
}

template<class Type>
requires std::is_floating_point_v<Type>
[[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);

Expand All @@ -35,19 +35,19 @@ namespace omath::angles

template<class Type>
requires std::is_floating_point_v<Type>
[[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<Type>(2) * std::atan(std::tan(fov_as_radians / static_cast<Type>(2)) * aspect);
const auto horizontal_fov =
static_cast<Type>(2) * std::atan(std::tan(fov_as_radians / static_cast<Type>(2)) * aspect);

return radians_to_degrees(horizontal_fov);
}

template<class Type>
requires std::is_arithmetic_v<Type>
[[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;
Expand Down
8 changes: 4 additions & 4 deletions include/omath/collision/line_tracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ namespace omath::collision
bool infinite_length = false;

[[nodiscard]]
Vector3<float> direction_vector() const;
Vector3<float> direction_vector() const noexcept;

[[nodiscard]]
Vector3<float> direction_vector_normalized() const;
Vector3<float> direction_vector_normalized() const noexcept;
};
class LineTracer
{
public:
LineTracer() = delete;

[[nodiscard]]
static bool can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle);
static bool can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& 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<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle);
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept;
};
} // namespace omath::collision
22 changes: 11 additions & 11 deletions include/omath/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ namespace omath
class Color final : public Vector4<float>
{
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{};

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -120,35 +120,35 @@ 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;

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

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

*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);
Expand Down
4 changes: 2 additions & 2 deletions include/omath/engines/iw_engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace omath::iw_engine
void look_at(const Vector3<float>& 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
4 changes: 2 additions & 2 deletions include/omath/engines/opengl_engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace omath::opengl_engine
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
void look_at(const Vector3<float>& 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
12 changes: 6 additions & 6 deletions include/omath/engines/opengl_engine/formulas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
namespace omath::opengl_engine
{
[[nodiscard]]
Vector3<float> forward_vector(const ViewAngles& angles);
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;

[[nodiscard]]
Vector3<float> right_vector(const ViewAngles& angles);
Vector3<float> right_vector(const ViewAngles& angles) noexcept;

[[nodiscard]]
Vector3<float> up_vector(const ViewAngles& angles);
Vector3<float> up_vector(const ViewAngles& angles) noexcept;

[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& 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
4 changes: 2 additions & 2 deletions include/omath/engines/source_engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace omath::source_engine
void look_at(const Vector3<float>& 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
12 changes: 6 additions & 6 deletions include/omath/engines/source_engine/formulas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
namespace omath::source_engine
{
[[nodiscard]]
Vector3<float> forward_vector(const ViewAngles& angles);
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;

[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles);
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;

[[nodiscard]]
Vector3<float> right_vector(const ViewAngles& angles);
Vector3<float> right_vector(const ViewAngles& angles) noexcept;

[[nodiscard]]
Vector3<float> up_vector(const ViewAngles& angles);
Vector3<float> up_vector(const ViewAngles& angles) noexcept;

[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& 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
4 changes: 2 additions & 2 deletions include/omath/engines/unity_engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace omath::unity_engine
void look_at(const Vector3<float>& 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
Loading