From 8bc47bf27b1cdb5a05a88a0600ad69a2a6bfde46 Mon Sep 17 00:00:00 2001 From: Stefano Facchini Date: Sun, 8 Oct 2017 12:35:03 +0200 Subject: Circle3pts LPE: handle overlapping points If two of the three points overlap, just draw the circle having that segment as diameter. This is not rigorous mathematically, but it is a reasonable behavior and avoid a crash when snapping is on. --- src/live_effects/lpe-circle_3pts.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp index 3410b13f2..c49d5ca4d 100644 --- a/src/live_effects/lpe-circle_3pts.cpp +++ b/src/live_effects/lpe-circle_3pts.cpp @@ -40,12 +40,18 @@ static void _circle3(Geom::Point const &A, Geom::Point const &B, Geom::Point con Point v = (B - A).ccw(); Point w = (C - B).ccw(); + double det = -v[0] * w[1] + v[1] * w[0]; - Point F = E - D; - double lambda = 1/det * (-w[1] * F[0] + w[0] * F[1]); + Point M; + if (!v.isZero()) { + Point F = E - D; + double lambda = det == 0 ? 0 : (-w[1] * F[0] + w[0] * F[1]) / det; + M = D + v * lambda; + } else { + M = E; + } - Point M = D + v * lambda; double radius = L2(M - A); Geom::Circle c(M, radius); -- cgit v1.2.3