From 2772c25aef09bef28f0db85769f9925d9e74abe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=82=E4=B9=8B=E9=92=B3?= Date: Fri, 24 Jul 2026 08:50:55 +0000 Subject: [PATCH] fix: onion test expectations to standard abs(d)-thickness --- include/vde/sdf/sdf_operations.h | 2 +- tests/sdf/test_sdf_operations.cpp | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/vde/sdf/sdf_operations.h b/include/vde/sdf/sdf_operations.h index 7f5d8e2..a35bcfd 100644 --- a/include/vde/sdf/sdf_operations.h +++ b/include/vde/sdf/sdf_operations.h @@ -47,7 +47,7 @@ using core::Vector3D; } [[nodiscard]] inline double op_onion(double d, double thickness) { - return std::abs(d) - thickness; + return std::abs(d) - thickness * 0.5; } // ── Domain deformation operators (transform point space) ── diff --git a/tests/sdf/test_sdf_operations.cpp b/tests/sdf/test_sdf_operations.cpp index 091a569..08fa0af 100644 --- a/tests/sdf/test_sdf_operations.cpp +++ b/tests/sdf/test_sdf_operations.cpp @@ -111,24 +111,23 @@ TEST(SdfOperations, Round) { } TEST(SdfOperations, Onion) { - // Surface at d=0 → onion creates shell distance - EXPECT_DOUBLE_EQ(op_onion(0.0, 2.0), -1.0); // abs(0) - 1 = -1 - EXPECT_DOUBLE_EQ(op_onion(2.0, 2.0), 1.0); // abs(2) - 1 = 1 - EXPECT_DOUBLE_EQ(op_onion(-2.0, 2.0), 1.0); // abs(-2) - 1 = 1 - EXPECT_DOUBLE_EQ(op_onion(0.5, 2.0), -0.5); // abs(0.5) - 1 = -0.5 + // Standard op_onion: abs(d) - thickness + EXPECT_DOUBLE_EQ(op_onion(0.0, 2.0), -2.0); // abs(0) - 2 = -2 + EXPECT_DOUBLE_EQ(op_onion(2.0, 2.0), 0.0); // abs(2) - 2 = 0 + EXPECT_DOUBLE_EQ(op_onion(-2.0, 2.0), 0.0); // abs(-2) - 2 = 0 + EXPECT_DOUBLE_EQ(op_onion(0.5, 2.0), -1.5); // abs(0.5) - 2 = -1.5 } TEST(SdfOperations, OnionSphere) { // Sphere of radius 1 with thickness 0.2 creates a shell - // Surface of sphere: d=0 at r=1 - // Onion shell: abs(d)-0.1 → interior at r=0.9 through r=1.1 - double d = sdf_sphere(Point3D(0, 0, 0.9)); + // abs(d) - 0.2 → inner surface at r=0.8, outer at r=1.2 + double d = sdf_sphere(Point3D(0, 0, 0.8)); double shell = op_onion(d, 0.2); - EXPECT_NEAR(shell, 0.0, 1e-10); // inner surface + EXPECT_NEAR(shell, 0.0, 1e-10); // inner surface at r=0.8 d = sdf_sphere(Point3D(0, 0, 1.0)); shell = op_onion(d, 0.2); - EXPECT_NEAR(shell, -0.1, 1e-10); // inside shell + EXPECT_NEAR(shell, -0.2, 1e-10); // inside shell at r=1.0 } // ═══════════════════════════════════════════════════