diff --git a/Quickhull.h b/Quickhull.h index c61d0db..ed1da94 100644 --- a/Quickhull.h +++ b/Quickhull.h @@ -10,7 +10,7 @@ class Quickhull { public: - static void get_hull(std::list &input, std::list &output) + static void get_hull(std::list input, std::list &output) { // Get leftmost and rightmost point Point leftmost(INFINITY, 0.0), rightmost(-INFINITY, 0.0); @@ -75,6 +75,30 @@ private: } } + // TODO: e.g. in the case of a rectangle, it's possible for there to be + // multiple closest points (sometimes all at distance 0). How do we handle + // these properly? We definitely need to remove them all from input later; + // do we also need to handle them all further? This hotfix works, but seems + // like an unnecessarily big performance hit for that edge case. + // FIXME: This workaround also causes problems with extremely large numbers + // of randomly generated numbers, causing random lines within the data! + // Points inside the hull are added because of random lines. + for (const Point &point : input) + { + float this_distance = line.distance_to(point); + // TODO: Both are required, otherwise only one side of the rectangle is + // taken -- why? + if (this_distance == furthest_distance || line.distance_to(point) == 0) + { + output.emplace_back(point); + } + } + input.remove_if([furthest_distance, line](Point point) + { + return furthest_distance == line.distance_to(point); + }); + // Hotfix end + output.emplace_back(furthest_point); input.remove(furthest_point); diff --git a/performance.cpp b/performance.cpp index dff3f97..9b25bff 100644 --- a/performance.cpp +++ b/performance.cpp @@ -4,7 +4,7 @@ int main() { - std::list points = NumberGenerator::get_circle_numbers(500); + std::list points = NumberGenerator::get_rectangle_numbers(100); std::list hull; Quickhull::get_hull(points, hull);