forked from bl4ckb0ne/delaunay-triangulation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvector2.h
80 lines (66 loc) · 1.04 KB
/
vector2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef H_VECTOR2
#define H_VECTOR2
#include <iostream>
#include <cmath>
namespace delaunay {
template <typename T>
class Vector2
{
public:
//
// Constructors
//
Vector2()
{
x = 0;
y = 0;
}
Vector2(T _x, T _y, int aid=0)
{
x = _x;
y = _y;
id = aid;
}
Vector2(const Vector2 &v)
{
x = v.x;
y = v.y;
id = v.id;
}
Vector2& operator=(const Vector2& rhs) {
x = rhs.x;
y = rhs.y;
id = rhs.id;
tag = rhs.tag;
return *this;
}
//
// Operations
//
T dist2(const Vector2 &v) const
{
T dx = x - v.x;
T dy = y - v.y;
return dx * dx + dy * dy;
}
float dist(const Vector2 &v)
{
return sqrtf(dist2(v));
}
T x;
T y;
int id=0;
int tag=0;
};
template<typename T>
std::ostream &operator << (std::ostream &str, Vector2<T> const &point)
{
return str << "Point x: " << point.x << " y: " << point.y << " tag: " << point.tag;
}
template<typename T>
bool operator == (Vector2<T> v1, Vector2<T> v2)
{
return (v1.x == v2.x) && (v1.y == v2.y);
}
}
#endif