Add Akl Heuristic in performance mode

Doesn't seem to make much of a difference though :(

but another issue was fixed in the meantime (we weren't actually usign the leftmost and rightmost points!)
This commit is contained in:
karl 2020-12-06 22:09:35 +01:00
parent ef01f37834
commit 7bfa0f0ed2
2 changed files with 50 additions and 15 deletions

3
Line.h
View File

@ -42,8 +42,7 @@ public:
other -= from(); other -= from();
// Cross product greater than zero? // Cross product greater than zero?
// Note: We need ">=" here so that we include points which are directly on the existing hull. if (m_to_from_origin.x() * other.y() - m_to_from_origin.y() * other.x() > 0)
if (m_to_from_origin.x() * other.y() - m_to_from_origin.y() * other.x() >= 0)
{ {
return true; return true;
} }

View File

@ -8,6 +8,7 @@
#include "Display.h" #include "Display.h"
#include "Triangle.h" #include "Triangle.h"
#include "Utility.h" // For IsPointInRectangle
class Quickhull class Quickhull
{ {
@ -19,11 +20,45 @@ public:
// 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);
if (akl)
{
// Also get highest and lowest point
Point lowest(0.0, -INFINITY), highest(0.0, INFINITY);
for (const Point &point : input) for (const Point &point : input)
{ {
if (point.x() < leftmost.x()) { if (point.x() < leftmost.x()) {
leftmost = point; leftmost = point;
} else if (point.y() > rightmost.y()) { } else if (point.x() > rightmost.x()) {
rightmost = point;
}
if (point.y() < highest.y()) {
highest = point;
} else if (point.y() > lowest.y()) {
lowest = point;
}
}
Triangle t1(highest, rightmost, lowest);
Triangle t2(lowest, leftmost, highest);
// Remove all points in this rectangle
input.remove_if([highest, leftmost, lowest, rightmost](const Point &point)
{
return IsPointInRectangle(point, highest, leftmost, lowest, rightmost);
});
output.emplace_back(leftmost);
output.emplace_back(rightmost);
output.emplace_back(highest);
output.emplace_back(lowest);
} else {
for (const Point &point : input)
{
if (point.x() < leftmost.x()) {
leftmost = point;
} else if (point.x() > rightmost.x()) {
rightmost = point; rightmost = point;
} }
} }
@ -34,6 +69,7 @@ public:
// Remove them from the input (as well as duplicates) // Remove them from the input (as well as duplicates)
input.remove(leftmost); input.remove(leftmost);
input.remove(rightmost); input.remove(rightmost);
}
// Create a line from leftmost to rightmost // Create a line from leftmost to rightmost
Line line = Line(leftmost, rightmost); Line line = Line(leftmost, rightmost);