From 57008afcc21bba0da8234a37d1c4735c9c5cb92b Mon Sep 17 00:00:00 2001 From: Allan Cueff Date: Sun, 11 Feb 2024 12:54:02 +0100 Subject: [PATCH] corrected infinite loop & intersection points multiples --- src/main.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e75ba41..e198484 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,13 +88,7 @@ int main() { } list> intersections; for (auto i = mediators.begin(); i != prev(mediators.end()); i++) { - for (auto j = next(i); j != i; j++) { - if (j == mediators.end()) { - if (i == mediators.begin()) { - break; - } - j = mediators.begin(); - } + for (auto j = next(i); j != mediators.end(); j++) { pair intersection; double x_intersect = ((*i).second - (*j).second) / ((*j).first - (*i).first); intersection = make_pair(x_intersect, (*i).second - (*i).first * x_intersect); @@ -105,7 +99,7 @@ int main() { double total_x = 0; double total_y = 0; unsigned int n = 0; - for (auto iter = intersections.begin(); it != intersections.end(); it++) { + for (auto iter = intersections.begin(); iter != intersections.end(); iter++) { n++; total_x += (*iter).first; total_y += (*iter).second;