diff --git a/CDT/include/CDTUtils.h b/CDT/include/CDTUtils.h index bb320ae..8128013 100644 --- a/CDT/include/CDTUtils.h +++ b/CDT/include/CDTUtils.h @@ -444,7 +444,7 @@ CDT_EXPORT bool isEncroachingOnEdge( /// Position of ABC triangle circumcenter template -CDT_EXPORT V2d circumcenter(V2d a, V2d b, const V2d& c); +CDT_EXPORT V2d circumcenter(V2d a, V2d b, V2d c); /// Doubled surface area of a triangle ABC template diff --git a/CDT/include/CDTUtils.hpp b/CDT/include/CDTUtils.hpp index 93ed4f9..c6e3a0c 100644 --- a/CDT/include/CDTUtils.hpp +++ b/CDT/include/CDTUtils.hpp @@ -320,15 +320,16 @@ bool isEncroachingOnEdge( } template -V2d circumcenter(V2d a, V2d b, const V2d& c) +V2d circumcenter(V2d a, V2d b, V2d c) { - const T denom = 0.5 / orient2D(c, a, b); + const T denom = T(2) * orient2D(a, b, c); + assert(denom != T(0)); a.x -= c.x, a.y -= c.y; b.x -= c.x, b.y -= c.y; const T aLenSq = lengthSquared(a), bLenSq = lengthSquared(b); - return V2d::make( - c.x + (b.y * aLenSq - a.y * bLenSq) * denom, - c.y + (a.x * bLenSq - b.x * aLenSq) * denom); + c.x += (b.y * aLenSq - a.y * bLenSq) / denom; + c.y += (a.x * bLenSq - b.x * aLenSq) / denom; + return c; } template