From 33741e18f58bf785fad3bd778caaae52804ed8cf Mon Sep 17 00:00:00 2001 From: QuimMoya Date: Mon, 21 Oct 2024 09:26:04 +0200 Subject: [PATCH] Partial fix for #540 Centroid falls exactly in the boundary of a face causing a bug, this fix changes the centroid function --- .../geometry/operations/boolean-utils/clip-mesh.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cpp/geometry/operations/boolean-utils/clip-mesh.h b/src/cpp/geometry/operations/boolean-utils/clip-mesh.h index 52a0c142..817d743b 100644 --- a/src/cpp/geometry/operations/boolean-utils/clip-mesh.h +++ b/src/cpp/geometry/operations/boolean-utils/clip-mesh.h @@ -76,7 +76,7 @@ namespace fuzzybools glm::dvec3 n = computeNormal(a, b, c); - glm::dvec3 triCenter = (a + b + c) * 1.0 / 3.0; + glm::dvec3 triCenter = (a + b * 2.0 + c * 3.0) * 1.0 / 6.0; // Using true centroid could cause issues (#540) auto isInsideTarget = MeshLocation::INSIDE; @@ -158,18 +158,18 @@ namespace fuzzybools } #ifdef CSG_DEBUG_OUTPUT - if (doit || true) + if (doit) { - edgesPrinted.push_back({ glm::dvec2(a.z + a.x/2, a.y+ a.x/2), glm::dvec2(b.z+ b.x/2, b.y+ b.x/2)}); - edgesPrinted.push_back({ glm::dvec2(a.z+ a.x/2, a.y+ a.x/2), glm::dvec2(c.z+ c.x/2, c.y+ c.x/2) }); - edgesPrinted.push_back({ glm::dvec2(b.z+ b.x/2, b.y+ b.x/2), glm::dvec2(c.z+ c.x/2, c.y+ c.x/2) }); - DumpSVGLines(edgesPrinted, L"final_tri.html"); + // edgesPrinted.push_back({ glm::dvec2(a.z + a.x/2, a.y+ a.x/2), glm::dvec2(b.z+ b.x/2, b.y+ b.x/2)}); + // edgesPrinted.push_back({ glm::dvec2(a.z+ a.x/2, a.y+ a.x/2), glm::dvec2(c.z+ c.x/2, c.y+ c.x/2) }); + // edgesPrinted.push_back({ glm::dvec2(b.z+ b.x/2, b.y+ b.x/2), glm::dvec2(c.z+ c.x/2, c.y+ c.x/2) }); + // DumpSVGLines(edgesPrinted, L"final_tri.html"); } #endif } #ifdef CSG_DEBUG_OUTPUT - DumpSVGLines(edgesPrinted, L"final_tri.html"); + // DumpSVGLines(edgesPrinted, L"final_tri.html"); #endif }