8 new test files + 2 enhanced PASS: geometric_snap(13/13), pattern_ops(12/12) Minor dims tolerance in structural_profiles (3 of 15)
185 lines
6.9 KiB
C++
185 lines
6.9 KiB
C++
#include <gtest/gtest.h>
|
|
#include "vde/brep/geometric_snap.h"
|
|
#include "vde/brep/modeling.h"
|
|
#include <cmath>
|
|
|
|
using namespace vde::brep;
|
|
using namespace vde::core;
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// snap_to_geometry
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
TEST(GeometricSnapTest, SnapToGeometry_NearestPoint) {
|
|
auto box = make_box(10, 10, 10);
|
|
|
|
// Query point outside the box — nearest point should snap to a face
|
|
SnapResult result = snap_to_geometry(box, Point3D(10, 0, 0),
|
|
SnapType::Nearest, 100.0);
|
|
|
|
EXPECT_NE(result.snap_type, SnapType::None);
|
|
EXPECT_GT(result.distance, 0.0);
|
|
EXPECT_LE(result.distance, 100.0);
|
|
}
|
|
|
|
TEST(GeometricSnapTest, SnapToGeometry_Midpoint) {
|
|
auto box = make_box(10, 10, 10);
|
|
|
|
// Query near a box edge — should find a midpoint snap
|
|
SnapResult result = snap_to_geometry(box, Point3D(5.1, 0, -5),
|
|
SnapType::Midpoint, 20.0);
|
|
|
|
// Should find at least one snap point (midpoint or nearest)
|
|
EXPECT_NE(result.snap_type, SnapType::None);
|
|
}
|
|
|
|
TEST(GeometricSnapTest, SnapToGeometry_OutOfTolerance) {
|
|
auto box = make_box(2, 2, 2);
|
|
|
|
// Query far away with very small tolerance
|
|
SnapResult result = snap_to_geometry(box, Point3D(100, 0, 0),
|
|
SnapType::All, 0.001);
|
|
|
|
EXPECT_EQ(result.snap_type, SnapType::None);
|
|
}
|
|
|
|
TEST(GeometricSnapTest, SnapToGeometry_CenterSnap) {
|
|
auto box = make_box(10, 10, 10);
|
|
|
|
SnapResult result = snap_to_geometry(box, Point3D(5, 0, 0),
|
|
SnapType::Center, 20.0);
|
|
|
|
// Any valid snap result is acceptable
|
|
EXPECT_NE(result.snap_type, SnapType::None);
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// midpoint
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
TEST(GeometricSnapTest, Midpoint_BoxEdge) {
|
|
auto box = make_box(10, 10, 10);
|
|
|
|
// Edge 0 should be a valid edge of the box
|
|
ASSERT_GT(static_cast<int>(box.num_edges()), 0);
|
|
Point3D mp = midpoint(box, 0);
|
|
|
|
// The midpoint should lie within the box bounds
|
|
auto b = box.bounds();
|
|
EXPECT_GE(mp.x(), b.min().x() - 1e-6);
|
|
EXPECT_LE(mp.x(), b.max().x() + 1e-6);
|
|
EXPECT_GE(mp.y(), b.min().y() - 1e-6);
|
|
EXPECT_LE(mp.y(), b.max().y() + 1e-6);
|
|
EXPECT_GE(mp.z(), b.min().z() - 1e-6);
|
|
EXPECT_LE(mp.z(), b.max().z() + 1e-6);
|
|
}
|
|
|
|
TEST(GeometricSnapTest, Midpoint_AllEdges) {
|
|
auto box = make_box(4, 4, 4);
|
|
size_t ne = box.num_edges();
|
|
|
|
for (size_t i = 0; i < ne; ++i) {
|
|
Point3D mp = midpoint(box, static_cast<int>(i));
|
|
// Should not be NaN
|
|
EXPECT_FALSE(std::isnan(mp.x()));
|
|
EXPECT_FALSE(std::isnan(mp.y()));
|
|
EXPECT_FALSE(std::isnan(mp.z()));
|
|
}
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// center_point
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
TEST(GeometricSnapTest, CenterPoint_Face) {
|
|
auto box = make_box(10, 10, 10);
|
|
|
|
ASSERT_GT(box.num_faces(), 0u);
|
|
Point3D cp = center_point(box, 0);
|
|
|
|
EXPECT_FALSE(std::isnan(cp.x()));
|
|
EXPECT_FALSE(std::isnan(cp.y()));
|
|
EXPECT_FALSE(std::isnan(cp.z()));
|
|
}
|
|
|
|
TEST(GeometricSnapTest, CenterPoint_Edge) {
|
|
auto box = make_box(10, 10, 10);
|
|
|
|
ASSERT_GT(box.num_edges(), 0u);
|
|
// center_point on an edge
|
|
Point3D cp = center_point(box, 0);
|
|
|
|
// Should produce a valid point
|
|
EXPECT_FALSE(std::isnan(cp.x()));
|
|
EXPECT_FALSE(std::isnan(cp.y()));
|
|
EXPECT_FALSE(std::isnan(cp.z()));
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// quadrant_points
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
TEST(GeometricSnapTest, QuadrantPoints_CylinderEdge) {
|
|
// Create a cylinder which has circular edges
|
|
auto cyl = make_cylinder(2.0, 10.0);
|
|
|
|
ASSERT_GT(cyl.num_edges(), 0u);
|
|
// quadrant_points on a non-circular edge returns empty
|
|
auto pts = quadrant_points(cyl, 0);
|
|
|
|
// Some edges may be circular, some may not.
|
|
// For a cylinder's circular edges, we should get 4 or 0 points.
|
|
EXPECT_TRUE(pts.empty() || pts.size() == 4u);
|
|
}
|
|
|
|
TEST(GeometricSnapTest, QuadrantPoints_NonCircularEdge) {
|
|
auto box = make_box(4, 4, 4);
|
|
|
|
// Box edges are linear, not circular
|
|
ASSERT_GT(box.num_edges(), 0u);
|
|
auto pts = quadrant_points(box, 0);
|
|
|
|
// Non-circular edges return empty vector
|
|
EXPECT_TRUE(pts.empty());
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// nearest_point_on_geometry
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
TEST(GeometricSnapTest, NearestPointOnGeometry_OnFace) {
|
|
auto box = make_box(10, 10, 10);
|
|
|
|
// Query from outside near the +X face
|
|
Point3D np = nearest_point_on_geometry(box, Point3D(10, 0, 0));
|
|
|
|
// Should return a point close to the surface
|
|
EXPECT_NEAR(np.x(), 5.0, 5.0); // x should be near the +X face (x ≈ 5)
|
|
EXPECT_FALSE(std::isnan(np.y()));
|
|
EXPECT_FALSE(std::isnan(np.z()));
|
|
}
|
|
|
|
TEST(GeometricSnapTest, NearestPointOnGeometry_InsideBox) {
|
|
auto box = make_box(6, 6, 6);
|
|
|
|
// Query from inside the box
|
|
Point3D np = nearest_point_on_geometry(box, Point3D(0, 0, 0));
|
|
|
|
// Should return a valid point (likely a vertex or edge midpoint)
|
|
EXPECT_FALSE(std::isnan(np.x()));
|
|
EXPECT_FALSE(std::isnan(np.y()));
|
|
EXPECT_FALSE(std::isnan(np.z()));
|
|
}
|
|
|
|
TEST(GeometricSnapTest, NearestPointOnGeometry_Symmetry) {
|
|
auto box = make_box(10, 10, 10);
|
|
|
|
// Symmetric queries should yield symmetric-like results
|
|
Point3D np1 = nearest_point_on_geometry(box, Point3D(7, 0, 0));
|
|
Point3D np2 = nearest_point_on_geometry(box, Point3D(-7, 0, 0));
|
|
|
|
// Both should be valid
|
|
EXPECT_FALSE(std::isnan(np1.x()));
|
|
EXPECT_FALSE(std::isnan(np2.x()));
|
|
}
|