Diff Revisions 1 vs 10 for /trunk/geometry.cpp
| 1 | 10 | <- Revisions | |
|
Diff lines for: Rev 1 : Lines 7 -> 88 Rev 10 : Lines 7 -> 96 |
|||
| 7 | 7 | ///////////////////////////////////////////////////////// | |
| 8 | 8 | //////////////////////////Vector///////////////////////// | |
| 9 | 9 | ///////////////////////////////////////////////////////// | |
| 10 | - | bool Vector::less(Vector* a,Vector* b) | |
| 10 | + | bool Vector::less(const Vector& a,const Vector& b) | |
| 11 | 11 | { | |
| 12 | - | if (fabs((*a)[dirXP] - (*b)[dirXP]) > gEpsilon) return (*a)[dirXP] < (*b)[dirXP]; else | |
| 13 | - | if (fabs((*a)[dirYP] - (*b)[dirYP]) > gEpsilon) return (*a)[dirYP] < (*b)[dirYP]; else | |
| 14 | - | if (fabs((*a)[dirZP] - (*b)[dirZP]) > gEpsilon) return (*a)[dirZP] < (*b)[dirZP]; else | |
| 12 | + | if (fabs(a.data[dirXP] - b.data[dirXP]) > gEpsilon) return a.data[dirXP] < b.data[dirXP]; else | |
| 13 | + | if (fabs(a.data[dirYP] - b.data[dirYP]) > gEpsilon) return a.data[dirYP] < b.data[dirYP]; else | |
| 14 | + | if (fabs(a.data[dirZP] - b.data[dirZP]) > gEpsilon) return a.data[dirZP] < b.data[dirZP]; else | |
| 15 | 15 | return false; | |
| 16 | 16 | } | |
| 17 | 17 | //------------------------------------------------------- | |
| 18 | - | FloatType Vector::len() | |
| 19 | - | { | |
| 20 | - | return sqrt(x*x+y*y+z*z); | |
| 18 | + | FloatType Vector::len() const | |
| 19 | + | { | |
| 20 | + | return sqrt(sqr(data[dirXP])+sqr(data[dirYP])+sqr(data[dirZP])); | |
| 21 | 21 | } | |
| 22 | 22 | //------------------------------------------------------- | |
| 23 | - | FloatType Vector::dist(Vector aVec) | |
| 23 | + | FloatType Vector::dist(Vector const aVec) const | |
| 24 | 24 | { | |
| 25 | - | return sqrt(sqr(aVec.x-x)+sqr(aVec.y-y)+sqr(aVec.z-z)); | |
| 25 | + | return sqrt(sqr(data[dirXP]-aVec.data[dirXP])+ | |
| 26 | + | sqr(data[dirYP]-aVec.data[dirYP])+ | |
| 27 | + | sqr(data[dirZP]-aVec.data[dirZP])); | |
| 26 | 28 | } | |
| 27 | 29 | //------------------------------------------------------- | |
| 28 | - | bool Vector::operator==(Vector otherVec) | |
| 30 | + | bool Vector::operator==(const Vector otherVec) const | |
| 29 | 31 | { | |
| 30 | 32 | return dist(otherVec)<gEpsilon; | |
| 31 | 33 | } | |
| 32 | 34 | //------------------------------------------------------- | |
| 33 | - | void Vector::operator+=(Vector otherVec) | |
| 35 | + | void Vector::operator+=(const Vector otherVec) | |
| 34 | 36 | { | |
| 35 | 37 | for (int i=dirXP; i<noOfAxis; i++) | |
| 36 | - | operator[](i)+=otherVec[i]; | |
| 38 | + | operator[](i)+=otherVec(i); | |
| 37 | 39 | } | |
| 38 | 40 | //------------------------------------------------------- | |
| 39 | - | void Vector::operator*=(FloatType r) | |
| 41 | + | void Vector::operator*=(const FloatType r) | |
| 40 | 42 | { | |
| 41 | 43 | for (int i=dirXP; i<noOfAxis; i++) | |
| 42 | 44 | operator[](i)*=r; | |
| 43 | 45 | } | |
| 44 | 46 | //------------------------------------------------------- | |
| 45 | - | void Vector::operator/=(FloatType r) | |
| 47 | + | void Vector::operator/=(const FloatType r) | |
| 46 | 48 | { | |
| 47 | 49 | for (int i=dirXP; i<noOfAxis; i++) | |
| 48 | 50 | operator[](i)/=r; | |
| 49 | 51 | } | |
| 50 | 52 | //------------------------------------------------------- | |
| 51 | - | FloatType Vector::operator*(Vector otherVec) | |
| 53 | + | FloatType Vector::operator*(const Vector aVec) const | |
| 52 | 54 | { | |
| 53 | - | return x*otherVec.x+y*otherVec.y+z*otherVec.z; | |
| 55 | + | return data[dirXP]*aVec.data[dirXP]+ | |
| 56 | + | data[dirYP]*aVec.data[dirYP]+ | |
| 57 | + | data[dirZP]*aVec.data[dirZP]; | |
| 54 | 58 | } | |
| 55 | 59 | //------------------------------------------------------- | |
| 56 | - | Vector Vector::operator^(Vector otherVec) | |
| 60 | + | Vector Vector::operator^(Vector const aVec) const | |
| 57 | 61 | { | |
| 58 | - | return Vector( y*otherVec.z-z*otherVec.y , | |
| 59 | - | -(x*otherVec.z-z*otherVec.x), | |
| 60 | - | x*otherVec.y-y*otherVec.x ); | |
| 62 | + | return Vector( data[dirYP]*aVec.data[dirZP]-data[dirZP]*aVec.data[dirYP] , | |
| 63 | + | -(data[dirXP]*aVec.data[dirZP]-data[dirZP]*aVec.data[dirXP]), | |
| 64 | + | data[dirXP]*aVec.data[dirYP]-data[dirYP]*aVec.data[dirXP] ); | |
| 61 | 65 | } | |
| 62 | 66 | //------------------------------------------------------- | |
| 63 | - | Vector Vector::operator*(FloatType r) | |
| 67 | + | Vector Vector::operator*(const FloatType r) const | |
| 64 | 68 | { | |
| 65 | - | return Vector(x*r,y*r,z*r); | |
| 69 | + | return Vector(data[dirXP]*r,data[dirYP]*r,data[dirZP]*r); | |
| 66 | 70 | } | |
| 67 | 71 | //------------------------------------------------------- | |
| 68 | - | Vector Vector::operator/(FloatType r) | |
| 72 | + | Vector Vector::operator/(const FloatType r) const | |
| 69 | 73 | { | |
| 70 | - | return Vector(x/r,y/r,z/r); | |
| 74 | + | return Vector(data[dirXP]/r,data[dirYP]/r,data[dirZP]/r); | |
| 71 | 75 | } | |
| 72 | 76 | //------------------------------------------------------- | |
| 73 | - | Vector Vector::operator+(Vector otherVec) | |
| 77 | + | Vector Vector::operator+(const Vector aVec) const | |
| 74 | 78 | { | |
| 75 | - | return Vector(x+otherVec.x,y+otherVec.y,z+otherVec.z); | |
| 79 | + | return Vector(data[dirXP]+aVec.data[dirXP], | |
| 80 | + | data[dirYP]+aVec.data[dirYP], | |
| 81 | + | data[dirZP]+aVec.data[dirZP]); | |
| 76 | 82 | } | |
| 77 | 83 | //------------------------------------------------------- | |
| 78 | - | Vector Vector::operator-(Vector otherVec) | |
| 84 | + | Vector Vector::operator-(const Vector aVec) const | |
| 79 | 85 | { | |
| 80 | - | return Vector(x-otherVec.x,y-otherVec.y,z-otherVec.z); | |
| 86 | + | return Vector(data[dirXP]-aVec.data[dirXP], | |
| 87 | + | data[dirYP]-aVec.data[dirYP], | |
| 88 | + | data[dirZP]-aVec.data[dirZP]); | |
| 81 | 89 | } | |
| 82 | 90 | //------------------------------------------------------- | |
| 83 | - | Vector Vector::operator-() | |
| 91 | + | Vector Vector::operator-() const | |
| 84 | 92 | { | |
| 85 | - | return Vector(-x,-y,-z); | |
| 93 | + | return Vector(-data[dirXP],-data[dirYP],-data[dirZP]); | |
| 86 | 94 | } | |
| 87 | 95 | ///////////////////////////////////////////////////////// | |
| 88 | 96 | ///////////////////FractionalComponent/////////////////// | |
View this file contents
View the full history
Commits for aban:/trunk/geometry.cpp