-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector2.h
49 lines (44 loc) · 1.44 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
#ifndef _VECTOR2_H_
#define _VECTOR2_H_ 1
/**
* this class defines a what a 2-D vector should behave
*/
class Vector2{
public:
//constructors
Vector2();
Vector2(double _x,double _y);
Vector2(const Vector2 &orig);
double operator[](int i)const;
double &operator[](int i);
double getX()const;
double getY()const;
void setX(double _x);
void setY(double _y);
// operators
friend Vector2 operator+(const Vector2 &v1,const Vector2 &v2);
friend Vector2 operator-(const Vector2 &v1,const Vector2 &v2);
friend Vector2 operator*(const Vector2 &v1,double scale);
friend Vector2 operator*(double scale,const Vector2 &v1);
friend Vector2 operator/(const Vector2 &v1,double scale);
friend Vector2 operator/(double scale,const Vector2 &v1);
friend double dot(const Vector2 &v1,const Vector2 &v2);
friend double cross(const Vector2 &v1,const Vector2 &v2);
friend bool operator==(const Vector2 &v1,const Vector2 &v2);
friend bool operator!=(const Vector2 &v1,const Vector2 &v2);
const Vector2 &operator+()const;
Vector2 operator-()const;
Vector2 &operator+=(const Vector2 &v1);
Vector2 &operator-=(const Vector2 &v1);
Vector2 &operator*=(double scale);
Vector2 &operator/=(double scale);
// return the length of the vector
double length()const;
// return the square length of the vector
double sqrLength()const;
// return the normalized vector of a given vector
friend Vector2 normalize(const Vector2 &v);
private:
double x,y;
};
#endif // VECTOR2_H_