Skip to content

Commit

Permalink
fix compilation on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
Deamon87 committed Apr 13, 2023
1 parent 3e3decb commit a4cff1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/DBImporter
Submodule DBImporter updated 1 files
+7 −5 CMakeLists.txt
43 changes: 17 additions & 26 deletions wowViewerLib/src/engine/algorithms/grahamScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
#include <algorithm>
using namespace std;

// Point having the least y coordinate, used for sorting other points
// according to polar angle about this point
//Point pivot;
Point p0;

// returns -1 if a -> b -> c forms a counter-clockwise turn,
// +1 for a clockwise turn, 0 if they are collinear
int ccw(Point a, Point b, Point c) {
int ccw(const Point &a, const Point &b, const Point &c) {
float area = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
if (area > 0)
return -1;
Expand All @@ -20,7 +15,7 @@ int ccw(Point a, Point b, Point c) {
}

// returns square of Euclidean distance between two points
float sqrDist(Point a, Point b) {
float sqrDist(const Point &a, const Point &b) {
float dx = a.x - b.x, dy = a.y - b.y;
return dx * dx + dy * dy;
}
Expand All @@ -43,7 +38,7 @@ void swap(Point &p1, Point &p2)

// A utility function to return square of distance
// between p1 and p2
int distSq(Point &p1, Point &p2)
int distSq(const Point &p1, const Point &p2)
{
return (p1.x - p2.x)*(p1.x - p2.x) +
(p1.y - p2.y)*(p1.y - p2.y);
Expand All @@ -54,7 +49,7 @@ int distSq(Point &p1, Point &p2)
// 0 --> p, q and r are colinear
// 1 --> Clockwise
// 2 --> Counterclockwise
int orientation(Point &p, Point &q, Point &r)
int orientation(const Point &p, const Point &q, const Point &r)
{
int val = (q.y - p.y) * (r.x - q.x) -
(q.x - p.x) * (r.y - q.y);
Expand All @@ -63,21 +58,6 @@ int orientation(Point &p, Point &q, Point &r)
return (val > 0)? 1: 2; // clock or counterclock wise
}

// A function used by library function qsort() to sort an array of
// points with respect to the first point
int compare(const void *vp1, const void *vp2)
{
Point *p1 = (Point *)vp1;
Point *p2 = (Point *)vp2;

// Find orientation
int o = orientation(p0, *p1, *p2);
if (o == 0)
return (distSq(p0, *p2) >= distSq(p0, *p1))? -1 : 1;

return (o == 2)? -1: 1;
}

Point nextToTop(stack<Point> &S)
{
Point p = S.top();
Expand Down Expand Up @@ -107,12 +87,23 @@ stack<Point> grahamScan(std::vector<Point> &points) {
// Place the bottom-most point at first position
swap(points[0], points[min]);

// Point having the least y coordinate, used for sorting other points
// according to polar angle about this point
Point p0 = points[0];

// Sort n-1 points with respect to the first point.
// A point p1 comes before p2 in sorted ouput if p2
// has larger polar angle (in counterclockwise
// direction) than p1
p0 = points[0];
qsort(&points[1], n-1, sizeof(Point), compare);

std::sort(points.begin()+1, points.end(), [&p0](auto const &p1, auto const &p2) -> int {
// Find orientation
int o = orientation(p0, p1, p2);
if (o == 0)
return (distSq(p0, p2) >= distSq(p0, p1))? -1 : 1;

return (o == 2)? -1: 1;
});

// If two or more points make same angle with p0,
// Remove all but the one that is farthest from p0
Expand Down

0 comments on commit a4cff1c

Please sign in to comment.