mirror of
https://github.com/orange-cpp/omath.git
synced 2026-06-12 02:04:35 +00:00
now add constexpr gcem tests for triangle and mat classes
This commit is contained in:
@@ -622,10 +622,14 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||||
[[nodiscard("You must use extracted scale")]]
|
[[nodiscard("You must use extracted scale")]]
|
||||||
Vector3<Type> mat_extract_scale(const Mat<4, 4, Type, St>& mat) noexcept
|
OMATH_CONSTEXPR Vector3<Type> mat_extract_scale(const Mat<4, 4, Type, St>& mat) noexcept
|
||||||
{
|
{
|
||||||
auto column_length = [](const Type x, const Type y, const Type z) {
|
auto column_length = [](const Type x, const Type y, const Type z) {
|
||||||
|
#ifdef OMATH_CONSTEXPR
|
||||||
|
return static_cast<Type>(gcem::sqrt(x * x + y * y + z * z));
|
||||||
|
#else
|
||||||
return static_cast<Type>(std::sqrt(x * x + y * y + z * z));
|
return static_cast<Type>(std::sqrt(x * x + y * y + z * z));
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto scale_x = column_length(mat.at(0, 0), mat.at(1, 0), mat.at(2, 0));
|
const auto scale_x = column_length(mat.at(0, 0), mat.at(1, 0), mat.at(2, 0));
|
||||||
@@ -635,9 +639,16 @@ namespace omath
|
|||||||
constexpr auto epsilon = std::numeric_limits<Type>::epsilon();
|
constexpr auto epsilon = std::numeric_limits<Type>::epsilon();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
#ifdef OMATH_CONSTEXPR
|
||||||
|
gcem::abs(scale_x) < epsilon ? Type{1} : scale_x,
|
||||||
|
gcem::abs(scale_y) < epsilon ? Type{1} : scale_y,
|
||||||
|
gcem::abs(scale_z) < epsilon ? Type{1} : scale_z,
|
||||||
|
#else
|
||||||
std::abs(scale_x) < epsilon ? Type{1} : scale_x,
|
std::abs(scale_x) < epsilon ? Type{1} : scale_x,
|
||||||
std::abs(scale_y) < epsilon ? Type{1} : scale_y,
|
std::abs(scale_y) < epsilon ? Type{1} : scale_y,
|
||||||
std::abs(scale_z) < epsilon ? Type{1} : scale_z,
|
std::abs(scale_z) < epsilon ? Type{1} : scale_z,
|
||||||
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,9 +665,15 @@ namespace omath
|
|||||||
const auto m22 = mat.at(2, 2) / scale.z;
|
const auto m22 = mat.at(2, 2) / scale.z;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
angles::radians_to_degrees(std::atan2(m21, m22)),
|
#ifdef OMATH_CONSTEXPR
|
||||||
|
angles::radians_to_degrees(gcem::atan2(m21, m22)),
|
||||||
|
angles::radians_to_degrees(gcem::asin(std::clamp(-m20, Type{-1}, Type{1}))),
|
||||||
|
angles::radians_to_degrees(gcem::atan2(m10, m00)),
|
||||||
|
#else
|
||||||
|
angles::radians_to_degrees(gc::atan2(m21, m22)),
|
||||||
angles::radians_to_degrees(std::asin(std::clamp(-m20, Type{-1}, Type{1}))),
|
angles::radians_to_degrees(std::asin(std::clamp(-m20, Type{-1}, Type{1}))),
|
||||||
angles::radians_to_degrees(std::atan2(m10, m00)),
|
angles::radians_to_degrees(std::atan2(m10, m00)),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "vector3.hpp"
|
#include "vector3.hpp"
|
||||||
|
#include "omath/internal/optional_constexpr_math.hpp"
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -40,13 +40,13 @@ namespace omath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector::ContainedType side_a_length() const
|
OMATH_CONSTEXPR Vector::ContainedType side_a_length() const
|
||||||
{
|
{
|
||||||
return m_vertex1.distance_to(m_vertex2);
|
return m_vertex1.distance_to(m_vertex2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector::ContainedType side_b_length() const
|
OMATH_CONSTEXPR Vector::ContainedType side_b_length() const
|
||||||
{
|
{
|
||||||
return m_vertex3.distance_to(m_vertex2);
|
return m_vertex3.distance_to(m_vertex2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
// Created by Orange on 11/30/2024.
|
// Created by Orange on 11/30/2024.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <omath/trigonometry/angle.hpp>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
|
#include <omath/trigonometry/angle.hpp>
|
||||||
|
|
||||||
using namespace omath;
|
using namespace omath;
|
||||||
|
|
||||||
@@ -19,6 +19,14 @@ namespace
|
|||||||
|
|
||||||
constexpr float k_eps = 1e-5f;
|
constexpr float k_eps = 1e-5f;
|
||||||
|
|
||||||
|
#ifdef OMATH_USE_GCEM
|
||||||
|
constexpr bool close_to(const float actual, const float expected, const float epsilon)
|
||||||
|
{
|
||||||
|
const float diff = actual - expected;
|
||||||
|
return (diff < 0.0f ? -diff : diff) <= epsilon;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// ---------- Construction / factories ----------
|
// ---------- Construction / factories ----------
|
||||||
@@ -190,3 +198,11 @@ TEST(UnitTestAngle, BinaryMinus_ReturnsWrappedDiff)
|
|||||||
const Deg c = a - b; // expect 340°
|
const Deg c = a - b; // expect 340°
|
||||||
EXPECT_FLOAT_EQ(c.as_degrees(), 340.0f);
|
EXPECT_FLOAT_EQ(c.as_degrees(), 340.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OMATH_USE_GCEM
|
||||||
|
static_assert(close_to(Pitch::from_degrees(0.0f).sin(), 0.0f, k_eps), "Sin should be constexpr with gcem");
|
||||||
|
static_assert(close_to(Pitch::from_degrees(0.0f).cos(), 1.0f, k_eps), "Cos should be constexpr with gcem");
|
||||||
|
static_assert(close_to(Pitch::from_degrees(45.0f).tan(), 1.0f, 1e-4f), "Tan should be constexpr with gcem");
|
||||||
|
static_assert(close_to(Pitch::from_degrees(45.0f).cot(), 1.0f, 1e-4f), "Cot should be constexpr with gcem");
|
||||||
|
static_assert(close_to(Pitch::from_degrees(45.0f).atan(), 0.66577375f, 1e-6f), "Atan should be constexpr with gcem");
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user