Skip to content

Commit 251f14e

Browse files
committed
Update Vec2
1 parent ae05bf6 commit 251f14e

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/iou.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace IOU
3939
struct Vec2 {
4040
// Members.
4141
union {
42-
struct
42+
struct
4343
{
4444
T x;
4545
T y;
@@ -64,8 +64,11 @@ namespace IOU
6464
inline bool operator==(const Vec2 &p) const {
6565
return (abs(x - p.x) <= _ZERO_ && abs(y - p.y) <= _ZERO_);
6666
}
67+
inline bool operator!=(const Vec2 &p) const {
68+
return (abs(x - p.x) > _ZERO_ || abs(y - p.y) > _ZERO_);
69+
}
6770
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); }
6972
inline Vec2& operator*=(T t) { x *= t; y *= t; return *this; }
7073
inline Vec2& operator/=(T t) { x /= t; y /= t; return *this; }
7174

@@ -76,7 +79,7 @@ namespace IOU
7679

7780
inline Vec2 dmul(const Vec2 &p) const { return Vec2(x * p.x, y * p.y); }
7881
inline Vec2 ddiv(const Vec2 &p) const { return Vec2(x / p.x, y / p.y); }
79-
82+
8083
inline T dot(const Vec2 &p) const { return x * p.x + y * p.y; }
8184
inline T operator*(const Vec2 &p) const { return x * p.x + y * p.y; }
8285

@@ -98,16 +101,7 @@ namespace IOU
98101
double angle(const Vec2 &r) const {
99102
return acos( dot(r) / (norm() * r.norm()) ); }
100103
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);
111105
}
112106
};
113107
template <typename T>
@@ -118,13 +112,12 @@ namespace IOU
118112
inline T squareDistance(const Vec2<T> &p1, const Vec2<T> &p2) { return p1.squareDistance(p2); }
119113
template <typename T>
120114
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-
124115

125116
typedef Vec2<int> Vec2i;
126117
typedef Vec2<float> Vec2f;
127118
typedef Vec2<double> Vec2d;
119+
120+
128121
typedef Vec2d Point;
129122
typedef std::vector<Point> Vertexes;
130123

0 commit comments

Comments
 (0)