Files
ViewDesignEngine/tests/core/test_line.cpp
T
茂之钳 4eb4f00c57
Build & Test / build-and-test (push) Has been cancelled
VDE Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
test: max coverage — 10 new + 11 expanded test files, 140+ cases
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)
2026-08-02 16:32:36 +08:00

82 lines
3.1 KiB
C++

#include <gtest/gtest.h>
#include "vde/core/line.h"
#include "vde/core/point.h"
#include <cmath>
using namespace vde::core;
// ═══════════════════════════════════════════════════════════
// Line3D
// ═══════════════════════════════════════════════════════════
TEST(Line3DTest, DefaultConstructor_XAxis) {
Line3Dd line;
EXPECT_DOUBLE_EQ(line.origin().x(), 0.0);
EXPECT_DOUBLE_EQ(line.origin().y(), 0.0);
EXPECT_DOUBLE_EQ(line.origin().z(), 0.0);
EXPECT_DOUBLE_EQ(line.direction().x(), 1.0);
EXPECT_DOUBLE_EQ(line.direction().y(), 0.0);
EXPECT_DOUBLE_EQ(line.direction().z(), 0.0);
}
TEST(Line3DTest, DirectionIsNormalized) {
Line3Dd line(Point3D(1, 2, 3), Vector3D(0, 5, 0));
EXPECT_NEAR(line.direction().norm(), 1.0, 1e-9);
EXPECT_NEAR(line.direction().y(), 1.0, 1e-9);
}
TEST(Line3DTest, PointAt_Parametric) {
Line3Dd line(Point3D(1, 2, 3), Vector3D(0, 0, 1));
Point3D p = line.point_at(5.0);
EXPECT_NEAR(p.x(), 1.0, 1e-9);
EXPECT_NEAR(p.y(), 2.0, 1e-9);
EXPECT_NEAR(p.z(), 8.0, 1e-9);
}
// ═══════════════════════════════════════════════════════════
// Segment3D
// ═══════════════════════════════════════════════════════════
TEST(Segment3DTest, DefaultConstructor_ZeroLength) {
Segment3Dd seg;
EXPECT_DOUBLE_EQ(seg.length(), 0.0);
}
TEST(Segment3DTest, Length_345Triangle) {
Segment3Dd seg(Point3D(0, 0, 0), Point3D(3, 4, 0));
EXPECT_NEAR(seg.length(), 5.0, 1e-9);
}
TEST(Segment3DTest, Direction_NotNormalized) {
Segment3Dd seg(Point3D(0, 0, 0), Point3D(3, 4, 0));
EXPECT_NEAR(seg.direction().x(), 3.0, 1e-9);
EXPECT_NEAR(seg.direction().y(), 4.0, 1e-9);
}
TEST(Segment3DTest, Endpoints_Accessible) {
Segment3Dd seg(Point3D(1, 2, 3), Point3D(4, 5, 6));
EXPECT_NEAR(seg.p0().x(), 1.0, 1e-9);
EXPECT_NEAR(seg.p1().x(), 4.0, 1e-9);
}
// ═══════════════════════════════════════════════════════════
// Ray3D
// ═══════════════════════════════════════════════════════════
TEST(Ray3DTest, DefaultConstructor) {
Ray3Dd ray;
EXPECT_DOUBLE_EQ(ray.origin().x(), 0.0);
EXPECT_DOUBLE_EQ(ray.direction().x(), 1.0);
}
TEST(Ray3DTest, DirectionIsNormalized) {
Ray3Dd ray(Point3D(1, 2, 3), Vector3D(1, 1, 1));
EXPECT_NEAR(ray.direction().norm(), 1.0, 1e-9);
}
TEST(Ray3DTest, PointAt_NonNegative) {
Ray3Dd ray(Point3D(0, 0, 0), Vector3D(0, 1, 0));
Point3D p = ray.point_at(10.0);
EXPECT_NEAR(p.y(), 10.0, 1e-9);
}