Debian Codegraph @

Oodle/src/CVector.cpp

raw
1 #include "CVector.h"
2 #include <iostream>
3 using namespace std;
4
5 CVector::CVector(double x, double y)
6 {
7 this->x = x;
8 this->y = y;
9 }
10
11 CVector CVector::add(const CVector &b) const
12 {
13 CVector c ( x + b.getX(),y + b.getY() );
14 return c;
15 }
16
17 CVector CVector::subtract(const CVector &b) const
18 {
19 CVector c ( x - b.getX(),y - b.getY() );
20 return c;
21 }
22 double CVector::dot(const CVector &b) const
23 {
24 return ( ( x * b.getX() ) + ( y * b.getY() ) );
25 }
26
27 CVector CVector::multiply(double d) const
28 {
29 return CVector( (d * x), (d * y) );
30 }
31
32 CVector CVector::operator+=(CVector b)
33 {
34 *this = add(b);
35 return *this;
36 }
37
38 CVector CVector::operator+(const CVector &b) const
39 {
40 return add(b);
41 }
42
43 CVector CVector::operator-(const CVector &b) const
44 {
45 return subtract(b);
46 }
47
48 double CVector::operator*(const CVector &b) const
49 {
50 // dot product
51 return dot(b);
52 }
53
54 CVector CVector::operator*(double d) const
55 {
56 // scalar product
57 return multiply(d);
58 }
59
60 /*const CVector& CVector::operator=(CVector b)
61 {
62 x = b.x;
63 y = b.y;
64 return *this;
65 }*/
66
67 bool CVector::operator==(const CVector &b) const
68 {
69 if ( x == b.getX() && y == b.getY() )
70 return true;
71 else
72 return false;
73 }
74
75 bool CVector::operator>(const CVector &b) const
76 {
77 if ( x > b.getX() && y > b.getY() )
78 return true;
79 else
80 return false;
81 }
82
83 bool CVector::operator<(const CVector &b) const
84 {
85 if ( x < b.getX() && y < b.getY() )
86 return true;
87 else
88 return false;
89 }
90
91 bool CVector::operator>=(const CVector &b) const
92 {
93 if ( x >= b.getX() && y >= b.getY() )
94 return true;
95 else
96 return false;
97 }
98
99 bool CVector::operator<=(const CVector &b) const
100 {
101 if ( x <= b.getX() && y <= b.getY() )
102 return true;
103 else
104 return false;
105 }
106
107 bool CVector::operator!=(const CVector &b) const
108 {
109 return ! (b == *this);
110 }
111
112 ostream& operator << (ostream& os, const CVector& v)
113 {
114 // Output the vector's magnitude and direction
115 return (os << "Mag: " << v.getMag() << " @ " << v.getDirDeg());
116 }
117
118 CVector ZERO_VECTOR = CVector(0,0);