Commits

Anonymous committed e9b0752

More test cases for vectors :)

  • Participants
  • Parent commits b8e890d

Comments (0)

Files changed (3)

File neglect/cpplib/include/neglect/math.hpp

 
     inline bool almost_equal(float a, float b)
     {
-        return (a - 1e-06 < b && a + 1e-06 > b);
+        return (a - 1e-08 < b && a + 1e-08 > b);
     }
 
     inline bool almost_equal(double a, double b)
     {
-        return (a - 1e-08 < b && a + 1e-08 > b);
+        return (a - 1e-10 < b && a + 1e-10 > b);
     }
 
     // currently these are just aliases to the C/C++ math functions

File neglect/cpplib/include/neglect/vector.hpp

         return vector<T, 2>(-vec.y, vec.x);
     }
 
-#if 0
     /* returns a reflection vector to the plane with the given normal vector. */
     template <typename T, size_t Size>
     vector<T, Size> reflect(const vector<T, Size> &vec,
     {
         return (vec1 - vec2).norm();
     }
-#endif
 }
 
 // the actual vector implementations

File neglect/tests/src/test_vectors.cpp

         NUT_CHECK_EQUAL(v1 * v2, vec2(1.5f, -5.0f));
         NUT_CHECK_EQUAL(v1 / v2, vec2(1.5f, -1.25f));
         NUT_CHECK_EQUAL(-v1, vec2(-1.5f, 2.5f));
+
+        NUT_CHECK_EQUAL(v1.norm(), 8.5f);
+        NUT_CHECK_EQUAL(v1.length(), 2.9154759f);
+
+        NUT_CHECK(&v1 == &+v1);
     }
 
     NUT_TESTCASE(vector_functions)
         vec2 v2(1.0f, 1.0f);
         vec2 v3(5.0f, 3.0f);
         NUT_CHECK_EQUAL(normalize(v1), vec2(1.0f, 0.0f));
-        NUT_CHECK_ALMOST_EQUAL(normalize(v2), vec2(0.707107f, 0.707107f));
+        NUT_CHECK_ALMOST_EQUAL(normalize(v2), vec2(0.70710678f, 0.70710678f));
         NUT_CHECK_EQUAL(cross(v1, v2), 1.5f);
         NUT_CHECK_EQUAL(dot(v2, v3), 8.0f);
         NUT_CHECK_EQUAL(perpendicular(v3), vec2(-3.0f, 5.0f));
+        NUT_CHECK_EQUAL(reflect(v3, v2), vec2(-11.0f, -13.0f));
+        NUT_CHECK_ALMOST_EQUAL(distance(v2, v3), 4.4721359f);
+        NUT_CHECK_ALMOST_EQUAL(square_distance(v2, v3), 20.0f);
     }
 
     NUT_TESTCASE(stream_support)