From b93b9d558cfa6f4460304ce1945d28f326520f2a Mon Sep 17 00:00:00 2001 From: Tommaso Bianchi Date: Tue, 30 Jun 2026 17:55:06 +0200 Subject: [PATCH] Mirror [Deviation] surface_deviation test into test_caddocument.cpp orca_cad's test_geometry.cpp is upstream Catch2 v3 with no CAD suite, so the surface_deviation check lives alongside the CAD tests here. Built + ran green in orca_cad's kernel-test docker: All tests passed (4 assertions). Both forks now carry the test. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01BVzKmX6Y1aEteit1HTXG4Q --- tests/libslic3r/test_caddocument.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/libslic3r/test_caddocument.cpp b/tests/libslic3r/test_caddocument.cpp index 60baf8bd69..832c3c9be8 100644 --- a/tests/libslic3r/test_caddocument.cpp +++ b/tests/libslic3r/test_caddocument.cpp @@ -1,6 +1,7 @@ #include // mainline OrcaSlicer ships Catch2 v3 (v2 was catch2/catch.hpp) #include "libslic3r/CadDocument.hpp" +#include "libslic3r/GeometryEngine.hpp" #include "libslic3r/SketchEngine.hpp" #include "libslic3r/SketchImport.hpp" #include "libslic3r/ThreadStandards.hpp" @@ -13,6 +14,9 @@ #include #include #include +#include +#include +#include #include using namespace Slic3r; @@ -1603,3 +1607,21 @@ TEST_CASE("datum plane construction methods", "[CadDocument][plane]") CHECK_THAT(std::abs(sp.y_axis.dot(sp.normal)), WithinAbs(0.0, 1e-6)); } } + +// Mirrors the snaporca [Deviation] case (snaporca carries it in test_geometry.cpp; here it lives +// alongside the CAD suite). GeometryEngine::surface_deviation = one-sided Hausdorff used by the +// MCP validate_against acceptance metric. +TEST_CASE("surface_deviation: identical solids ~0, shifted solid ~shift", "[Deviation]") +{ + TopoDS_Shape ref = BRepPrimAPI_MakeBox(10.0, 10.0, 10.0).Shape(); + auto d0 = GeometryEngine::surface_deviation(ref, ref, 0.5); + REQUIRE(d0.sample_count > 0); + REQUIRE_THAT(d0.max_mm, Catch::Matchers::WithinAbs(0.0, 1e-6)); + + // candidate shifted +2mm in X: far corner vertices sit 2mm outside the reference + gp_Trsf t; t.SetTranslation(gp_Vec(2.0, 0.0, 0.0)); + TopoDS_Shape shifted = BRepBuilderAPI_Transform(ref, t, true).Shape(); + auto d1 = GeometryEngine::surface_deviation(shifted, ref, 0.5); + REQUIRE_THAT(d1.max_mm, Catch::Matchers::WithinAbs(2.0, 0.05)); + REQUIRE(d1.mean_mm > 0.0); +}