Phase 8a MVP: CGAL traits + Discrete_conformal_map.h Euclidean entry #6

Merged
user2595 merged 2 commits from feature/phase-8a-mvp-traits into main 2026-05-19 20:54:32 +00:00
2 changed files with 48 additions and 3 deletions
Showing only changes of commit 140f50f707 - Show all commits

View File

@@ -52,8 +52,10 @@ auto result = CGAL::discrete_conformal_map_euclidean(
#include <CGAL/Conformal_map_traits.h>
#include <CGAL/Conformal_map/internal/parameters.h>
#include <CGAL/Kernel_traits.h>
#include <CGAL/Named_function_parameters.h>
#include <CGAL/boost/graph/named_params_helper.h>
#include <CGAL/property_map.h>
// 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<TriangleMesh, Simple_cartesian<double>>;
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<double>. This lets the wrapper work with any
// Surface_mesh<P> 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<Point_type>::Kernel;
using Default_traits = Default_conformal_map_traits<TriangleMesh, Default_kernel>;
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<FT> result;

View File

@@ -17,6 +17,7 @@
#include <CGAL/Conformal_map_traits.h>
#include <CGAL/Discrete_conformal_map.h>
#include <CGAL/Kernel_traits.h>
#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<double>` 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<P>::Kernel;
using DeducedTraits = CGAL::Default_conformal_map_traits<Mesh, DeducedKernel>;
static_assert(std::is_same_v<DeducedKernel, CGAL::Simple_cartesian<double>>,
"ConformalMesh point type must deduce to Simple_cartesian<double>");
static_assert(std::is_same_v<typename DeducedTraits::FT, double>);
static_assert(std::is_same_v<typename DeducedTraits::Triangle_mesh, Mesh>);
// 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();