Operators == and != were returning that 90 degrees != (90+360) degrees, due to floati...
[synfig.git] / ETL / trunk / ETL / _angle.h
index 3868b3e..20f8261 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdio.h>
 /* ========================================================================
 ** Extended Template and Library
 ** Angle Abstraction Class Implementation
@@ -122,8 +123,8 @@ public:
        operator~()const
        {
                angle ret;
-               ret.v=(value_type)std::floor(v+0.5f);
-               return ret;
+               ret.v = v+PI;
+               return ret.mod();
        }
 
        /*! Returns true if the shortest
@@ -131,16 +132,14 @@ public:
                right-hand side is clockwise */
        bool
        operator<(const angle &rhs)const
-       { return v<rhs.v; }
-//     { return dist(rhs).v<(value_type)0.0; }
+               { return dist(rhs).v<(value_type)0.0; }
 
        /*! Returns true if the shortest
                angle between the left-hand and
                right-hand side is counter-clockwise */
        bool
        operator>(const angle &rhs)const
-       { return v>rhs.v; }
-//     { return dist(rhs).v>(value_type)0.0; }
+               { return dist(rhs).v>(value_type)0.0; }
 
        /*! Returns true if the shortest
                angle between the left-hand and
@@ -149,8 +148,7 @@ public:
                point on the unit circle. */
        bool
        operator<=(const angle &rhs)const
-       { return v<=rhs.v; }
-//     { return dist(rhs).v<=(value_type)0.0; }
+               { return dist(rhs).v<=(value_type)0.0; }
 
        /*! Returns true if the shortest
                angle between the left-hand and
@@ -159,24 +157,21 @@ public:
                point on the unit circle. */
        bool
        operator>=(const angle &rhs)const
-       { return v>=rhs.v; }
-//     { return dist(rhs).v>=(value_type)0.0; }
+               { return dist(rhs).v>=(value_type)0.0; }
 
        /*! Returns true if the angles
                are refer to the same point
                on the unit circle. */
        bool
        operator==(const angle &rhs)const
-       { return v==rhs.v; }
-//     { return dist(rhs).v==(value_type)0.0; }
+               { return std::abs(dist(rhs).v)<epsilon; }
 
        /*! Returns false if the angles
                are refer to the same point
                on the unit circle. */
        bool
        operator!=(const angle &rhs)const
-       { return v!=rhs.v; }
-//     { return dist(rhs).v!=(value_type)0.0; }
+               { return std::abs(dist(rhs).v)>epsilon; }
 
        //! Angle Difference Function
        /*! This function will return the
@@ -237,6 +232,8 @@ private:
        static value_type rot_floor(value_type x)
        { return static_cast<value_type>(std::floor(x/(PI*2))*PI*2); }
 
+       static const value_type epsilon = 1.0e-6;
+
 public:
        /*
        ** Conversion Classes