Add temp workaround for rectangle
Getting both rectangle sides to work as intended is tricky. This works, but should be replaced with something better.
This commit is contained in:
parent
b9fd11ca0d
commit
c0bba8b264
26
Quickhull.h
26
Quickhull.h
@ -10,7 +10,7 @@
|
|||||||
class Quickhull
|
class Quickhull
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void get_hull(std::list<Point> &input, std::list<Point> &output)
|
static void get_hull(std::list<Point> input, std::list<Point> &output)
|
||||||
{
|
{
|
||||||
// Get leftmost and rightmost point
|
// Get leftmost and rightmost point
|
||||||
Point leftmost(INFINITY, 0.0), rightmost(-INFINITY, 0.0);
|
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);
|
output.emplace_back(furthest_point);
|
||||||
input.remove(furthest_point);
|
input.remove(furthest_point);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::list<Point> points = NumberGenerator::get_circle_numbers(500);
|
std::list<Point> points = NumberGenerator::get_rectangle_numbers(100);
|
||||||
std::list<Point> hull;
|
std::list<Point> hull;
|
||||||
|
|
||||||
Quickhull::get_hull(points, hull);
|
Quickhull::get_hull(points, hull);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user