-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangulate.h
61 lines (43 loc) · 1.17 KB
/
triangulate.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef TRIANGULATE_H
#define TRIANGULATE_H
#include <vector> // Include STL vector class.
class Vector2d
{
public:
Vector2d(float x,float y)
{
Set(x,y);
};
float GetX(void) const { return mX; };
float GetY(void) const { return mY; };
void Set(float x,float y)
{
mX = x;
mY = y;
};
private:
float mX;
float mY;
};
// Typedef an STL vector of vertices which are used to represent
// a polygon/contour and a series of triangles.
typedef std::vector< Vector2d > Vector2dVector;
class Triangulate
{
public:
// triangulate a contour/polygon, places results in STL vector
// as series of triangles.
static bool Process(const Vector2dVector &contour,
Vector2dVector &result);
// compute area of a contour/polygon
static float Area(const Vector2dVector &contour);
// decide if point Px/Py is inside triangle defined by
// (Ax,Ay) (Bx,By) (Cx,Cy)
static bool InsideTriangle(float Ax, float Ay,
float Bx, float By,
float Cx, float Cy,
float Px, float Py);
private:
static bool Snip(const Vector2dVector &contour,int u,int v,int w,int n,int *V);
};
#endif