Added Jarvi algo to find convex hull

This commit is contained in:
rishabh-997 2020-08-17 02:46:38 +05:30
parent d21f56e836
commit bf610fb91d

View File

@ -26,7 +26,6 @@
* @author [Rishabh Agarwal](https://github.com/rishabh-997)
*/
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
@ -54,19 +53,19 @@ namespace geometry {
* throughout the code
*/
class Convexhull {
public:
std::vector<Point> points;
int size;
public:
/**
* Constructor of given class
*
* @param pointList list of all points in the space
* @param n number of points in space
*/
Convexhull(std::vector<Point> pointList, int n) {
points = std::move(pointList);
size = n;
explicit Convexhull(const std::vector<Point> &pointList) {
points = pointList;
size = points.size();
}
/**
@ -120,16 +119,18 @@ namespace geometry {
}
/**
*
* This function returns the geometric orientation for the three points
* in a space, ie, whether they are linear ir clockwise or
* anti-clockwise
* @param p first point selected
* @param q adjacent point for q
* @param r adjacent point for q
* @returns the geometric orientation for the three points
* 0 -> Linear
* 1 -> Clock Wise
* 2 -> Anti Clock Wise
*
* @returns 0 -> Linear
* @returns 1 -> Clock Wise
* @returns 2 -> Anti Clock Wise
*/
static int orientation(Point p, Point q, Point r) {
static 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);
if (val == 0) {
@ -156,8 +157,7 @@ static void test() {
{0, 0},
{3, 3}
};
int n = points.size();
geometry::jarvis::Convexhull hull(points, n);
geometry::jarvis::Convexhull hull(points);
std::vector<geometry::jarvis::Point> actualPoint;
actualPoint = hull.getConvexHull();