-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVec2.cpp
More file actions
57 lines (44 loc) · 1023 Bytes
/
Copy pathVec2.cpp
File metadata and controls
57 lines (44 loc) · 1023 Bytes
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
#include "Vec2.h"
#include<math.h>
#include<iostream>
Vec2::Vec2() {
}
Vec2::Vec2(float xin, float yin) :x(xin), y(yin) {
}
bool Vec2::operator ==(const Vec2& rhs)const {
return (x == rhs.x && y == rhs.y);
}
bool Vec2::operator !=(const Vec2& rhs)const {
return (x != rhs.x && y != rhs.y);
}
Vec2 Vec2::operator +(const Vec2& rhs)const {
return Vec2(x + rhs.x, y + rhs.y);
}
Vec2 Vec2::operator -(const Vec2& rhs)const {
return Vec2(x - rhs.x, y - rhs.y);
}
Vec2 Vec2::operator *(const float val)const {
return Vec2(x * val, y * val);
}
Vec2 Vec2::operator /(const float val)const {
return Vec2(x / val, y / val);
}
void Vec2::operator +=(const Vec2& rhs) {
x += rhs.x;
y += rhs.y;
}
void Vec2::operator -=(const Vec2& rhs) {
x -= rhs.x;
y -= rhs.y;
}
void Vec2::operator *=(const float val) {
x *= val;
y *= val;
}
void Vec2::operator /=(const float val) {
x /= val;
y /= val;
}
float Vec2::distance(const Vec2& rhs)const {
return sqrtf((x - rhs.x) * (x - rhs.x) + (y - rhs.y) * (y - rhs.y));
}