-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvector2.h
77 lines (72 loc) · 1.67 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
#ifndef VECTOR2_H
#define VECTOR2_H
class Vector2
{
public:
double x,y;
Vector2();
Vector2(double,double);
void normalize();
inline const Vector2 operator+(const Vector2 &)const;
inline Vector2& operator+=(const Vector2 &);
inline Vector2& operator-=(const Vector2 &);
inline const Vector2 operator-(const Vector2 &)const;
inline const Vector2 operator-()const;
inline const double operator*(const Vector2 &)const;
inline const Vector2 operator/(double)const;
inline Vector2& operator/=(double);
inline friend const Vector2 operator*(const Vector2 &,double);
inline friend const Vector2 operator*(double,const Vector2 &);
};
const Vector2 Vector2::operator +(const Vector2 &v)const{
Vector2 r;
r.x=x+v.x;
r.y=y+v.y;
return r;
}
Vector2& Vector2::operator+=(const Vector2 &v){
x+=v.x;
y+=v.y;
return *this;
}
Vector2& Vector2::operator-=(const Vector2 &v){
x-=v.x;
y-=v.y;
return *this;
}
const Vector2 Vector2::operator -(const Vector2 &v)const{
Vector2 r;
r.x=x-v.x;
r.y=y-v.y;
return r;
}
const Vector2 Vector2::operator-()const{
Vector2 r;
r.x=-x;r.y=-y;
return r;
}
const double Vector2::operator*(const Vector2 &v)const{
return x*v.x+y*v.y;
}
const Vector2 Vector2::operator/(double a)const{
Vector2 r;
r.x=x/a;r.y=y/a;
return r;
}
inline Vector2& Vector2::operator/=(double a)
{
x/=a;
y/=a;
return *this;
}
const Vector2 operator*(const Vector2 &v,double a){
Vector2 r;
r.x=v.x*a;r.y=v.y*a;
return r;
}
const Vector2 operator*(double a,const Vector2 &v){
Vector2 r;
r.x=v.x*a;r.y=v.y*a;
return r;
}
#endif // VECTOR2_H