75 lines
2.7 KiB
C++
75 lines
2.7 KiB
C++
/**
|
||
* @file test_tolerance_chain.cpp
|
||
* @brief VDE B-5:公差链分析(线性 / 角度 / 并联)
|
||
*/
|
||
#include <gtest/gtest.h>
|
||
|
||
#include "vde/brep/dimension_api.h"
|
||
|
||
#include <cmath>
|
||
#include <vector>
|
||
|
||
using namespace vde;
|
||
|
||
namespace {
|
||
|
||
brep::ToleranceChainLink link(double nominal, double tu, double tl, int dir) {
|
||
brep::ToleranceChainLink l;
|
||
l.nominal = nominal;
|
||
l.tolerance_upper = tu;
|
||
l.tolerance_lower = tl;
|
||
l.direction = dir;
|
||
return l;
|
||
}
|
||
|
||
} // namespace
|
||
|
||
TEST(DraftingB5Test, ToleranceChain_Linear_Exact) {
|
||
// 10±0.1(增) + 20±0.2(增) − 5±0.05(减) → 封闭环 25,上/下偏差 0.35
|
||
std::vector<brep::ToleranceChainLink> links{
|
||
link(10.0, 0.1, 0.1, +1), link(20.0, 0.2, 0.2, +1),
|
||
link(5.0, 0.05, 0.05, -1)};
|
||
const auto r = brep::analyze_linear_chain(links, 25.35, 24.65);
|
||
EXPECT_NEAR(r.closure_nominal, 25.0, 1e-12);
|
||
EXPECT_NEAR(r.closure_upper_dev, 0.35, 1e-12);
|
||
EXPECT_NEAR(r.closure_lower_dev, -0.35, 1e-12);
|
||
EXPECT_NEAR(r.closure_max, 25.35, 1e-12);
|
||
EXPECT_NEAR(r.closure_min, 24.65, 1e-12);
|
||
EXPECT_TRUE(r.within_tolerance);
|
||
EXPECT_GE(r.satisfy_rate, 0.99);
|
||
EXPECT_TRUE(r.violations.empty());
|
||
|
||
const auto bad = brep::analyze_linear_chain(links, 25.2, 24.8);
|
||
EXPECT_FALSE(bad.within_tolerance);
|
||
EXPECT_FALSE(bad.violations.empty());
|
||
}
|
||
|
||
TEST(DraftingB5Test, ToleranceChain_Angular_Exact) {
|
||
std::vector<brep::ToleranceChainLink> links{
|
||
link(30.0, 0.01, 0.01, +1), link(45.0, 0.02, 0.02, +1)};
|
||
const auto r = brep::analyze_angular_chain(links, 75.03, 74.97);
|
||
EXPECT_NEAR(r.closure_nominal, 75.0, 1e-12);
|
||
EXPECT_NEAR(r.closure_upper_dev, 0.03, 1e-12);
|
||
EXPECT_NEAR(r.closure_lower_dev, -0.03, 1e-12);
|
||
EXPECT_TRUE(r.within_tolerance);
|
||
EXPECT_FALSE(brep::analyze_angular_chain(links, 75.01, 74.99)
|
||
.within_tolerance);
|
||
}
|
||
|
||
TEST(DraftingB5Test, ToleranceChain_Parallel_Exact) {
|
||
std::vector<brep::ToleranceChainLink> pa{link(5.0, 0.1, 0.05, +1),
|
||
link(3.0, 0.05, 0.05, +1)};
|
||
std::vector<brep::ToleranceChainLink> pb{link(4.0, 0.05, 0.05, +1)};
|
||
const auto r = brep::analyze_parallel_chain(pa, pb, 1.0, 0.05, 0.05, 1.30,
|
||
0.70);
|
||
const double expected_upper = 0.05 + (0.1 + 0.05 + 0.05);
|
||
const double expected_lower = -(0.05 + (0.1 + 0.05 + 0.05));
|
||
EXPECT_NEAR(r.closure_nominal, 1.0, 1e-12);
|
||
EXPECT_NEAR(r.closure_upper_dev, expected_upper, 1e-12);
|
||
EXPECT_NEAR(r.closure_lower_dev, expected_lower, 1e-12);
|
||
EXPECT_TRUE(r.within_tolerance);
|
||
const auto bad =
|
||
brep::analyze_parallel_chain(pa, pb, 1.0, 0.0, 0.0, 1.10, 0.90);
|
||
EXPECT_FALSE(bad.within_tolerance);
|
||
}
|