@@ -39,7 +39,7 @@ namespace IOU
39
39
struct Vec2 {
40
40
// Members.
41
41
union {
42
- struct
42
+ struct
43
43
{
44
44
T x;
45
45
T y;
@@ -64,8 +64,11 @@ namespace IOU
64
64
inline bool operator ==(const Vec2 &p) const {
65
65
return (abs (x - p.x ) <= _ZERO_ && abs (y - p.y ) <= _ZERO_);
66
66
}
67
+ inline bool operator !=(const Vec2 &p) const {
68
+ return (abs (x - p.x ) > _ZERO_ || abs (y - p.y ) > _ZERO_);
69
+ }
67
70
inline Vec2 operator *(T t) const { return Vec2 (x * t, y * t); }
68
- inline Vec2 operator /(T t) const { return Vec2 (x / t, y / t); }
71
+ inline Vec2 operator /(T t) const { return Vec2 (x / t, y / t); }
69
72
inline Vec2& operator *=(T t) { x *= t; y *= t; return *this ; }
70
73
inline Vec2& operator /=(T t) { x /= t; y /= t; return *this ; }
71
74
@@ -76,7 +79,7 @@ namespace IOU
76
79
77
80
inline Vec2 dmul (const Vec2 &p) const { return Vec2 (x * p.x , y * p.y ); }
78
81
inline Vec2 ddiv (const Vec2 &p) const { return Vec2 (x / p.x , y / p.y ); }
79
-
82
+
80
83
inline T dot (const Vec2 &p) const { return x * p.x + y * p.y ; }
81
84
inline T operator *(const Vec2 &p) const { return x * p.x + y * p.y ; }
82
85
@@ -98,16 +101,7 @@ namespace IOU
98
101
double angle (const Vec2 &r) const {
99
102
return acos ( dot (r) / (norm () * r.norm ()) ); }
100
103
double theta () const {
101
- Vec2 ax (1.0 , 0.0 );
102
- double a = angle (ax);
103
- if (cmul (ax) > 0.0 )
104
- a = 3.141592653 * 2 - a;
105
- return a;
106
- }
107
- void swap (Vec2<T> &p) {
108
- Vec2<T> temp = *this ;
109
- *this = p;
110
- p = temp;
104
+ return atan2 (y, x);
111
105
}
112
106
};
113
107
template <typename T>
@@ -118,13 +112,12 @@ namespace IOU
118
112
inline T squareDistance (const Vec2<T> &p1, const Vec2<T> &p2) { return p1.squareDistance (p2); }
119
113
template <typename T>
120
114
inline double angle (const Vec2<T> &p1, const Vec2<T> &p2) { return p1.angle (p2); }
121
- template <typename T>
122
- inline void swap (Vec2<T> &p1, Vec2<T> &p2) { return p1.swap (p2); }
123
-
124
115
125
116
typedef Vec2<int > Vec2i;
126
117
typedef Vec2<float > Vec2f;
127
118
typedef Vec2<double > Vec2d;
119
+
120
+
128
121
typedef Vec2d Point;
129
122
typedef std::vector<Point> Vertexes;
130
123
0 commit comments