Files
ViewDesignEngine/tests/brep/test_measure.cpp
T
茂之钳 12db7d3e5a
CI / Build & Test (push) Failing after 1m31s
CI / Release Build (push) Failing after 31s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
feat(v3.5): perf caching + measure + flange/gear + feature tree + assembly constraints
2026-07-24 14:02:24 +00:00

99 lines
4.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <gtest/gtest.h>
#include "vde/brep/brep.h"
#include "vde/brep/modeling.h"
#include "vde/brep/measure.h"
#include <cmath>
using namespace vde::brep;
using namespace vde::core;
// ═══════════════════════════════════════════════════════════
// Volume measurements
// ═══════════════════════════════════════════════════════════
TEST(MeasureTest, Volume_UnitBox) {
// 2×2×2 box centered at origin → volume = 8.0
auto box = make_box(2, 2, 2);
double vol = volume(box);
EXPECT_NEAR(vol, 8.0, 0.2) << "Volume of 2×2×2 box should be ~8.0";
}
TEST(MeasureTest, Volume_LargeBox) {
auto box = make_box(10, 5, 3); // volume = 150
double vol = volume(box);
EXPECT_NEAR(vol, 150.0, 1.0) << "Volume of 10×5×3 box should be ~150";
}
// ═══════════════════════════════════════════════════════════
// Surface area measurements
// ═══════════════════════════════════════════════════════════
TEST(MeasureTest, SurfaceArea_UnitBox) {
// 2×2×2 box: 6 faces × 4 = 24.0
auto box = make_box(2, 2, 2);
double area = surface_area(box);
EXPECT_NEAR(area, 24.0, 0.5) << "Surface area of 2×2×2 box should be ~24.0";
}
TEST(MeasureTest, SurfaceArea_LargeBox) {
auto box = make_box(10, 5, 3);
double area = surface_area(box);
double expected = 2.0 * (10*5 + 10*3 + 5*3); // 190
EXPECT_NEAR(area, expected, 2.0) << "Surface area of 10×5×3 box should be ~" << expected;
}
// ═══════════════════════════════════════════════════════════
// Centroid measurements
// ═══════════════════════════════════════════════════════════
TEST(MeasureTest, Centroid_BoxAtOrigin) {
auto box = make_box(2, 2, 2);
auto c = centroid(box);
EXPECT_NEAR(c.x(), 0.0, 0.01);
EXPECT_NEAR(c.y(), 0.0, 0.01);
EXPECT_NEAR(c.z(), 0.0, 0.01);
}
// ═══════════════════════════════════════════════════════════
// Distance measurements
// ═══════════════════════════════════════════════════════════
TEST(MeasureTest, Distance_SeparatedBoxes) {
auto box1 = make_box(1, 1, 1); // centered at origin, half-size 0.5
// We can't easily translate boxes, but make_box creates centered boxes
// so we test two boxes at origin — they overlap
auto box2 = make_box(1, 1, 1);
double d = distance(box1, box2);
// Two identical boxes at origin → overlap → distance ≈ 0
EXPECT_NEAR(d, 0.0, 0.1) << "Overlapping boxes should have distance ~0";
}
TEST(MeasureTest, Distance_OverlappingBoxes) {
auto box1 = make_box(2, 2, 2);
auto box2 = make_box(2, 2, 2);
double d = distance(box1, box2);
// Overlapping boxes
EXPECT_NEAR(d, 0.0, 0.1) << "Overlapping boxes should have distance ~0";
}
// ═══════════════════════════════════════════════════════════
// Integration: volume + surface area consistency
// ═══════════════════════════════════════════════════════════
TEST(MeasureTest, Volume_NonNegative) {
auto box = make_box(2, 2, 2);
EXPECT_GE(volume(box), 0.0);
}
TEST(MeasureTest, SurfaceArea_NonNegative) {
auto box = make_box(2, 2, 2);
EXPECT_GE(surface_area(box), 0.0);
}
TEST(MeasureTest, Distance_NonNegative) {
auto box1 = make_box(1, 1, 1);
auto box2 = make_box(1, 1, 1);
EXPECT_GE(distance(box1, box2), 0.0);
}