forked from bl4ckb0ne/delaunay-triangulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector2.h
71 lines (58 loc) · 869 Bytes
/
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
#ifndef H_VECTOR2
#define H_VECTOR2
#include <iostream>
#include <cmath>
template <typename T>
class Vector2
{
public:
//
// Constructors
//
Vector2()
{
x = 0;
y = 0;
}
Vector2(T _x, T _y)
{
x = _x;
y = _y;
}
Vector2(const Vector2 &v)
{
x = v.x;
y = v.y;
}
void set(const Vector2 &v)
{
x = v.x;
y = v.y;
}
//
// Operations
//
T dist2(const Vector2 &v)
{
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;
};
template<typename T>
std::ostream &operator << (std::ostream &str, Vector2<T> const &point)
{
return str << "Point x: " << point.x << " y: " << point.y;
}
template<typename T>
bool operator == (Vector2<T> v1, Vector2<T> v2)
{
return (v1.x == v2.x) && (v1.y == v2.y);
}
#endif