Compare commits

..

3 Commits

Author SHA1 Message Date
aae22f5af9 added more constexpr 2026-04-30 05:38:20 +03:00
fa4e2b1d94 update 2026-04-30 05:35:17 +03:00
7e55b1d00e code clean up 2026-04-30 02:15:02 +03:00
6 changed files with 15 additions and 56 deletions

View File

@@ -130,7 +130,6 @@ namespace omath
return x * other.x + y * other.y; return x * other.x + y * other.y;
} }
#ifndef _MSC_VER
[[nodiscard]] constexpr Type length() const noexcept [[nodiscard]] constexpr Type length() const noexcept
{ {
return std::hypot(this->x, this->y); return std::hypot(this->x, this->y);
@@ -141,18 +140,6 @@ namespace omath
const Type len = length(); const Type len = length();
return len > 0.f ? *this / len : *this; return len > 0.f ? *this / len : *this;
} }
#else
[[nodiscard]] Type length() const noexcept
{
return std::hypot(x, y);
}
[[nodiscard]] Vector2 normalized() const noexcept
{
const Type len = length();
return len > static_cast<Type>(0) ? *this / len : *this;
}
#endif
[[nodiscard]] constexpr Type length_sqr() const noexcept [[nodiscard]] constexpr Type length_sqr() const noexcept
{ {
return x * x + y * y; return x * x + y * y;

View File

@@ -129,7 +129,6 @@ namespace omath
return Vector2<Type>::dot(other) + z * other.z; return Vector2<Type>::dot(other) + z * other.z;
} }
#ifndef _MSC_VER
[[nodiscard]] constexpr Type length() const [[nodiscard]] constexpr Type length() const
{ {
return std::hypot(this->x, this->y, z); return std::hypot(this->x, this->y, z);
@@ -149,29 +148,6 @@ namespace omath
return length_value != 0 ? *this / length_value : *this; return length_value != 0 ? *this / length_value : *this;
} }
#else
[[nodiscard]] Type length() const noexcept
{
return std::hypot(this->x, this->y, z);
}
[[nodiscard]] Vector3 normalized() const noexcept
{
const Type len = this->length();
return len != static_cast<Type>(0) ? *this / len : *this;
}
[[nodiscard]] Type length_2d() const noexcept
{
return Vector2<Type>::length();
}
[[nodiscard]] Type distance_to(const Vector3& v_other) const noexcept
{
return (*this - v_other).length();
}
#endif
[[nodiscard]] constexpr Type length_sqr() const noexcept [[nodiscard]] constexpr Type length_sqr() const noexcept
{ {

View File

@@ -70,31 +70,31 @@ namespace omath
} }
[[nodiscard]] [[nodiscard]]
Type sin() const noexcept constexpr Type sin() const noexcept
{ {
return std::sin(as_radians()); return std::sin(as_radians());
} }
[[nodiscard]] [[nodiscard]]
Type cos() const noexcept constexpr Type cos() const noexcept
{ {
return std::cos(as_radians()); return std::cos(as_radians());
} }
[[nodiscard]] [[nodiscard]]
Type tan() const noexcept constexpr Type tan() const noexcept
{ {
return std::tan(as_radians()); return std::tan(as_radians());
} }
[[nodiscard]] [[nodiscard]]
Type atan() const noexcept constexpr Type atan() const noexcept
{ {
return std::atan(as_radians()); return std::atan(as_radians());
} }
[[nodiscard]] [[nodiscard]]
Type cot() const noexcept constexpr Type cot() const noexcept
{ {
return cos() / sin(); return cos() / sin();
} }

View File

@@ -24,7 +24,7 @@ namespace omath::angles
template<class Type> template<class Type>
requires std::is_floating_point_v<Type> requires std::is_floating_point_v<Type>
[[nodiscard]] Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect) noexcept [[nodiscard]] constexpr Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect) noexcept
{ {
const auto fov_rad = degrees_to_radians(horizontal_fov); const auto fov_rad = degrees_to_radians(horizontal_fov);
@@ -35,7 +35,7 @@ namespace omath::angles
template<class Type> template<class Type>
requires std::is_floating_point_v<Type> requires std::is_floating_point_v<Type>
[[nodiscard]] Type vertical_fov_to_horizontal(const Type& vertical_fov, const Type& aspect) noexcept [[nodiscard]] constexpr 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 fov_as_radians = degrees_to_radians(vertical_fov);
@@ -47,7 +47,7 @@ namespace omath::angles
template<class Type> template<class Type>
requires std::is_arithmetic_v<Type> requires std::is_arithmetic_v<Type>
[[nodiscard]] Type wrap_angle(const Type& angle, const Type& min, const Type& max) noexcept [[nodiscard]] constexpr Type wrap_angle(const Type& angle, const Type& min, const Type& max) noexcept
{ {
if (angle <= max && angle >= min) if (angle <= max && angle >= min)
return angle; return angle;

View File

@@ -44,18 +44,16 @@ namespace omath::iw_engine
// aspect ratio. // aspect ratio.
// vfov = 2 · atan( tan(hfov_4:3 / 2) / (4/3) ) // vfov = 2 · atan( tan(hfov_4:3 / 2) / (4/3) )
constexpr float k_source_reference_aspect = 4.f / 3.f; constexpr float k_source_reference_aspect = 4.f / 3.f;
const float half_hfov_4_3 = angles::degrees_to_radians(field_of_view) / 2.f; const auto vertical_fov = angles::horizontal_fov_to_vertical(field_of_view, k_source_reference_aspect);
const float vfov_deg = angles::radians_to_degrees(
2.f * std::atan(std::tan(half_hfov_4_3) / k_source_reference_aspect));
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE) if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed< return mat_perspective_left_handed<
float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>( float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
vfov_deg, aspect_ratio, near, far); vertical_fov, aspect_ratio, near, far);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE) if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed< return mat_perspective_left_handed<
float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>( float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
vfov_deg, aspect_ratio, near, far); vertical_fov, aspect_ratio, near, far);
std::unreachable(); std::unreachable();
}; };
} // namespace omath::iw_engine } // namespace omath::iw_engine

View File

@@ -44,18 +44,16 @@ namespace omath::source_engine
// aspect ratio. // aspect ratio.
// vfov = 2 · atan( tan(hfov_4:3 / 2) / (4/3) ) // vfov = 2 · atan( tan(hfov_4:3 / 2) / (4/3) )
constexpr float k_source_reference_aspect = 4.f / 3.f; constexpr float k_source_reference_aspect = 4.f / 3.f;
const float half_hfov_4_3 = angles::degrees_to_radians(field_of_view) / 2.f; const auto vertical_fov = angles::horizontal_fov_to_vertical(field_of_view, k_source_reference_aspect);
const float vfov_deg = angles::radians_to_degrees(
2.f * std::atan(std::tan(half_hfov_4_3) / k_source_reference_aspect));
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE) if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed< return mat_perspective_left_handed<
float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>( float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
vfov_deg, aspect_ratio, near, far); vertical_fov, aspect_ratio, near, far);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE) if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed< return mat_perspective_left_handed<
float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>( float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
vfov_deg, aspect_ratio, near, far); vertical_fov, aspect_ratio, near, far);
std::unreachable(); std::unreachable();
} }
} // namespace omath::source_engine } // namespace omath::source_engine