From ca259caf336d5a69a410ab71af909d5a23724e20 Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Wed, 9 Mar 2022 15:47:47 +0100 Subject: [PATCH] fix ccw angle computation in Point.cpp --- src/libslic3r/Point.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Point.cpp b/src/libslic3r/Point.cpp index b2427d46db..66f125bb6f 100644 --- a/src/libslic3r/Point.cpp +++ b/src/libslic3r/Point.cpp @@ -131,9 +131,11 @@ double Point::ccw(const Line &line) const // i.e. this assumes a CCW rotation from p1 to p2 around this double Point::ccw_angle(const Point &p1, const Point &p2) const { - //FIXME this calculates an atan2 twice! Project one vector into the other! - double angle = atan2(p1.x() - (*this).x(), p1.y() - (*this).y()) - - atan2(p2.x() - (*this).x(), p2.y() - (*this).y()); + const Point v1 = *this - p1; + const Point v2 = p2 - *this; + int64_t dot = int64_t(v1(0)) * int64_t(v2(0)) + int64_t(v1(1)) * int64_t(v2(1)); + int64_t cross = int64_t(v1(0)) * int64_t(v2(1)) - int64_t(v1(1)) * int64_t(v2(0)); + float angle = float(atan2(float(cross), float(dot))); // we only want to return only positive angles return angle <= 0 ? angle + 2*PI : angle; }