From 69b6832b9a1d690c7c7259bb067c9d77428f4741 Mon Sep 17 00:00:00 2001 From: Lajat5 Date: Sat, 6 Nov 2021 09:02:27 +0000 Subject: [PATCH] Fix #2 --- geometry/graham_scan_functions.hpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/geometry/graham_scan_functions.hpp b/geometry/graham_scan_functions.hpp index 6f2bb4f85..4e99ff9fe 100644 --- a/geometry/graham_scan_functions.hpp +++ b/geometry/graham_scan_functions.hpp @@ -186,33 +186,32 @@ std::vector convexHull(std::vector points, uint64_t size) { // If modified array of points has less than 3 points, convex hull is not // possible if (m < 3) { - return {} + return {}; }; // Create an empty stack and push first three points to it. - std::stack S; - S.push(points[0]); - S.push(points[1]); - S.push(points[2]); + std::stack St; + St.push(points[0]); + St.push(points[1]); + St.push(points[2]); // Process remaining n-3 points for (int i = 3; i < m; i++) { // Keep removing top while the angle formed by // points next-to-top, top, and points[i] makes // a non-left turn - while (S.size() > 1 && - orientation(nextToTop(S), S.top(), points[i]) != 2) { - S.pop(); + while (St.size() > 1 && orientation(nextToTop(&St), St.top(), points[i]) != 2) { + St.pop(); } - S.push(points[i]); + St.push(points[i]); } std::vector result; // Now stack has the output points, push them into the resultant vector - while (!S.empty()) { - Point p = S.top(); + while (!St.empty()) { + Point p = St.top(); result.push_back(p); - S.pop(); + St.pop(); } return result; // return resultant vector with Convex Hull co-ordinates.