mirror of
https://github.com/orange-cpp/omath.git
synced 2026-06-12 02:04:35 +00:00
added mat tests and triangle tests
This commit is contained in:
@@ -1,11 +1,25 @@
|
||||
// UnitTestMat.cpp
|
||||
#include "omath/linear_algebra/mat.hpp"
|
||||
#include "omath/linear_algebra/vector3.hpp"
|
||||
#include "omath/trigonometry/angle.hpp"
|
||||
#include "omath/trigonometry/angles.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace omath;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
namespace
|
||||
{
|
||||
using Pitch = Angle<float, static_cast<float>(-90), static_cast<float>(90), AngleFlags::Clamped>;
|
||||
|
||||
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;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
class UnitTestMat : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
@@ -522,4 +536,48 @@ TEST(UnitTestMatStandalone, MatOrthoNegativeOneToOneDefault)
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(-1.f, 1.f, -1.f, 1.f, 0.1f, 100.f);
|
||||
|
||||
EXPECT_EQ(ortho_default, ortho_explicit);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr auto scale = mat_extract_scale(mat_scale(Vector3{2.0f, 3.0f, 4.0f}));
|
||||
return close_to(scale.x, 2.0f, 1e-5f) && close_to(scale.y, 3.0f, 1e-5f) && close_to(scale.z, 4.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat scale extraction should be constexpr with gcem");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr auto rotation = mat_rotation_axis_z<float>(Pitch::from_degrees(90.0f));
|
||||
return close_to(rotation.at(0, 0), 0.0f, 1e-5f) && close_to(rotation.at(0, 1), -1.0f, 1e-5f)
|
||||
&& close_to(rotation.at(1, 0), 1.0f, 1e-5f) && close_to(rotation.at(1, 1), 0.0f, 1e-5f)
|
||||
&& close_to(rotation.at(2, 2), 1.0f, 1e-5f) && close_to(rotation.at(3, 3), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat rotation should be constexpr with gcem");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr auto projection =
|
||||
mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(90.0f, 1.0f, 1.0f, 11.0f);
|
||||
return close_to(projection.at(0, 0), 1.0f, 1e-5f) && close_to(projection.at(1, 1), 1.0f, 1e-5f)
|
||||
&& close_to(projection.at(2, 2), 1.1f, 1e-5f) && close_to(projection.at(2, 3), -1.1f, 1e-5f)
|
||||
&& close_to(projection.at(3, 2), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat vertical-FOV perspective should be constexpr with gcem");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr auto projection =
|
||||
mat_perspective_right_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(90.0f, 2.0f, 1.0f, 11.0f);
|
||||
return close_to(projection.at(0, 0), 1.0f, 1e-5f) && close_to(projection.at(1, 1), 2.0f, 1e-5f)
|
||||
&& close_to(projection.at(2, 2), -1.1f, 1e-5f) && close_to(projection.at(2, 3), -1.1f, 1e-5f)
|
||||
&& close_to(projection.at(3, 2), -1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat horizontal-FOV perspective should be constexpr with gcem");
|
||||
#endif
|
||||
|
||||
@@ -8,6 +8,17 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
namespace
|
||||
{
|
||||
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;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
class UnitTestTriangle : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
@@ -129,3 +140,20 @@ TEST_F(UnitTestTriangle, MidPoint)
|
||||
EXPECT_FLOAT_EQ(mid2.y, (2.0f + 5.0f + 8.0f) / 3.0f);
|
||||
EXPECT_FLOAT_EQ(mid2.z, (3.0f + 6.0f + 9.0f) / 3.0f);
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr Triangle<Vector3<float>> triangle{{3.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 4.0f, 0.0f}};
|
||||
constexpr auto normal = triangle.calculate_normal();
|
||||
constexpr auto mid_point = triangle.mid_point();
|
||||
|
||||
return close_to(triangle.side_a_length(), 3.0f, 1e-5f) && close_to(triangle.side_b_length(), 4.0f, 1e-5f)
|
||||
&& close_to(triangle.hypot(), 5.0f, 1e-5f) && triangle.is_rectangular()
|
||||
&& close_to(normal.length(), 1.0f, 1e-5f) && close_to(normal.z, -1.0f, 1e-5f)
|
||||
&& close_to(mid_point.x, 1.0f, 1e-5f) && close_to(mid_point.y, 4.0f / 3.0f, 1e-5f)
|
||||
&& close_to(mid_point.z, 0.0f, 1e-5f);
|
||||
}(),
|
||||
"Triangle helpers should be constexpr with gcem");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user