feat(v10): tolerant modeling + Class-A deep + hex mesh + constraint solver + drawing standards
v10.1 — Tolerant Modeling (对标 Parasolid): - tolerant_modeling.h/.cpp: TolerantVertex/Edge, merge_within_tolerance (BFS) - gap_bridging (free edge detection → triangle filling) - overlap_resolution (normal+centroid+AABB detection) - tolerant_boolean (heal→degenerate detect→boolean→heal) + BooleanDiagnostic - import_heal_pipeline (STEP one-shot repair) - ssi_boolean enhanced: coplanar/collinear/tangent detection, GMP on all classify paths - step_import enhanced: broken file recovery, non-standard entity mapping, diagnostic report - 30 tests, 4112 total lines v10.2 — Class-A Deep + Hex Mesh (对标 CGM + ANSYS): - class_a_surfacing enhanced: g3_blend_with_constraints, surface_energy_minimization - curvature_continuity_optimization, reflection_line_discontinuity (+720 lines) - fea_mesh enhanced: mapped_hex, submapped_hex, multi_block_hex (TFI), hex_quality_optimization (+522 lines) - 22 tests v10.3 — Constraint Solver + Drawing Standards (对标 D-Cubed + AutoCAD): - constraint_solver enhanced: DOFAnalyzer, RedundancyDetector, ConstraintPropagator, KinematicChainSolver - drawing_standards.h/.cpp: IsoStandard (ISO 128/129), AnsiStandard (ASME Y14.5), JisStandard (JIS B 0001) - 12 tests 12 files, ~5000 lines, 64 tests. Target: 87% → 93%
This commit is contained in:
@@ -41,3 +41,4 @@ add_vde_test(test_advanced_healing)
|
||||
add_vde_test(test_assembly_patterns)
|
||||
add_vde_test(test_sheet_metal)
|
||||
add_vde_test(test_quality_feedback)
|
||||
add_vde_test(test_tolerant_modeling)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "vde/brep/constraint_solver.h"
|
||||
#include "vde/brep/drawing_standards.h"
|
||||
#include "vde/brep/modeling.h"
|
||||
#include "vde/core/transform.h"
|
||||
#include "vde/core/aabb.h"
|
||||
@@ -698,3 +699,448 @@ TEST(ConstraintTypeTest, TypeNames) {
|
||||
EXPECT_STREQ(constraint_type_name(ConstraintType::Angle), "Angle");
|
||||
EXPECT_STREQ(constraint_type_name(ConstraintType::Parallel), "Parallel");
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
// DOFAnalyzer 详细测试
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
|
||||
TEST(DOFAnalyzerTest, SingleNodeFreeDirections) {
|
||||
Assembly assy("dof_detail");
|
||||
auto* box = assy.root.add_part("box", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("box", box);
|
||||
|
||||
DOFAnalyzer analyzer;
|
||||
auto results = analyzer.analyze(graph);
|
||||
|
||||
ASSERT_EQ(results.size(), 1u);
|
||||
EXPECT_EQ(results[0].translational_dof_remaining, 3);
|
||||
EXPECT_EQ(results[0].rotational_dof_remaining, 3);
|
||||
EXPECT_FALSE(results[0].is_fully_constrained);
|
||||
|
||||
auto dirs = analyzer.free_direction_names(graph, 0);
|
||||
EXPECT_EQ(dirs.size(), 6u); // 全部自由
|
||||
}
|
||||
|
||||
TEST(DOFAnalyzerTest, GlobalDofSummary) {
|
||||
Assembly assy("dof_global");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident}); // 3 DOF each
|
||||
graph.add_constraint({0, 1, ConstraintType::Concentric}); // 4 DOF each
|
||||
|
||||
DOFAnalyzer analyzer;
|
||||
auto summary = analyzer.global_dof_summary(graph);
|
||||
EXPECT_FALSE(summary.empty());
|
||||
// Both nodes should be over-constrained (3+4=7 > 6)
|
||||
auto results = analyzer.analyze(graph);
|
||||
EXPECT_TRUE(results[0].is_over_constrained);
|
||||
EXPECT_TRUE(results[1].is_over_constrained);
|
||||
}
|
||||
|
||||
TEST(DOFAnalyzerTest, PartiallyConstrainedDirections) {
|
||||
Assembly assy("dof_partial");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_constraint({0, 1, ConstraintType::Parallel}); // 2 rot DOF
|
||||
|
||||
DOFAnalyzer analyzer;
|
||||
auto results = analyzer.analyze(graph);
|
||||
|
||||
EXPECT_EQ(results[0].translational_dof_remaining, 3);
|
||||
EXPECT_EQ(results[0].rotational_dof_remaining, 1); // 3 - 2 = 1
|
||||
EXPECT_FALSE(results[0].is_fully_constrained);
|
||||
EXPECT_FALSE(results[0].summary.empty());
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
// RedundancyDetector 测试
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
|
||||
TEST(RedundancyDetectorTest, DetectsDuplicateConstraints) {
|
||||
Assembly assy("rd_dup");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident});
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident}); // duplicate
|
||||
|
||||
RedundancyDetector detector;
|
||||
auto suggestions = detector.detect(graph);
|
||||
EXPECT_GE(suggestions.size(), 1u);
|
||||
|
||||
bool found_dup = false;
|
||||
for (const auto& s : suggestions) {
|
||||
if (s.reason.find("Duplicate") != std::string::npos)
|
||||
found_dup = true;
|
||||
}
|
||||
EXPECT_TRUE(found_dup);
|
||||
}
|
||||
|
||||
TEST(RedundancyDetectorTest, DetectsOverConstrainedNode) {
|
||||
Assembly assy("rd_over");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
// Coincident(3) + Concentric(4) + Distance(1) = 8 > 6
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident});
|
||||
graph.add_constraint({0, 1, ConstraintType::Concentric});
|
||||
graph.add_constraint({0, 1, ConstraintType::Distance, 5.0});
|
||||
|
||||
RedundancyDetector detector;
|
||||
auto suggestions = detector.detect(graph);
|
||||
EXPECT_GE(suggestions.size(), 1u);
|
||||
}
|
||||
|
||||
TEST(RedundancyDetectorTest, DetectsConflictsParallelPerpendicular) {
|
||||
Assembly assy("rd_conflict");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_constraint({0, 1, ConstraintType::Parallel});
|
||||
graph.add_constraint({0, 1, ConstraintType::Perpendicular}); // 冲突!
|
||||
|
||||
RedundancyDetector detector;
|
||||
auto conflicts = detector.detect_conflicts(graph);
|
||||
EXPECT_GE(conflicts.size(), 1u);
|
||||
EXPECT_NE(conflicts[0].description.find("Conflict"), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(RedundancyDetectorTest, ReportGeneratesText) {
|
||||
Assembly assy("rd_report");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident});
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident});
|
||||
|
||||
RedundancyDetector detector;
|
||||
auto report = detector.report(graph);
|
||||
EXPECT_FALSE(report.empty());
|
||||
EXPECT_NE(report.find("Redundancy Report"), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(RedundancyDetectorTest, DetectForNodeFiltersCorrectly) {
|
||||
Assembly assy("rd_filter");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident});
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident});
|
||||
|
||||
RedundancyDetector detector;
|
||||
auto for_node = detector.detect_for_node(graph, 0);
|
||||
EXPECT_GE(for_node.size(), 1u);
|
||||
for (const auto& s : for_node) {
|
||||
EXPECT_EQ(s.node_index, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
// ConstraintPropagator 测试
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
|
||||
TEST(ConstraintPropagatorTest, PropagateModifiesConstraint) {
|
||||
Assembly assy("cp_prop");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
auto* c = assy.root.add_part("c", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_node("c", c);
|
||||
int ci = graph.add_constraint({0, 1, ConstraintType::Distance, 5.0});
|
||||
graph.add_constraint({1, 2, ConstraintType::Coincident});
|
||||
|
||||
ConstraintPropagator propagator;
|
||||
auto result = propagator.propagate(graph, assy, ci, 10.0,
|
||||
ConstraintType::Distance, nullptr);
|
||||
|
||||
EXPECT_TRUE(result.success);
|
||||
EXPECT_GE(result.affected_nodes.size(), 2u);
|
||||
EXPECT_GE(result.changes.size(), 1u);
|
||||
EXPECT_EQ(graph.constraint(ci).value, 10.0);
|
||||
}
|
||||
|
||||
TEST(ConstraintPropagatorTest, ComputeDependencyOrder) {
|
||||
Assembly assy("cp_order");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
auto* c = assy.root.add_part("c", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_node("c", c);
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident});
|
||||
graph.add_constraint({1, 2, ConstraintType::Coincident});
|
||||
|
||||
ConstraintPropagator propagator;
|
||||
auto order = propagator.compute_dependency_order(graph, 0);
|
||||
|
||||
EXPECT_GE(order.size(), 2u);
|
||||
EXPECT_EQ(order[0], 0); // 起始节点
|
||||
}
|
||||
|
||||
TEST(ConstraintPropagatorTest, DependencyDepth) {
|
||||
Assembly assy("cp_depth");
|
||||
auto* a = assy.root.add_part("a", make_box(2, 2, 2));
|
||||
auto* b = assy.root.add_part("b", make_box(2, 2, 2));
|
||||
auto* c = assy.root.add_part("c", make_box(2, 2, 2));
|
||||
|
||||
ConstraintGraph graph;
|
||||
graph.add_node("a", a);
|
||||
graph.add_node("b", b);
|
||||
graph.add_node("c", c);
|
||||
graph.add_constraint({0, 1, ConstraintType::Coincident});
|
||||
graph.add_constraint({1, 2, ConstraintType::Coincident});
|
||||
|
||||
ConstraintPropagator propagator;
|
||||
int depth = propagator.dependency_depth(graph, 0, 2);
|
||||
EXPECT_EQ(depth, 2); // a→b→c, 2 hops
|
||||
|
||||
int same = propagator.dependency_depth(graph, 0, 0);
|
||||
EXPECT_EQ(same, 0);
|
||||
|
||||
// In an unconnected subgraph (no node 3 exists — but negative test)
|
||||
int unreachable = propagator.dependency_depth(graph, 0, -1);
|
||||
EXPECT_EQ(unreachable, -1);
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
// KinematicChainSolver 测试
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
|
||||
TEST(KinematicChainTest, ForwardKinematicsIdentity) {
|
||||
Assembly assy("kc_fwd");
|
||||
KinematicChainSolver solver;
|
||||
|
||||
std::vector<ChainLink> links;
|
||||
std::vector<double> angles;
|
||||
|
||||
auto poses = solver.forward_kinematics(assy, links, angles);
|
||||
EXPECT_EQ(poses.size(), 1u); // Just identity
|
||||
}
|
||||
|
||||
TEST(KinematicChainTest, ForwardKinematics2Link) {
|
||||
Assembly assy("kc_fwd2");
|
||||
KinematicChainSolver solver;
|
||||
|
||||
std::vector<ChainLink> links = {
|
||||
{0, 1.0, 0.0, 0.0, "link1"},
|
||||
{1, 1.0, 0.0, 0.0, "link2"}
|
||||
};
|
||||
std::vector<double> angles = {0.0, M_PI / 2.0};
|
||||
|
||||
auto poses = solver.forward_kinematics(assy, links, angles);
|
||||
EXPECT_EQ(poses.size(), 3u); // identity + link1 + link2
|
||||
// Second link should extend in X+ then Y+ direction
|
||||
EXPECT_GT(poses.back()(0, 3), 0.9);
|
||||
EXPECT_GT(std::abs(poses.back()(1, 3)), 0.9);
|
||||
}
|
||||
|
||||
TEST(KinematicChainTest, InverseKinematicsReachable) {
|
||||
Assembly assy("kc_ik");
|
||||
KinematicChainSolver solver;
|
||||
|
||||
std::vector<ChainLink> links = {
|
||||
{0, 1.0, 0.0, 0.0, "link1"},
|
||||
{1, 1.0, 0.0, 0.0, "link2"}
|
||||
};
|
||||
|
||||
// Target at (0, 2) — reachable by 2 links of length 1
|
||||
core::Transform3D target = core::Transform3D::Identity();
|
||||
target.translation() = core::Vector3D(0.0, 2.0, 0.0);
|
||||
|
||||
auto angles = solver.inverse_kinematics(assy, links, target);
|
||||
EXPECT_EQ(angles.size(), 2u); // Should produce 2 angles
|
||||
}
|
||||
|
||||
TEST(KinematicChainTest, InverseKinematicsUnreachable) {
|
||||
Assembly assy("kc_ik_unreachable");
|
||||
KinematicChainSolver solver;
|
||||
|
||||
std::vector<ChainLink> links = {
|
||||
{0, 1.0, 0.0, 0.0, "link1"},
|
||||
{1, 1.0, 0.0, 0.0, "link2"}
|
||||
};
|
||||
|
||||
// Target at (0, 3) — unreachable (max reach = 2)
|
||||
core::Transform3D target = core::Transform3D::Identity();
|
||||
target.translation() = core::Vector3D(0.0, 3.0, 0.0);
|
||||
|
||||
auto angles = solver.inverse_kinematics(assy, links, target);
|
||||
EXPECT_TRUE(angles.empty()); // Unreachable
|
||||
}
|
||||
|
||||
TEST(KinematicChainTest, IsReachableCheck) {
|
||||
KinematicChainSolver solver;
|
||||
|
||||
std::vector<ChainLink> links = {
|
||||
{0, 1.0, 0.0, 0.0, "l1"},
|
||||
{1, 0.5, 0.0, 0.0, "l2"}
|
||||
};
|
||||
|
||||
core::Point3D near(1.0, 0.0, 0.0);
|
||||
EXPECT_TRUE(solver.is_reachable(links, near));
|
||||
|
||||
core::Point3D far(10.0, 0.0, 0.0);
|
||||
EXPECT_FALSE(solver.is_reachable(links, far));
|
||||
}
|
||||
|
||||
TEST(KinematicChainTest, DHTransformIdentity) {
|
||||
// DH transform with all zero params should give identity
|
||||
auto T = KinematicChainSolver::dh_transform(0.0, 0.0, 0.0, 0.0);
|
||||
// Not fully identity because DH includes rotation
|
||||
// At theta=0, should be I + translation on a=0
|
||||
core::Transform3D I = core::Transform3D::Identity();
|
||||
EXPECT_TRUE(T.isApprox(I, 1e-6));
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
// Drawing Standards 测试
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
|
||||
TEST(DrawingStandardsTest, IsoStandardCreatesValidStyle) {
|
||||
auto style = IsoStandard::create_style();
|
||||
|
||||
EXPECT_EQ(style.projection_angle, ProjectionAngle::FirstAngle);
|
||||
EXPECT_GT(style.text_height, 0.0);
|
||||
EXPECT_GT(style.line_width_thick, style.line_width_thin);
|
||||
EXPECT_EQ(style.text_font, FontStyle::Normal);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, AnsiStandardCreatesValidStyle) {
|
||||
auto style = AnsiStandard::create_style();
|
||||
|
||||
EXPECT_EQ(style.projection_angle, ProjectionAngle::ThirdAngle);
|
||||
EXPECT_GT(style.line_width_thick, 0.0);
|
||||
EXPECT_GT(style.arrow_length, 0.0);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, JisStandardCreatesValidStyle) {
|
||||
auto style = JisStandard::create_style();
|
||||
|
||||
EXPECT_EQ(style.projection_angle, ProjectionAngle::FirstAngle);
|
||||
EXPECT_GT(style.text_height, 0.0);
|
||||
EXPECT_EQ(style.cutting_plane, LineType::Chain); // JIS 特有
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, IsoLineWidthGroup) {
|
||||
EXPECT_NEAR(IsoStandard::line_width_group(2), 0.25, 1e-9);
|
||||
EXPECT_NEAR(IsoStandard::line_width_group(3), 0.35, 1e-9);
|
||||
EXPECT_NEAR(IsoStandard::line_width_group(4), 0.50, 1e-9);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, IsoLineTypeNames) {
|
||||
EXPECT_NE(IsoStandard::line_type_iso_name(LineType::Continuous).find("01"), std::string::npos);
|
||||
EXPECT_NE(IsoStandard::line_type_iso_name(LineType::Dashed).find("02"), std::string::npos);
|
||||
EXPECT_NE(IsoStandard::line_type_iso_name(LineType::Chain).find("04"), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, ApplyStandardByName) {
|
||||
std::vector<ProjectionView> views;
|
||||
StandardOptions opts;
|
||||
opts.paper_size = "A4";
|
||||
|
||||
auto ctx = drawing::apply_standard_by_name(views, "ISO", opts);
|
||||
EXPECT_EQ(ctx.standard_name, "ISO");
|
||||
EXPECT_EQ(ctx.view_projection, ProjectionAngle::FirstAngle);
|
||||
|
||||
auto ctx_ansi = drawing::apply_standard_by_name(views, "ANSI", opts);
|
||||
EXPECT_EQ(ctx_ansi.standard_name, "ANSI");
|
||||
EXPECT_EQ(ctx_ansi.view_projection, ProjectionAngle::ThirdAngle);
|
||||
|
||||
auto ctx_jis = drawing::apply_standard_by_name(views, "JIS", opts);
|
||||
EXPECT_EQ(ctx_jis.standard_name, "JIS");
|
||||
EXPECT_EQ(ctx_jis.view_projection, ProjectionAngle::FirstAngle);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, ValidateStyleWarnings) {
|
||||
auto style = IsoStandard::create_style();
|
||||
|
||||
auto warns = drawing::validate_style(style, "ISO");
|
||||
EXPECT_EQ(warns.size(), 0u); // Valid ISO style should have no warnings
|
||||
|
||||
// Test ANSI validation
|
||||
auto warns_ansi = drawing::validate_style(style, "ANSI");
|
||||
// Should warn about first-angle vs third-angle
|
||||
EXPECT_GE(warns_ansi.size(), 1u);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, AvailableStandards) {
|
||||
auto standards = drawing::available_standards();
|
||||
EXPECT_GE(standards.size(), 3u);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, StandardDescriptionsNotEmpty) {
|
||||
EXPECT_FALSE(IsoStandard::description().empty());
|
||||
EXPECT_FALSE(AnsiStandard::description().empty());
|
||||
EXPECT_FALSE(JisStandard::description().empty());
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, AnsiSymbolsAndFrameFormat) {
|
||||
auto symbols = AnsiStandard::gdt_symbols_summary();
|
||||
EXPECT_FALSE(symbols.empty());
|
||||
EXPECT_NE(symbols.find("位置度"), std::string::npos);
|
||||
|
||||
auto fcf = AnsiStandard::feature_control_frame_format();
|
||||
EXPECT_FALSE(fcf.empty());
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, JisPaperSize) {
|
||||
auto a4 = JisStandard::paper_size_spec("A4");
|
||||
EXPECT_NE(a4.find("210"), std::string::npos);
|
||||
EXPECT_NE(a4.find("297"), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, JisScales) {
|
||||
auto scales = JisStandard::preferred_scales();
|
||||
EXPECT_GE(scales.size(), 5u);
|
||||
EXPECT_DOUBLE_EQ(scales[0], 1.0);
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, ApplyStandardFunction) {
|
||||
std::vector<ProjectionView> views;
|
||||
auto style = IsoStandard::create_style();
|
||||
StandardOptions opts;
|
||||
opts.paper_size = "A3";
|
||||
|
||||
auto ctx = drawing::apply_standard(views, style, opts);
|
||||
EXPECT_EQ(ctx.style.projection_angle, ProjectionAngle::FirstAngle);
|
||||
EXPECT_EQ(ctx.options.paper_size, "A3");
|
||||
}
|
||||
|
||||
TEST(DrawingStandardsTest, LineTypeEnumValues) {
|
||||
// 验证所有线型枚举都有对应名称
|
||||
EXPECT_STREQ(line_type_name(LineType::Continuous), "Continuous");
|
||||
EXPECT_STREQ(line_type_name(LineType::Dashed), "Dashed");
|
||||
EXPECT_STREQ(line_type_name(LineType::Chain), "Chain");
|
||||
EXPECT_STREQ(line_type_name(LineType::DoubleChain), "DoubleChain");
|
||||
EXPECT_STREQ(line_type_name(LineType::Dotted), "Dotted");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "vde/brep/brep.h"
|
||||
#include "vde/brep/modeling.h"
|
||||
#include "vde/brep/brep_validate.h"
|
||||
#include "vde/brep/brep_heal.h"
|
||||
#include "vde/brep/tolerant_modeling.h"
|
||||
#include "vde/brep/tolerance.h"
|
||||
#include "vde/brep/ssi_boolean.h"
|
||||
#include "vde/brep/step_import.h"
|
||||
#include "vde/curves/nurbs_surface.h"
|
||||
#include "vde/core/point.h"
|
||||
|
||||
using namespace vde::brep;
|
||||
using namespace vde::core;
|
||||
using namespace vde::curves;
|
||||
|
||||
namespace {
|
||||
|
||||
/// Create a simple planar NURBS surface on the XY plane
|
||||
NurbsSurface make_plane_surface() {
|
||||
std::vector<std::vector<Point3D>> grid = {
|
||||
{Point3D(-1, -1, 0), Point3D(-1, 1, 0)},
|
||||
{Point3D( 1, -1, 0), Point3D( 1, 1, 0)}
|
||||
};
|
||||
return NurbsSurface(grid, {0,0,1,1}, {0,0,1,1}, {}, 1, 1);
|
||||
}
|
||||
|
||||
/// Create a simple triangular BrepModel
|
||||
BrepModel make_triangle(const Point3D& a, const Point3D& b, const Point3D& c) {
|
||||
BrepModel body;
|
||||
int v0 = body.add_vertex(a);
|
||||
int v1 = body.add_vertex(b);
|
||||
int v2 = body.add_vertex(c);
|
||||
int e0 = body.add_edge(v0, v1);
|
||||
int e1 = body.add_edge(v1, v2);
|
||||
int e2 = body.add_edge(v2, v0);
|
||||
int loop_id = body.add_loop({e0, e1, e2});
|
||||
auto surf = make_plane_surface();
|
||||
int sid = body.add_surface(surf);
|
||||
int fid = body.add_face(sid, {loop_id});
|
||||
int shell = body.add_shell({fid}, false);
|
||||
body.add_body({shell}, "triangle");
|
||||
return body;
|
||||
}
|
||||
|
||||
/// Create a simple box using modeling API
|
||||
BrepModel make_test_box() {
|
||||
return make_box(2.0, 2.0, 2.0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 1. TolerantVertex / TolerantEdge 基本构造
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, TolerantVertex_DefaultConstruction) {
|
||||
TolerantVertex tv;
|
||||
tv.id = 0;
|
||||
tv.point = Point3D(1, 2, 3);
|
||||
tv.tolerance = 1e-5;
|
||||
|
||||
EXPECT_EQ(tv.id, 0);
|
||||
EXPECT_DOUBLE_EQ(tv.point.x(), 1.0);
|
||||
EXPECT_DOUBLE_EQ(tv.point.y(), 2.0);
|
||||
EXPECT_DOUBLE_EQ(tv.point.z(), 3.0);
|
||||
EXPECT_DOUBLE_EQ(tv.tolerance, 1e-5);
|
||||
EXPECT_EQ(tv.merged_from, 1);
|
||||
EXPECT_FALSE(tv.is_degenerate);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, TolerantVertex_FromTopo) {
|
||||
TopoVertex topo;
|
||||
topo.id = 5;
|
||||
topo.point = Point3D(10, 20, 30);
|
||||
topo.tolerance = 1e-7;
|
||||
|
||||
TolerantVertex tv = TolerantVertex::from_topo(topo);
|
||||
EXPECT_EQ(tv.id, 5);
|
||||
EXPECT_DOUBLE_EQ(tv.point.x(), 10.0);
|
||||
EXPECT_DOUBLE_EQ(tv.tolerance, 1e-7);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, TolerantEdge_DefaultConstruction) {
|
||||
TolerantEdge te;
|
||||
te.id = 3;
|
||||
te.v_start = 1;
|
||||
te.v_end = 2;
|
||||
te.tolerance = 1e-6;
|
||||
te.is_tangent_contact = true;
|
||||
|
||||
EXPECT_EQ(te.id, 3);
|
||||
EXPECT_EQ(te.v_start, 1);
|
||||
EXPECT_EQ(te.v_end, 2);
|
||||
EXPECT_FALSE(te.is_degenerate);
|
||||
EXPECT_FALSE(te.gap_flag);
|
||||
EXPECT_TRUE(te.is_tangent_contact);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, TolerantEdge_FromTopo) {
|
||||
TopoEdge topo;
|
||||
topo.id = 7;
|
||||
topo.v_start = 0;
|
||||
topo.v_end = 1;
|
||||
|
||||
TolerantEdge te = TolerantEdge::from_topo(topo);
|
||||
EXPECT_EQ(te.id, 7);
|
||||
EXPECT_EQ(te.v_start, 0);
|
||||
EXPECT_EQ(te.v_end, 1);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, TolerantEdge_CheckDegenerate_True) {
|
||||
BrepModel body;
|
||||
int v0 = body.add_vertex(Point3D(0, 0, 0));
|
||||
int v1 = body.add_vertex(Point3D(1e-8, 1e-8, 0)); // extremely short edge
|
||||
int e0 = body.add_edge(v0, v1);
|
||||
|
||||
TolerantEdge te = TolerantEdge::from_topo(body.edge(e0));
|
||||
te.tolerance = 1e-6;
|
||||
|
||||
EXPECT_TRUE(te.check_degenerate(body));
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, TolerantEdge_CheckDegenerate_False) {
|
||||
BrepModel body;
|
||||
int v0 = body.add_vertex(Point3D(0, 0, 0));
|
||||
int v1 = body.add_vertex(Point3D(1, 0, 0));
|
||||
int e0 = body.add_edge(v0, v1);
|
||||
|
||||
TolerantEdge te = TolerantEdge::from_topo(body.edge(e0));
|
||||
te.tolerance = 1e-6;
|
||||
|
||||
EXPECT_FALSE(te.check_degenerate(body));
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 2. build_tolerant_vertices / build_tolerant_edges
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, BuildTolerantVertices) {
|
||||
BrepModel body;
|
||||
body.add_vertex(Point3D(0, 0, 0));
|
||||
body.add_vertex(Point3D(1, 0, 0));
|
||||
body.add_vertex(Point3D(0, 1, 0));
|
||||
|
||||
auto tvs = build_tolerant_vertices(body, 1e-5);
|
||||
EXPECT_EQ(tvs.size(), 3u);
|
||||
for (const auto& tv : tvs) {
|
||||
EXPECT_DOUBLE_EQ(tv.tolerance, 1e-5);
|
||||
EXPECT_EQ(tv.merged_from, 1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, BuildTolerantEdges) {
|
||||
BrepModel body;
|
||||
int v0 = body.add_vertex(Point3D(0, 0, 0));
|
||||
int v1 = body.add_vertex(Point3D(1, 0, 0));
|
||||
int v2 = body.add_vertex(Point3D(0, 1, 0));
|
||||
body.add_edge(v0, v1);
|
||||
body.add_edge(v1, v2);
|
||||
body.add_edge(v2, v0);
|
||||
|
||||
auto tes = build_tolerant_edges(body);
|
||||
EXPECT_EQ(tes.size(), 3u);
|
||||
EXPECT_FALSE(tes[0].is_degenerate); // 1.0 length
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 3. merge_within_tolerance
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, MergeWithinTolerance_NearCoincident) {
|
||||
BrepModel body;
|
||||
int v0 = body.add_vertex(Point3D(0, 0, 0));
|
||||
int v1 = body.add_vertex(Point3D(1, 0, 0));
|
||||
int v2 = body.add_vertex(Point3D(0, 1, 0));
|
||||
int v_near = body.add_vertex(Point3D(1e-7, 1e-7, 1e-7));
|
||||
|
||||
int e0 = body.add_edge(v0, v1);
|
||||
int e1 = body.add_edge(v1, v2);
|
||||
int e2 = body.add_edge(v2, v_near);
|
||||
|
||||
int loop_id = body.add_loop({e0, e1, e2});
|
||||
auto surf = make_plane_surface();
|
||||
int sid = body.add_surface(surf);
|
||||
body.add_face(sid, {loop_id});
|
||||
|
||||
size_t before = body.num_vertices();
|
||||
int merged = merge_within_tolerance(body, 1e-5);
|
||||
|
||||
EXPECT_GE(merged, 1);
|
||||
EXPECT_LT(body.num_vertices(), before);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, MergeWithinTolerance_Empty) {
|
||||
BrepModel body;
|
||||
EXPECT_EQ(merge_within_tolerance(body), 0);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, MergeWithinTolerance_SingleVertex) {
|
||||
BrepModel body;
|
||||
body.add_vertex(Point3D(0, 0, 0));
|
||||
EXPECT_EQ(merge_within_tolerance(body), 0);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 4. gap_bridging
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, GapBridging_Empty) {
|
||||
BrepModel body;
|
||||
EXPECT_EQ(gap_bridging(body), 0);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, GapBridging_SingleTriangle_NoGaps) {
|
||||
auto body = make_triangle(Point3D(0,0,0), Point3D(1,0,0), Point3D(0,1,0));
|
||||
// A closed triangle has no free edges
|
||||
int bridged = gap_bridging(body, 1e-4);
|
||||
EXPECT_GE(bridged, 0);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 5. overlap_resolution
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, OverlapResolution_Empty) {
|
||||
BrepModel body;
|
||||
EXPECT_EQ(overlap_resolution(body), 0);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, OverlapResolution_SingleFace) {
|
||||
auto body = make_triangle(Point3D(0,0,0), Point3D(1,0,0), Point3D(0,1,0));
|
||||
EXPECT_EQ(overlap_resolution(body), 0);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 6. tolerant_boolean
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, TolerantBoolean_EmptyBodies) {
|
||||
BrepModel a, b;
|
||||
auto diag = tolerant_boolean(a, b, 0); // union
|
||||
EXPECT_TRUE(diag.success);
|
||||
EXPECT_EQ(diag.result.num_faces(), 0u);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, TolerantBoolean_UnionOfDisjoint) {
|
||||
auto box1 = make_box(1, 1, 1);
|
||||
auto box2 = make_box(1, 1, 1);
|
||||
|
||||
auto diag = tolerant_boolean(box1, box2, 0); // union
|
||||
// May succeed or have failures — check that diagnostic is populated
|
||||
EXPECT_FALSE(diag.report().empty());
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, TolerantBoolean_InvalidOp) {
|
||||
auto box1 = make_box(1, 1, 1);
|
||||
auto box2 = make_box(1, 1, 1);
|
||||
|
||||
auto diag = tolerant_boolean(box1, box2, 99);
|
||||
EXPECT_FALSE(diag.success);
|
||||
EXPECT_FALSE(diag.error_message.empty());
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 7. BooleanDiagnostic
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, BooleanDiagnostic_Default) {
|
||||
BooleanDiagnostic diag;
|
||||
EXPECT_FALSE(diag.success);
|
||||
EXPECT_FALSE(diag.has_failures());
|
||||
EXPECT_FALSE(diag.report().empty());
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, BooleanDiagnostic_HasFailures) {
|
||||
BooleanDiagnostic diag;
|
||||
EXPECT_FALSE(diag.has_failures());
|
||||
|
||||
FailedFaceInfo ffi;
|
||||
ffi.face_id = 3;
|
||||
ffi.reason = "Test failure";
|
||||
diag.failed_faces.push_back(ffi);
|
||||
|
||||
EXPECT_TRUE(diag.has_failures());
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, BooleanDiagnostic_FailedFaceInfo) {
|
||||
FailedFaceInfo ffi;
|
||||
ffi.face_id = 42;
|
||||
ffi.reason = "Coplanar degeneracy";
|
||||
ffi.related_face_id = 17;
|
||||
ffi.is_coplanar = true;
|
||||
ffi.suggested_tolerance = 1e-3;
|
||||
|
||||
EXPECT_EQ(ffi.face_id, 42);
|
||||
EXPECT_EQ(ffi.related_face_id, 17);
|
||||
EXPECT_TRUE(ffi.is_coplanar);
|
||||
EXPECT_DOUBLE_EQ(ffi.suggested_tolerance, 1e-3);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 8. detect_coplanar_faces / detect_tangent_contact / detect_degenerate_edge
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, DetectCoplanarFaces_SameBody) {
|
||||
auto body = make_triangle(Point3D(0,0,0), Point3D(1,0,0), Point3D(0,1,0));
|
||||
// Single face body → cannot check pair
|
||||
EXPECT_FALSE(detect_coplanar_faces(body, 0, 0));
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, DetectDegenerateEdge_Valid) {
|
||||
BrepModel body;
|
||||
int v0 = body.add_vertex(Point3D(0, 0, 0));
|
||||
int v1 = body.add_vertex(Point3D(1, 0, 0));
|
||||
int e0 = body.add_edge(v0, v1);
|
||||
|
||||
EXPECT_FALSE(detect_degenerate_edge(body, e0));
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, DetectDegenerateEdge_Degenerate) {
|
||||
BrepModel body;
|
||||
int v0 = body.add_vertex(Point3D(0, 0, 0));
|
||||
int v1 = body.add_vertex(Point3D(1e-8, 0, 0));
|
||||
int e0 = body.add_edge(v0, v1);
|
||||
|
||||
EXPECT_TRUE(detect_degenerate_edge(body, e0, 1e-5));
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 9. import_heal_pipeline
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, ImportHealPipeline_Empty) {
|
||||
auto bodies = import_heal_pipeline("");
|
||||
EXPECT_TRUE(bodies.empty());
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, ImportHealPipeline_InvalidStep) {
|
||||
auto bodies = import_heal_pipeline("garbage data");
|
||||
EXPECT_TRUE(bodies.empty());
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, ImportHealPipeline_ValidStepData) {
|
||||
// 测试最小合法 STEP 数据
|
||||
std::string step_data = R"(
|
||||
ISO-10303-21;
|
||||
HEADER;
|
||||
FILE_DESCRIPTION(('Test'),'2;1');
|
||||
FILE_SCHEMA(('CONFIG_CONTROL_DESIGN'));
|
||||
ENDSEC;
|
||||
DATA;
|
||||
#1=CARTESIAN_POINT('',(0.,0.,0.));
|
||||
#2=CARTESIAN_POINT('',(1.,0.,0.));
|
||||
#3=CARTESIAN_POINT('',(1.,1.,0.));
|
||||
#4=CARTESIAN_POINT('',(0.,1.,0.));
|
||||
ENDSEC;
|
||||
END-ISO-10303-21;
|
||||
)";
|
||||
auto bodies = import_heal_pipeline(step_data);
|
||||
// 此数据没有完整拓扑结构,预期为空或部分结果
|
||||
// 主要验证不崩溃
|
||||
EXPECT_TRUE(bodies.empty() || !bodies.empty());
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 10. STEP import diagnostic
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, StepImportDiagnostic_AfterImport) {
|
||||
std::string step_data = R"(
|
||||
ISO-10303-21;
|
||||
HEADER;
|
||||
FILE_DESCRIPTION(('Test'),'2;1');
|
||||
FILE_SCHEMA(('CONFIG_CONTROL_DESIGN'));
|
||||
ENDSEC;
|
||||
DATA;
|
||||
#1=CARTESIAN_POINT('',(0.,0.,0.));
|
||||
ENDSEC;
|
||||
END-ISO-10303-21;
|
||||
)";
|
||||
import_step_from_string(step_data);
|
||||
auto report = step_import_diagnostic();
|
||||
// 应至少解析到 1 个实体
|
||||
EXPECT_GE(report.total_entities, 1);
|
||||
}
|
||||
|
||||
TEST(TolerantModelingTest, StepImportDiagnostic_ReportFormat) {
|
||||
std::string step_data = R"(
|
||||
ISO-10303-21;
|
||||
HEADER;
|
||||
FILE_DESCRIPTION(('Test'),'2;1');
|
||||
FILE_SCHEMA(('CONFIG_CONTROL_DESIGN'));
|
||||
ENDSEC;
|
||||
DATA;
|
||||
ENDSEC;
|
||||
END-ISO-10303-21;
|
||||
)";
|
||||
import_step_from_string(step_data);
|
||||
auto report = step_import_diagnostic();
|
||||
auto str = report.report();
|
||||
EXPECT_FALSE(str.empty());
|
||||
EXPECT_TRUE(str.find("STEP Import Diagnostic") != std::string::npos);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 11. Damaged STEP recovery
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(TolerantModelingTest, StepImport_DamagedEntityRecovery) {
|
||||
// 包含损坏实体的 STEP 数据:不完整的实体定义
|
||||
std::string step_data = R"(
|
||||
ISO-10303-21;
|
||||
HEADER;
|
||||
FILE_DESCRIPTION(('Damaged'),'2;1');
|
||||
FILE_SCHEMA(('CONFIG_CONTROL_DESIGN'));
|
||||
ENDSEC;
|
||||
DATA;
|
||||
#10=INCOMPLETE_ENTITY
|
||||
#1=CARTESIAN_POINT('',(0.,0.,0.));
|
||||
#2=CARTESIAN_POINT('',(1.,0.,0.));
|
||||
ENDSEC;
|
||||
END-ISO-10303-21;
|
||||
)";
|
||||
auto bodies = import_step_from_string(step_data);
|
||||
// 即使有损坏实体,仍应能解析 CARTESIAN_POINT
|
||||
auto report = step_import_diagnostic();
|
||||
EXPECT_GE(report.skipped_damaged, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user