From 140f50f707b92fa5ce2366117e71e089ab704fd5 Mon Sep 17 00:00:00 2001 From: Tarik Moussa Date: Tue, 19 May 2026 22:50:40 +0200 Subject: [PATCH] fixup: deduce kernel from mesh point type instead of hard-coding it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes the only architectural lock-in spotted in the MVP audit before Phase 9a starts: the wrapper hard-coded Simple_cartesian as the kernel inside discrete_conformal_map_euclidean. This would have broken any Surface_mesh

where P came from a different kernel (e.g. EPIC). Change ────── * CGAL::Kernel_traits::Kernel is now used to deduce the kernel from the mesh's point type. * The full Default_traits<...> instantiation is wrapped in internal_np::Lookup_named_param_def so a future `geom_traits(...)` named parameter can override the entire traits class without changes to the wrapper body (CGAL idiom, used by every CGAL package). * New test `KernelIsDeducedFromMeshPointType` pins the contract explicitly with static_asserts. Why now ─────── Phase 9a (Inversive-Distance) will copy this same template pattern. Fixing the kernel deduction once here keeps the design free for any user kernel; doing it after 9a would mean two parallel hard-coded kernel sites to refactor. Tests ───── CGAL suite: 184/184 passed, 0 skipped (was 183). Co-Authored-By: Claude Sonnet 4.6 --- code/include/CGAL/Discrete_conformal_map.h | 20 +++++++++++--- code/tests/cgal/test_cgal_traits_mvp.cpp | 31 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/code/include/CGAL/Discrete_conformal_map.h b/code/include/CGAL/Discrete_conformal_map.h index 64a0773..64de271 100644 --- a/code/include/CGAL/Discrete_conformal_map.h +++ b/code/include/CGAL/Discrete_conformal_map.h @@ -52,8 +52,10 @@ auto result = CGAL::discrete_conformal_map_euclidean( #include #include +#include #include #include +#include // Existing implementation headers (Layer 1 — unchanged). #include "../euclidean_functional.hpp" @@ -147,9 +149,21 @@ auto discrete_conformal_map_euclidean( TriangleMesh& mesh, const CGAL_NP_CLASS& np = parameters::default_values()) { - using Traits = Default_conformal_map_traits>; - using FT = typename Traits::FT; - using Vertex_descriptor = typename Traits::Vertex_descriptor; + // ── Type plumbing ────────────────────────────────────────────────────── + // + // Deduce the kernel from the mesh's Point_3 type rather than hard-coding + // Simple_cartesian. This lets the wrapper work with any + // Surface_mesh

whose P is a CGAL kernel point. The user can override + // the entire traits class via the `geom_traits(...)` named parameter + // (Phase 8b.2 extension; default below covers the common case). + using Point_type = typename TriangleMesh::Point; + using Default_kernel = typename CGAL::Kernel_traits::Kernel; + using Default_traits = Default_conformal_map_traits; + using Traits = typename internal_np::Lookup_named_param_def< + internal_np::geom_traits_t, + CGAL_NP_CLASS, + Default_traits>::type; + using FT = typename Traits::FT; Conformal_map_result result; diff --git a/code/tests/cgal/test_cgal_traits_mvp.cpp b/code/tests/cgal/test_cgal_traits_mvp.cpp index ba6859b..4d2f1dc 100644 --- a/code/tests/cgal/test_cgal_traits_mvp.cpp +++ b/code/tests/cgal/test_cgal_traits_mvp.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "mesh_builder.hpp" // make_triangle, make_quad_strip, make_tetrahedron #include "euclidean_functional.hpp" @@ -169,6 +170,36 @@ TEST(CGALDiscreteConformalMap, GradientToleranceTakesEffect) // match what newton_euclidean produces directly. // ════════════════════════════════════════════════════════════════════════════ +// ════════════════════════════════════════════════════════════════════════════ +// 6. Kernel deduction: the wrapper must NOT hard-code Simple_cartesian +// +// Regression guard: the wrapper deduces its kernel from the mesh point type +// via `CGAL::Kernel_traits`. If anyone re-introduces a hard-coded +// `Simple_cartesian` in the wrapper, the static_asserts here still +// pass (the legacy ConformalMesh uses that kernel) — but Phase 9a or any +// user with a different kernel-backed Surface_mesh would fail to compile. +// This test pins the deduction *contract* explicitly. +// ════════════════════════════════════════════════════════════════════════════ + +TEST(CGALDiscreteConformalMap, KernelIsDeducedFromMeshPointType) +{ + using Mesh = ConformalMesh; + using P = typename Mesh::Point; + + using DeducedKernel = typename CGAL::Kernel_traits

::Kernel; + using DeducedTraits = CGAL::Default_conformal_map_traits; + + static_assert(std::is_same_v>, + "ConformalMesh point type must deduce to Simple_cartesian"); + static_assert(std::is_same_v); + static_assert(std::is_same_v); + + // Run-time sanity: the wrapper accepts the deduced-kernel mesh end-to-end. + auto mesh = make_quad_strip(); + auto result = CGAL::discrete_conformal_map_euclidean(mesh); + EXPECT_TRUE(result.converged); +} + TEST(CGALDiscreteConformalMap, WrapperMatchesLegacyAPI) { auto mesh = make_quad_strip();