New tests: plane/line/topology_compression/serializer/memory_pool/ interval/format_utils/sat/ray_intersect/tri_intersect Expanded: quality_feedback/gdt/validate/interference/motion/ explode/convex_hull/distance/polygon/transaction/sdf Total test files: 162 → 172 (+10)
64 lines
2.3 KiB
C++
64 lines
2.3 KiB
C++
#include <gtest/gtest.h>
|
|
#include "vde/core/plane.h"
|
|
#include "vde/core/point.h"
|
|
#include <cmath>
|
|
|
|
using namespace vde::core;
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// Plane construction
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
TEST(PlaneTest, DefaultConstructor_XYPlane) {
|
|
Plane3D p;
|
|
EXPECT_DOUBLE_EQ(p.normal().x(), 0.0);
|
|
EXPECT_DOUBLE_EQ(p.normal().y(), 0.0);
|
|
EXPECT_DOUBLE_EQ(p.normal().z(), 1.0);
|
|
EXPECT_NEAR(p.normal().norm(), 1.0, 1e-9);
|
|
}
|
|
|
|
TEST(PlaneTest, PointNormalConstructor_NormalIsUnit) {
|
|
Plane3D p(Point3D(1, 2, 3), Vector3D(0, 0, 5));
|
|
EXPECT_NEAR(p.normal().norm(), 1.0, 1e-9);
|
|
EXPECT_NEAR(p.normal().z(), 1.0, 1e-9);
|
|
}
|
|
|
|
TEST(PlaneTest, ThreePointConstructor_ContainsPoints) {
|
|
Plane3D p(Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(0, 1, 0));
|
|
EXPECT_NEAR(p.signed_distance(Point3D(0, 0, 0)), 0.0, 1e-9);
|
|
EXPECT_NEAR(p.signed_distance(Point3D(1, 0, 0)), 0.0, 1e-9);
|
|
EXPECT_NEAR(p.signed_distance(Point3D(0, 1, 0)), 0.0, 1e-9);
|
|
}
|
|
|
|
TEST(PlaneTest, SignedDistance_PositiveInNormalDirection) {
|
|
Plane3D p(Point3D(0, 0, 0), Vector3D(0, 0, 1));
|
|
EXPECT_NEAR(p.signed_distance(Point3D(0, 0, 5)), 5.0, 1e-9);
|
|
EXPECT_NEAR(p.signed_distance(Point3D(0, 0, -5)), -5.0, 1e-9);
|
|
}
|
|
|
|
TEST(PlaneTest, Distance_AbsoluteValue) {
|
|
Plane3D p(Point3D(0, 0, 0), Vector3D(0, 0, 1));
|
|
EXPECT_NEAR(p.distance(Point3D(0, 0, 5)), 5.0, 1e-9);
|
|
EXPECT_NEAR(p.distance(Point3D(0, 0, -5)), 5.0, 1e-9);
|
|
}
|
|
|
|
TEST(PlaneTest, Project_OnPlane) {
|
|
Plane3D p(Point3D(0, 0, 0), Vector3D(0, 0, 1));
|
|
Point3D proj = p.project(Point3D(3, 4, 10));
|
|
EXPECT_NEAR(proj.x(), 3.0, 1e-9);
|
|
EXPECT_NEAR(proj.y(), 4.0, 1e-9);
|
|
EXPECT_NEAR(proj.z(), 0.0, 1e-9);
|
|
EXPECT_NEAR(p.signed_distance(proj), 0.0, 1e-9);
|
|
}
|
|
|
|
TEST(PlaneTest, D_Value_OriginOffset) {
|
|
Plane3D p(Point3D(0, 0, 5), Vector3D(0, 0, 1));
|
|
EXPECT_NEAR(p.d(), -5.0, 1e-9);
|
|
}
|
|
|
|
TEST(PlaneTest, ThreePoint_NonColinear) {
|
|
Plane3D p(Point3D(1, 0, 0), Point3D(0, 1, 0), Point3D(0, 0, 1));
|
|
EXPECT_NEAR(p.normal().norm(), 1.0, 1e-9);
|
|
EXPECT_NEAR(p.signed_distance(Point3D(0, 0, 0)), p.d(), 1e-9);
|
|
}
|