Debian Codegraph @

Oodle/src/CVector.h

raw
1 #ifndef _CVECTOR_
2 #define _CVECTOR_
3
4 #include <iostream>
5 #include <cmath>
6 using namespace std;
7
8 #define PI 3.14159
9
10 class CVector
11 {
12 private:
13 double x;
14 double y;
15
16 CVector add(const CVector &b) const;
17 CVector subtract(const CVector &b) const;
18 CVector multiply(double d) const;
19 double dot(const CVector &b) const;
20
21 public:
22 CVector(double x, double y);
23 // CVector(double mag, double rad);
24
25 CVector() : x(0), y(0) { }
26 ~CVector() {}
27
28 CVector operator+=(CVector b);
29 CVector operator+(const CVector &b) const;
30 CVector operator-(const CVector &b) const;
31 double operator*(const CVector &b) const; // dot product
32 CVector operator*(double d) const; // scalar product
33 // const CVector& operator=(CVector b);
34 bool operator==(const CVector &b) const;
35 bool operator>(const CVector &b) const;
36 bool operator<(const CVector &b) const;
37 bool operator>=(const CVector &b) const;
38 bool operator<=(const CVector &b) const;
39 bool operator!=(const CVector &b) const;
40 friend ostream& operator<<(ostream& os, const CVector& v);
41
42 double getDirRad() const { return atan2(y,x); }
43 double getDirDeg() const { return getDirRad() * (180 / PI); }
44 double getX() const { return x; }
45 double getY() const { return y; }
46 double getMag() const { return ( sqrt (pow(x,2.0) + pow(y,2.0) ) ); }
47
48 void setX(double x) { CVector::x = x; }
49 void setY(double y) { CVector::y = y; }
50 void addX(double x) { CVector::x += x; }
51 void addY(double y) { CVector::y += y; }
52 void setMag(double mag) { double rad = getDirRad(); y = sin(rad)*mag; x = cos(rad)*mag; }
53 void setDir(double rad) { double mag = getMag(); y = sin(rad)*mag; x = cos(rad)*mag; }
54 };
55
56 extern CVector ZERO_VECTOR;
57
58 #endif