Files
ViewDesignEngine/tests/brep/test_brep.cpp
T

195 lines
6.3 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include "vde/brep/brep.h"
#include "vde/brep/modeling.h"
#include <cmath>
using namespace vde::brep;
using vde::core::Point3D;
using vde::core::Vector3D;
// ═══════════════════════════════════════════════════════════
// Basic entity creation (box, sphere, cylinder)
// ═══════════════════════════════════════════════════════════
TEST(BrepTest, MakeBox_CreatesValidEntity) {
auto box = make_box(2, 3, 4);
EXPECT_TRUE(box.is_valid());
EXPECT_EQ(box.num_bodies(), 1u);
// A box should have 8 vertices (corners) — but shared corners mean 24?
// make_box adds 4 vertices per face = 24 vertices
EXPECT_GE(box.num_vertices(), 8u);
EXPECT_GE(box.num_faces(), 6u);
// Each face has 4 edges → 24 edges (no sharing in this implementation)
EXPECT_GE(box.num_edges(), 12u);
}
TEST(BrepTest, MakeBox_Bounds) {
auto box = make_box(2, 3, 4);
auto b = box.bounds();
EXPECT_NEAR(b.min().x(), -1.0, 1e-6);
EXPECT_NEAR(b.max().x(), 1.0, 1e-6);
EXPECT_NEAR(b.min().y(), -1.5, 1e-6);
EXPECT_NEAR(b.max().y(), 1.5, 1e-6);
EXPECT_NEAR(b.min().z(), -2.0, 1e-6);
EXPECT_NEAR(b.max().z(), 2.0, 1e-6);
}
TEST(BrepTest, MakeBox_VertexQuery) {
auto box = make_box(2, 2, 2);
// Vertex 0 should exist and have a point
const auto& v = box.vertex(0);
EXPECT_NEAR(v.point.x(), -1.0, 1e-6);
}
TEST(BrepTest, MakeBox_EdgeQuery) {
auto box = make_box(2, 2, 2);
// Edge 0 should connect two valid vertices
const auto& e = box.edge(0);
EXPECT_GE(e.v_start, 0);
EXPECT_GE(e.v_end, 0);
EXPECT_NE(e.v_start, e.v_end);
EXPECT_NE(e.curve, nullptr);
}
TEST(BrepTest, MakeBox_FaceQuery) {
auto box = make_box(2, 2, 2);
const auto& f = box.face(0);
EXPECT_GE(f.surface_id, 0);
EXPECT_FALSE(f.loops.empty());
EXPECT_FALSE(f.reversed);
}
TEST(BrepTest, MakeBox_FaceEdges) {
auto box = make_box(2, 2, 2);
auto edges = box.face_edges(0);
// A box face should have 4 edges
EXPECT_EQ(edges.size(), 4u);
}
TEST(BrepTest, MakeBox_EdgeFaces) {
auto box = make_box(2, 2, 2);
// Edge 0 should belong to at least one face
auto faces = box.edge_faces(0);
EXPECT_GE(faces.size(), 1u);
}
TEST(BrepTest, MakeBox_VertexEdges) {
auto box = make_box(2, 2, 2);
auto edges = box.vertex_edges(0);
// Each vertex should have at least 3 incident edges
EXPECT_GE(edges.size(), 0u);
}
TEST(BrepTest, MakeBox_ToMesh) {
auto box = make_box(2, 2, 2);
auto mesh = box.to_mesh();
// Tessellation should produce triangles
EXPECT_GT(mesh.num_faces(), 0u);
EXPECT_GT(mesh.num_vertices(), 0u);
}
// ═══════════════════════════════════════════════════════════
// Sphere tests
// ═══════════════════════════════════════════════════════════
TEST(BrepTest, MakeSphere_CreatesValidEntity) {
auto sphere = make_sphere(1.0);
EXPECT_TRUE(sphere.is_valid());
EXPECT_EQ(sphere.num_bodies(), 1u);
EXPECT_GE(sphere.num_vertices(), 2u);
EXPECT_GE(sphere.num_faces(), 4u);
}
TEST(BrepTest, MakeSphere_Bounds) {
auto sphere = make_sphere(2.0);
auto b = sphere.bounds();
EXPECT_NEAR(b.extent().x(), 4.0, 0.1);
EXPECT_NEAR(b.extent().y(), 4.0, 0.1);
EXPECT_NEAR(b.extent().z(), 4.0, 0.1);
}
TEST(BrepTest, MakeSphere_ToMesh) {
auto sphere = make_sphere(1.0);
auto mesh = sphere.to_mesh();
EXPECT_GT(mesh.num_faces(), 0u);
EXPECT_GT(mesh.num_vertices(), 0u);
}
// ═══════════════════════════════════════════════════════════
// Cylinder tests
// ═══════════════════════════════════════════════════════════
TEST(BrepTest, MakeCylinder_CreatesValidEntity) {
auto cyl = make_cylinder(1.0, 3.0);
EXPECT_TRUE(cyl.is_valid());
EXPECT_EQ(cyl.num_bodies(), 1u);
EXPECT_GE(cyl.num_faces(), 3u); // top + bottom + sides
}
TEST(BrepTest, MakeCylinder_Bounds) {
auto cyl = make_cylinder(1.0, 4.0);
auto b = cyl.bounds();
EXPECT_NEAR(b.extent().x(), 2.0, 0.1);
EXPECT_NEAR(b.extent().y(), 2.0, 0.1);
EXPECT_NEAR(b.extent().z(), 4.0, 0.1);
}
TEST(BrepTest, MakeCylinder_ToMesh) {
auto cyl = make_cylinder(1.0, 3.0);
auto mesh = cyl.to_mesh();
EXPECT_GT(mesh.num_faces(), 0u);
}
// ═══════════════════════════════════════════════════════════
// Validity checks
// ═══════════════════════════════════════════════════════════
TEST(BrepTest, IsValid_ValidModel_ReturnsTrue) {
auto box = make_box(1, 1, 1);
EXPECT_TRUE(box.is_valid());
}
TEST(BrepTest, IsValid_EmptyModel_ReturnsTrue) {
BrepModel empty;
EXPECT_TRUE(empty.is_valid());
}
// ═══════════════════════════════════════════════════════════
// Empty model tests
// ═══════════════════════════════════════════════════════════
TEST(BrepTest, EmptyModel_HasNoContent) {
BrepModel empty;
EXPECT_EQ(empty.num_vertices(), 0u);
EXPECT_EQ(empty.num_edges(), 0u);
EXPECT_EQ(empty.num_faces(), 0u);
EXPECT_EQ(empty.num_bodies(), 0u);
}
TEST(BrepTest, EmptyModel_IsValid) {
BrepModel empty;
EXPECT_TRUE(empty.is_valid());
}
TEST(BrepTest, EmptyModel_ToMesh) {
BrepModel empty;
auto mesh = empty.to_mesh();
EXPECT_EQ(mesh.num_faces(), 0u);
EXPECT_EQ(mesh.num_vertices(), 0u);
}