-
Notifications
You must be signed in to change notification settings - Fork 0
/
vectorfun.h
44 lines (36 loc) · 1.21 KB
/
vectorfun.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <vector>
#include "point.h"
using namespace std;
/***************************************************************
This function will find a vetor's back y's min x.
***************************************************************/
Point getXMin(vector<Point> pts)
{
Point minPoint = pts.back();
for (int i = pts.size() - 1; i >= 0 && pts[i].y == pts.back().y; i--)
if (pts[i].x < minPoint.x)
minPoint = pts[i];
return minPoint;
}
/***************************************************************
This function will find a vetor's back y's max x.
***************************************************************/
Point getXMax(vector<Point> pts)
{
Point maxPoint = pts.back();
for (int i = pts.size() - 1; i >= 0 && pts[i].y == pts.back().y; i--)
if (pts[i].x > maxPoint.x)
maxPoint = pts[i];
return maxPoint;
}
/***************************************************************
This function will remove the y's that match back.
***************************************************************/
void removeYBack(vector<Point>& pts)
{
vector<Point>::iterator it = pts.begin();
while ((*it).y != pts.back().y)
it++;
pts.erase(it, pts.end());
return;
}