mirror of
https://gitlab.com/splashmapper/splash.git
synced 2026-02-12 15:00:52 +01:00
82 lines
2.5 KiB
C++
82 lines
2.5 KiB
C++
#include <doctest.h>
|
|
|
|
#include "./graphics/camera.h"
|
|
|
|
using namespace Splash;
|
|
|
|
/*************/
|
|
TEST_CASE("Testing Camera::checkPointsCoplanar with coplanar points")
|
|
{
|
|
// Test case: 3 points forming a plane (e.g., a triangle)
|
|
std::vector<glm::dvec3> points = {
|
|
{0.0, 0.0, 0.0},
|
|
{1.0, 0.0, 0.0},
|
|
{0.0, 1.0, 0.0}
|
|
};
|
|
|
|
// Expected: coplanar with small tolerance
|
|
CHECK(Camera::checkPointsCoplanar(points, 0.1f));
|
|
CHECK(Camera::checkPointsCoplanar(points, 0.01f));
|
|
}
|
|
|
|
/*************/
|
|
TEST_CASE("Testing Camera::checkPointsCoplanar with non-coplanar points")
|
|
{
|
|
// Test case: 4 points forming a tetrahedron (non-coplanar)
|
|
std::vector<glm::dvec3> points = {
|
|
{0.0, 0.0, 0.0},
|
|
{1.0, 0.0, 0.0},
|
|
{0.0, 1.0, 0.0},
|
|
{0.0, 0.0, 1.0}
|
|
};
|
|
|
|
// Should fail with any reasonable tolerance
|
|
CHECK_FALSE(Camera::checkPointsCoplanar(points, 0.1f));
|
|
CHECK_FALSE(Camera::checkPointsCoplanar(points, 0.01f));
|
|
}
|
|
|
|
/*************/
|
|
TEST_CASE("Testing Camera::checkPointsCoplanar with edge cases")
|
|
{
|
|
// Case 1: Fewer than 3 points
|
|
std::vector<glm::dvec3> points1 = {{0.0, 0.0, 0.0}};
|
|
CHECK_FALSE(Camera::checkPointsCoplanar(points1, 0.1f));
|
|
|
|
std::vector<glm::dvec3> points2 = {{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}};
|
|
CHECK_FALSE(Camera::checkPointsCoplanar(points2, 0.1f));
|
|
|
|
// Case 2: All points are collinear (should still be coplanar, but normal is undefined)
|
|
std::vector<glm::dvec3> points3 = {
|
|
{0.0, 0.0, 0.0},
|
|
{1.0, 0.0, 0.0},
|
|
{2.0, 0.0, 0.0}
|
|
};
|
|
CHECK(Camera::checkPointsCoplanar(points3, 0.1f)); // Coplanar (in a plane), but normal may be unstable
|
|
|
|
// Case 3: Degenerate (all points same)
|
|
std::vector<glm::dvec3> points4 = {
|
|
{0.0, 0.0, 0.0},
|
|
{0.0, 0.0, 0.0},
|
|
{0.0, 0.0, 0.0}
|
|
};
|
|
CHECK_FALSE(Camera::checkPointsCoplanar(points4, 0.1f));
|
|
}
|
|
|
|
/*************/
|
|
TEST_CASE("Testing Camera::checkPointsCoplanar with noisy 4-point set and tolerance")
|
|
{
|
|
// Define a base plane with noise to each point
|
|
std::vector<glm::dvec3> noisyPoints = {
|
|
{0.0 + 0.01, 0.0 + 0.01, 0.0 - 0.02},
|
|
{1.0 - 0.01, 0.0 + 0.01, 0.0 - 0.02},
|
|
{0.0 + 0.01, 1.0 - 0.01, 0.0 + 0.02},
|
|
{1.0 + 0.01, 1.0 - 0.01, 0.0 - 0.02}
|
|
};
|
|
|
|
// Test with tolerance = 10% of diameter (should pass)
|
|
CHECK(Camera::checkPointsCoplanar(noisyPoints, 0.1));
|
|
|
|
// Test with tolerance = 0.1% of diameter (should fail)
|
|
CHECK_FALSE(Camera::checkPointsCoplanar(noisyPoints, 0.001));
|
|
}
|