diff options
author | Maxim Pimenov <m@maps.me> | 2015-05-22 15:28:20 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:49:17 +0300 |
commit | c93ecfd1b1e4e2c62d6f6148b4854081a06b98e5 (patch) | |
tree | ef876f3df9e0163ca8a63f064f542f2e0d7c60b1 /geometry | |
parent | f510a3bb6792341cf42ab7048c5b32124ae829cb (diff) |
Rename AlmostEqual into AlmostEqualULPs.
Diffstat (limited to 'geometry')
-rw-r--r-- | geometry/angles.cpp | 2 | ||||
-rw-r--r-- | geometry/distance.hpp | 2 | ||||
-rw-r--r-- | geometry/geometry_tests/angle_test.cpp | 22 | ||||
-rw-r--r-- | geometry/geometry_tests/distance_test.cpp | 34 | ||||
-rw-r--r-- | geometry/geometry_tests/point_test.cpp | 22 | ||||
-rw-r--r-- | geometry/geometry_tests/spline_test.cpp | 6 | ||||
-rw-r--r-- | geometry/geometry_tests/vector_test.cpp | 2 | ||||
-rw-r--r-- | geometry/point2d.hpp | 14 | ||||
-rw-r--r-- | geometry/polygon.hpp | 2 | ||||
-rw-r--r-- | geometry/region2d.hpp | 4 |
10 files changed, 55 insertions, 55 deletions
diff --git a/geometry/angles.cpp b/geometry/angles.cpp index b1a34ae508..7abf02c77a 100644 --- a/geometry/angles.cpp +++ b/geometry/angles.cpp @@ -11,7 +11,7 @@ double AngleIn2PI(double ang) if (ang < 0.0) ang += period; - if (my::AlmostEqual(period, ang)) + if (my::AlmostEqualULPs(period, ang)) return 0.0; return ang; diff --git a/geometry/distance.hpp b/geometry/distance.hpp index 47b7225285..1063779bc1 100644 --- a/geometry/distance.hpp +++ b/geometry/distance.hpp @@ -27,7 +27,7 @@ public: m_D = m_P1 - m_P0; m_D2 = Length(m_D); - if (my::AlmostEqual(m_D2, 0.0)) + if (my::AlmostEqualULPs(m_D2, 0.0)) { // make zero vector - then all DotProduct will be equal to zero m_D = m2::PointD::Zero(); diff --git a/geometry/geometry_tests/angle_test.cpp b/geometry/geometry_tests/angle_test.cpp index 54fd651a0d..866b2b904e 100644 --- a/geometry/geometry_tests/angle_test.cpp +++ b/geometry/geometry_tests/angle_test.cpp @@ -31,12 +31,12 @@ UNIT_TEST(Atan) UNIT_TEST(Atan2) { - TEST_ALMOST_EQUAL(atan2(1, 0), pi/2.0, ()); - TEST_ALMOST_EQUAL(atan2(-1, 0), -pi/2.0, ()); - TEST_ALMOST_EQUAL(atan2(0, 1), 0.0, ()); - TEST_ALMOST_EQUAL(atan2(0, -1), pi, ()); + TEST_ALMOST_EQUAL_ULPS(atan2(1, 0), pi/2.0, ()); + TEST_ALMOST_EQUAL_ULPS(atan2(-1, 0), -pi/2.0, ()); + TEST_ALMOST_EQUAL_ULPS(atan2(0, 1), 0.0, ()); + TEST_ALMOST_EQUAL_ULPS(atan2(0, -1), pi, ()); - TEST_ALMOST_EQUAL(atan2(1, 1), pi/4.0, ()); + TEST_ALMOST_EQUAL_ULPS(atan2(1, 1), pi/4.0, ()); } namespace @@ -67,16 +67,16 @@ UNIT_TEST(Average) UNIT_TEST(ShortestDistance) { - TEST_ALMOST_EQUAL(ang::GetShortestDistance(0, math::pi), math::pi, ()); - TEST_ALMOST_EQUAL(ang::GetShortestDistance(0, math::pi + 1), -math::pi + 1, ()); + TEST_ALMOST_EQUAL_ULPS(ang::GetShortestDistance(0, math::pi), math::pi, ()); + TEST_ALMOST_EQUAL_ULPS(ang::GetShortestDistance(0, math::pi + 1), -math::pi + 1, ()); - TEST_ALMOST_EQUAL(ang::GetShortestDistance(math::pi - 1, 0), -math::pi + 1, ()); - TEST_ALMOST_EQUAL(ang::GetShortestDistance(math::pi + 1, 0), math::pi - 1, ()); + TEST_ALMOST_EQUAL_ULPS(ang::GetShortestDistance(math::pi - 1, 0), -math::pi + 1, ()); + TEST_ALMOST_EQUAL_ULPS(ang::GetShortestDistance(math::pi + 1, 0), math::pi - 1, ()); } UNIT_TEST(TwoVectorsAngle){ - TEST_ALMOST_EQUAL(ang::TwoVectorsAngle(m2::Point<double>({0, 0}), + TEST_ALMOST_EQUAL_ULPS(ang::TwoVectorsAngle(m2::Point<double>({0, 0}), m2::Point<double>({0, 1}), m2::Point<double>(1, 0)), 3 * math::pi2, ()); - TEST_ALMOST_EQUAL(ang::TwoVectorsAngle(m2::Point<double>({1, 1}), + TEST_ALMOST_EQUAL_ULPS(ang::TwoVectorsAngle(m2::Point<double>({1, 1}), m2::Point<double>({2, 2}), m2::Point<double>(1, 2)), math::pi4, ()); } diff --git a/geometry/geometry_tests/distance_test.cpp b/geometry/geometry_tests/distance_test.cpp index e3f23252a8..aff4236b85 100644 --- a/geometry/geometry_tests/distance_test.cpp +++ b/geometry/geometry_tests/distance_test.cpp @@ -8,13 +8,13 @@ void FloatingPointsTest() m2::DistanceToLineSquare<PointT> d; d.SetBounds(PointT(-1, 3), PointT(2, 1)); - TEST_ALMOST_EQUAL(d(PointT(-1, 3)), 0.0, ()); - TEST_ALMOST_EQUAL(d(PointT(2, 1)), 0.0, ()); - TEST_ALMOST_EQUAL(d(PointT(-0.5, 0.5)), 3.25, ()); - TEST_ALMOST_EQUAL(d(PointT(3.5, 0.0)), 3.25, ()); - TEST_ALMOST_EQUAL(d(PointT(4.0, 4.0)), 13.0, ()); - TEST_ALMOST_EQUAL(d(PointT(0.5, 2.0)), 0.0, ()); - TEST_ALMOST_EQUAL(d(PointT(0.0, 1.25)), 0.5 * 0.5 + 0.75 * 0.75, ()); + TEST_ALMOST_EQUAL_ULPS(d(PointT(-1, 3)), 0.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(PointT(2, 1)), 0.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(PointT(-0.5, 0.5)), 3.25, ()); + TEST_ALMOST_EQUAL_ULPS(d(PointT(3.5, 0.0)), 3.25, ()); + TEST_ALMOST_EQUAL_ULPS(d(PointT(4.0, 4.0)), 13.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(PointT(0.5, 2.0)), 0.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(PointT(0.0, 1.25)), 0.5 * 0.5 + 0.75 * 0.75, ()); } UNIT_TEST(DistanceToLineSquare2D_Floating) @@ -28,13 +28,13 @@ UNIT_TEST(DistanceToLineSquare2D_Integer) m2::DistanceToLineSquare<m2::PointI> d; d.SetBounds(m2::PointI(-1, 3), m2::PointI(2, 1)); - TEST_ALMOST_EQUAL(d(m2::PointI(-1, 3)), 0.0, ()); - TEST_ALMOST_EQUAL(d(m2::PointI(2, 1)), 0.0, ()); - TEST_ALMOST_EQUAL(d(m2::PointI(4, 4)), 13.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(m2::PointI(-1, 3)), 0.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(m2::PointI(2, 1)), 0.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(m2::PointI(4, 4)), 13.0, ()); double const sqSin = 4.0 / m2::PointI(-1, 3).SquareLength(m2::PointI(2, 1)); - TEST_ALMOST_EQUAL(d(m2::PointI(0, 1)), 4.0*sqSin, ()); - TEST_ALMOST_EQUAL(d(m2::PointI(-1, 1)), 9.0*sqSin, ()); + TEST_ALMOST_EQUAL_ULPS(d(m2::PointI(0, 1)), 4.0*sqSin, ()); + TEST_ALMOST_EQUAL_ULPS(d(m2::PointI(-1, 1)), 9.0*sqSin, ()); } UNIT_TEST(DistanceToLineSquare2D_DegenerateSection) @@ -43,10 +43,10 @@ UNIT_TEST(DistanceToLineSquare2D_DegenerateSection) m2::DistanceToLineSquare<P> d; d.SetBounds(P(5, 5), P(5, 5)); - TEST_ALMOST_EQUAL(d(P(5, 5)), 0.0, ()); - TEST_ALMOST_EQUAL(d(P(6, 6)), 2.0, ()); - TEST_ALMOST_EQUAL(d(P(0, 0)), 50.0, ()); - TEST_ALMOST_EQUAL(d(P(-1, -2)), 36.0 + 49.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(P(5, 5)), 0.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(P(6, 6)), 2.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(P(0, 0)), 50.0, ()); + TEST_ALMOST_EQUAL_ULPS(d(P(-1, -2)), 36.0 + 49.0, ()); } UNIT_TEST(PointProjectionTests_Smoke) @@ -71,6 +71,6 @@ UNIT_TEST(PointProjectionTests_Smoke) for (size_t i = 0; i < ARRAY_SIZE(arr); ++i) { p.SetBounds(arr[i][1], arr[i][2]); - TEST(m2::AlmostEqual(p(arr[i][0]), arr[i][3]), (i)); + TEST(m2::AlmostEqualULPs(p(arr[i][0]), arr[i][3]), (i)); } } diff --git a/geometry/geometry_tests/point_test.cpp b/geometry/geometry_tests/point_test.cpp index 8024b4281a..116c8ef246 100644 --- a/geometry/geometry_tests/point_test.cpp +++ b/geometry/geometry_tests/point_test.cpp @@ -63,22 +63,22 @@ UNIT_TEST(GetArrowPoints) { array<m2::PointF, 3> arrPntsFlt; m2::GetArrowPoints(m2::PointF(0, 0), m2::PointF(1, 0), 1.f, 1.f, arrPntsFlt); - TEST(m2::AlmostEqual(arrPntsFlt[0], m2::PointF(1.f, 1.f)), ()); - TEST(m2::AlmostEqual(arrPntsFlt[1], m2::PointF(2.f, 0.f)), ()); - TEST(m2::AlmostEqual(arrPntsFlt[2], m2::PointF(1.f, -1.f)), ()); + TEST(m2::AlmostEqualULPs(arrPntsFlt[0], m2::PointF(1.f, 1.f)), ()); + TEST(m2::AlmostEqualULPs(arrPntsFlt[1], m2::PointF(2.f, 0.f)), ()); + TEST(m2::AlmostEqualULPs(arrPntsFlt[2], m2::PointF(1.f, -1.f)), ()); array<m2::PointD, 3> arrPntsDbl; m2::GetArrowPoints(m2::PointD(-1., 2.), m2::PointD(-1., 100.), 2., 5., arrPntsDbl); - TEST(m2::AlmostEqual(arrPntsDbl[0], m2::PointD(-3.f, 100.f)), ()); - TEST(m2::AlmostEqual(arrPntsDbl[1], m2::PointD(-1.f, 105.f)), ()); - TEST(m2::AlmostEqual(arrPntsDbl[2], m2::PointD(1.f, 100.f)), ()); + TEST(m2::AlmostEqualULPs(arrPntsDbl[0], m2::PointD(-3.f, 100.f)), ()); + TEST(m2::AlmostEqualULPs(arrPntsDbl[1], m2::PointD(-1.f, 105.f)), ()); + TEST(m2::AlmostEqualULPs(arrPntsDbl[2], m2::PointD(1.f, 100.f)), ()); } UNIT_TEST(PointAtSegment) { - TEST(m2::AlmostEqual(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(1, 0), 0.5f), m2::PointF(0.5f, 0.f)), ()); - TEST(m2::AlmostEqual(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(0, 1), 0.3f), m2::PointF(0.f, 0.3f)), ()); - TEST(m2::AlmostEqual(m2::PointAtSegment(m2::PointD(0., 0.), m2::PointD(30., 40.), 5.), m2::PointD(3., 4.)), ()); - TEST(m2::AlmostEqual(m2::PointAtSegment(m2::PointF(-3, -4), m2::PointF(-30, -40), 5.f), m2::PointF(-6.f, -8.f)), ()); - TEST(m2::AlmostEqual(m2::PointAtSegment(m2::PointD(14., -48.), m2::PointD(70., -240.), 25.), m2::PointD(21., -72.)), ()); + TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(1, 0), 0.5f), m2::PointF(0.5f, 0.f)), ()); + TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(0, 1), 0.3f), m2::PointF(0.f, 0.3f)), ()); + TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointD(0., 0.), m2::PointD(30., 40.), 5.), m2::PointD(3., 4.)), ()); + TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointF(-3, -4), m2::PointF(-30, -40), 5.f), m2::PointF(-6.f, -8.f)), ()); + TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointD(14., -48.), m2::PointD(70., -240.), 25.), m2::PointD(21., -72.)), ()); } diff --git a/geometry/geometry_tests/spline_test.cpp b/geometry/geometry_tests/spline_test.cpp index 4b0ccc69cb..f649302c5e 100644 --- a/geometry/geometry_tests/spline_test.cpp +++ b/geometry/geometry_tests/spline_test.cpp @@ -10,8 +10,8 @@ void TestPointDDir(PointD const & dst, PointD const & src) { double len1 = dst.Length(); double len2 = src.Length(); - TEST_ALMOST_EQUAL(dst.x/len1, src.x/len2, ()); - TEST_ALMOST_EQUAL(dst.y/len1, src.y/len2, ()); + TEST_ALMOST_EQUAL_ULPS(dst.x/len1, src.x/len2, ()); + TEST_ALMOST_EQUAL_ULPS(dst.y/len1, src.y/len2, ()); } UNIT_TEST(SmoothedDirections) @@ -202,6 +202,6 @@ UNIT_TEST(Length) double l3 = p3.Length(p4); double l4 = p4.Length(p5); double len2 = l1 + l2 + l3 + l4; - TEST_ALMOST_EQUAL(len1, len2, ()); + TEST_ALMOST_EQUAL_ULPS(len1, len2, ()); } diff --git a/geometry/geometry_tests/vector_test.cpp b/geometry/geometry_tests/vector_test.cpp index 1709833ec1..0b8ea7ee7c 100644 --- a/geometry/geometry_tests/vector_test.cpp +++ b/geometry/geometry_tests/vector_test.cpp @@ -8,7 +8,7 @@ namespace template <class T, size_t N> bool EqualArrays(T (&a1)[N], T (&a2)[N]) { for (size_t i = 0; i < N; ++i) - if (!my::AlmostEqual(a1[i], a2[i])) + if (!my::AlmostEqualULPs(a1[i], a2[i])) return false; return true; } diff --git a/geometry/point2d.hpp b/geometry/point2d.hpp index 4211efab4f..1e1ab3d838 100644 --- a/geometry/point2d.hpp +++ b/geometry/point2d.hpp @@ -43,7 +43,7 @@ namespace m2 bool IsAlmostZero() const { - return AlmostEqual(*this, Point<T>(0,0)); + return AlmostEqualULPs(*this, Point<T>(0,0)); } Point<T> Move(T len, T ang) const @@ -276,7 +276,7 @@ namespace m2 PointT const edgeR = vNext - v; double const cpLR = CrossProduct(edgeR, edgeL); - if (my::AlmostEqual(cpLR, 0.0)) + if (my::AlmostEqualULPs(cpLR, 0.0)) { // Points vPrev, v, vNext placed on one line; // use property that polygon has CCW orientation. @@ -315,9 +315,9 @@ namespace m2 } template <typename T> - bool AlmostEqual(m2::Point<T> const & a, m2::Point<T> const & b, unsigned int maxULPs = 256) + bool AlmostEqualULPs(m2::Point<T> const & a, m2::Point<T> const & b, unsigned int maxULPs = 256) { - return my::AlmostEqual(a.x, b.x, maxULPs) && my::AlmostEqual(a.y, b.y, maxULPs); + return my::AlmostEqualULPs(a.x, b.x, maxULPs) && my::AlmostEqualULPs(a.y, b.y, maxULPs); } /// Calculate three points of a triangle (p1, p2 and p3) which give an arrow that @@ -327,7 +327,7 @@ namespace m2 template <typename T, typename TT, typename PointT = Point<T>> void GetArrowPoints(PointT const & b, PointT const & e, T w, T l, array<Point<TT>, 3> & arrPnts) { - ASSERT(!m2::AlmostEqual(b, e), ()); + ASSERT(!m2::AlmostEqualULPs(b, e), ()); PointT const beVec = e - b; PointT beNormalizedVec = beVec.Normalize(); @@ -385,9 +385,9 @@ namespace my { template <typename T> -bool AlmostEqual(m2::Point<T> const & p1, m2::Point<T> const & p2, unsigned int maxULPs = 256) +bool AlmostEqualULPs(m2::Point<T> const & p1, m2::Point<T> const & p2, unsigned int maxULPs = 256) { - return m2::AlmostEqual(p1, p2, maxULPs); + return m2::AlmostEqualULPs(p1, p2, maxULPs); } } diff --git a/geometry/polygon.hpp b/geometry/polygon.hpp index 28c4ec0b6c..f36f4e20de 100644 --- a/geometry/polygon.hpp +++ b/geometry/polygon.hpp @@ -49,7 +49,7 @@ size_t FindSingleStrip(size_t n, IsVisibleF isVisible) template <typename IterT> bool TestPolygonPreconditions(IterT beg, IterT end) { ASSERT_GREATER ( distance(beg, end), 2, () ); - ASSERT ( !AlmostEqual(*beg, *(--end)), () ); + ASSERT ( !AlmostEqualULPs(*beg, *(--end)), () ); return true; } #endif diff --git a/geometry/region2d.hpp b/geometry/region2d.hpp index 21a8eba738..bbc89068c1 100644 --- a/geometry/region2d.hpp +++ b/geometry/region2d.hpp @@ -18,12 +18,12 @@ namespace m2 template <class PointT> bool EqualPoints(PointT const & p1, PointT const & p2) const { - return m2::AlmostEqual(p1, p2); + return m2::AlmostEqualULPs(p1, p2); } template <class CoordT> bool EqualZero(CoordT val, CoordT exp) const { - return my::AlmostEqual(val + exp, exp); + return my::AlmostEqualULPs(val + exp, exp); } }; |