]> Shamusworld >> Repos - ttedit/blobdiff - src/vector.cpp
Add ability to move points with the arrow keys.
[ttedit] / src / vector.cpp
index 1f4c29cc5ae5b69eedd639efaa5fa0a6bc56883c..1ba2064ee925fd510bd7bc0ed6d878664f344e98 100755 (executable)
@@ -323,14 +323,14 @@ Vector& Vector::operator-=(double const v)
 // Check for equality
 bool Vector::operator==(Vector const v)
 {
-       return (x == v.x && y == v.y && z == v.z ? true : false);
+       return ((x == v.x) && (y == v.y) && (z == v.z) ? true : false);
 }
 
 
 // Check for inequality
 bool Vector::operator!=(Vector const v)
 {
-       return (x != v.x || y != v.y || z != v.z ? true : false);
+       return ((x != v.x) || (y != v.y) || (z != v.z) ? true : false);
 }
 
 
@@ -348,7 +348,7 @@ Vector Vector::Unit(void)
 
 double Vector::Magnitude(void)
 {
-       return sqrt(x * x + y * y + z * z);
+       return sqrt((x * x) + (y * y) + (z * z));
 }
 
 
@@ -365,17 +365,26 @@ double Vector::Angle(void)
 
 
 //
-// Angle between these two vectors
+// Returns the smallest angle between these two vectors
 //
 double Vector::Angle(Vector v)
 {
+// seems that something relies on this bad behavior... :-P
+#if 0
+       // Discard the sign from the subtraction
+       double angle = fabs(Angle() - v.Angle());
+
+       // Return the complementary angle if greater than 180⁰
+       return (angle <= 180.0 ? angle : 360.0 - angle);
+#else
        return Angle() - v.Angle();
+#endif
 }
 
 
 bool Vector::isZero(double epsilon/*= 1e-6*/)
 {
-       return (fabs(x) < epsilon && fabs(y) < epsilon && fabs(z) < epsilon ? true : false);
+       return ((fabs(x) < epsilon) && (fabs(y) < epsilon) && (fabs(z) < epsilon) ? true : false);
 }
 
 
@@ -392,7 +401,7 @@ double Vector::Magnitude(Vector v1, Vector v2)
        double xx = v1.x - v2.x;
        double yy = v1.y - v2.y;
        double zz = v1.z - v2.z;
-       return sqrt(xx * xx + yy * yy + zz * zz);
+       return sqrt((xx * xx) + (yy * yy) + (zz * zz));
 }
 
 #endif