Feature/more constexpr (#125)

* added constexpr

* fix

* improved stuff

* added const

* improvement

* fix

* fix

* patch
This commit is contained in:
2025-12-24 02:32:14 +03:00
committed by GitHub
parent 897484bea1
commit d935caf1a4
36 changed files with 543 additions and 399 deletions

View File

@@ -23,7 +23,7 @@ TEST(SimplexExtra, HandleLine_CollinearProducesPerp)
EXPECT_TRUE(std::isfinite(dir.x));
EXPECT_TRUE(std::isfinite(dir.y));
EXPECT_TRUE(std::isfinite(dir.z));
auto zero = Vector3<float>{0.f, 0.f, 0.f};
constexpr auto zero = Vector3<float>{0.f, 0.f, 0.f};
EXPECT_FALSE(dir == zero);
// Ensure direction is (approximately) perpendicular to ab
@@ -89,23 +89,23 @@ TEST(SimplexExtra, HandleTetrahedron_InsideReturnsTrue)
TEST(SimplexMore, PushFrontAndAccess)
{
omath::collision::Simplex<omath::Vector3<float>> s;
s.push_front(omath::Vector3<float>{1.f,0.f,0.f});
s.push_front(omath::Vector3<float>{2.f,0.f,0.f});
s.push_front(omath::Vector3<float>{3.f,0.f,0.f});
s.push_front(omath::Vector3<float>{1.f, 0.f, 0.f});
s.push_front(omath::Vector3<float>{2.f, 0.f, 0.f});
s.push_front(omath::Vector3<float>{3.f, 0.f, 0.f});
EXPECT_EQ(s.size(), 3u);
omath::Vector3<float> exp_front{3.f,0.f,0.f};
omath::Vector3<float> exp_back{1.f,0.f,0.f};
constexpr omath::Vector3<float> exp_front{3.f, 0.f, 0.f};
constexpr omath::Vector3<float> exp_back{1.f, 0.f, 0.f};
EXPECT_TRUE(s.front() == exp_front);
EXPECT_TRUE(s.back() == exp_back);
auto d = s.data();
const auto d = s.data();
EXPECT_TRUE(d[0] == exp_front);
}
TEST(SimplexMore, ClearAndEmpty)
{
omath::collision::Simplex<omath::Vector3<float>> s;
s.push_front(omath::Vector3<float>{1.f,1.f,1.f});
s.push_front(omath::Vector3<float>{1.f, 1.f, 1.f});
EXPECT_FALSE(s.empty());
s.clear();
EXPECT_TRUE(s.empty());
@@ -114,8 +114,8 @@ TEST(SimplexMore, ClearAndEmpty)
TEST(SimplexMore, HandleLineCollinearProducesPerp)
{
omath::collision::Simplex<omath::Vector3<float>> s;
s = { omath::Vector3<float>{2.f,0.f,0.f}, omath::Vector3<float>{1.f,0.f,0.f} };
omath::Vector3<float> dir{0.f,0.f,0.f};
s = {omath::Vector3<float>{2.f, 0.f, 0.f}, omath::Vector3<float>{1.f, 0.f, 0.f}};
omath::Vector3<float> dir{0.f, 0.f, 0.f};
const bool res = s.handle(dir);
EXPECT_FALSE(res);
EXPECT_GT(dir.length_sqr(), 0.0f);
@@ -123,15 +123,15 @@ TEST(SimplexMore, HandleLineCollinearProducesPerp)
TEST(SimplexMore, HandleTriangleFlipWinding)
{
const omath::Vector3<float> a{1.f,0.f,0.f};
const omath::Vector3<float> b{0.f,1.f,0.f};
const omath::Vector3<float> c{0.f,0.f,1.f};
constexpr omath::Vector3<float> a{1.f, 0.f, 0.f};
constexpr omath::Vector3<float> b{0.f, 1.f, 0.f};
constexpr omath::Vector3<float> c{0.f, 0.f, 1.f};
omath::collision::Simplex<omath::Vector3<float>> s;
s = { a, b, c };
omath::Vector3<float> dir{0.f,0.f,0.f};
s = {a, b, c};
omath::Vector3<float> dir{0.f, 0.f, 0.f};
const auto ab = b - a;
const auto ac = c - a;
constexpr auto ab = b - a;
constexpr auto ac = c - a;
const auto abc = ab.cross(ac);
const bool res = s.handle(dir);
@@ -145,8 +145,9 @@ TEST(SimplexMore, HandleTriangleFlipWinding)
TEST(SimplexMore, HandleTetrahedronInsideTrue)
{
omath::collision::Simplex<omath::Vector3<float>> s;
s = { omath::Vector3<float>{1.f,0.f,0.f}, omath::Vector3<float>{0.f,1.f,0.f}, omath::Vector3<float>{0.f,0.f,1.f}, omath::Vector3<float>{-1.f,-1.f,-1.f} };
omath::Vector3<float> dir{0.f,0.f,0.f};
s = {omath::Vector3<float>{1.f, 0.f, 0.f}, omath::Vector3<float>{0.f, 1.f, 0.f},
omath::Vector3<float>{0.f, 0.f, 1.f}, omath::Vector3<float>{-1.f, -1.f, -1.f}};
omath::Vector3<float> dir{0.f, 0.f, 0.f};
const bool inside = s.handle(dir);
EXPECT_TRUE(inside);
}
@@ -154,8 +155,8 @@ TEST(SimplexMore, HandleTetrahedronInsideTrue)
TEST(SimplexMore, HandlePointSetsDirection)
{
omath::collision::Simplex<omath::Vector3<float>> s;
s = { omath::Vector3<float>{1.f,2.f,3.f} };
omath::Vector3<float> dir{0.f,0.f,0.f};
s = {omath::Vector3<float>{1.f, 2.f, 3.f}};
omath::Vector3<float> dir{0.f, 0.f, 0.f};
EXPECT_FALSE(s.handle(dir));
EXPECT_NEAR(dir.x, -1.f, 1e-6f);
EXPECT_NEAR(dir.y, -2.f, 1e-6f);
@@ -165,8 +166,8 @@ TEST(SimplexMore, HandlePointSetsDirection)
TEST(SimplexMore, HandleLineReducesToPointWhenAoOpposite)
{
omath::collision::Simplex<omath::Vector3<float>> s;
s = { omath::Vector3<float>{1.f,0.f,0.f}, omath::Vector3<float>{2.f,0.f,0.f} };
omath::Vector3<float> dir{0.f,0.f,0.f};
s = {omath::Vector3<float>{1.f, 0.f, 0.f}, omath::Vector3<float>{2.f, 0.f, 0.f}};
omath::Vector3<float> dir{0.f, 0.f, 0.f};
EXPECT_FALSE(s.handle(dir));
EXPECT_EQ(s.size(), 1u);
EXPECT_NEAR(dir.x, -1.f, 1e-6f);