diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2017-04-11 14:54:27 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2017-04-11 15:55:41 +0300 |
commit | 6fa3e50e060259d40a8d7427687d1d3ce759d453 (patch) | |
tree | bca5a2d4487994b242b765266f31e11900685ab9 /indexer/indexer_tests | |
parent | 1a9b2ef125a1d4dbbf5e96d8990becebb9d2234c (diff) |
Moved point-to-integer to coding
Diffstat (limited to 'indexer/indexer_tests')
-rw-r--r-- | indexer/indexer_tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | indexer/indexer_tests/geometry_coding_test.cpp | 2 | ||||
-rw-r--r-- | indexer/indexer_tests/indexer_tests.pro | 2 | ||||
-rw-r--r-- | indexer/indexer_tests/point_to_int64_test.cpp | 129 | ||||
-rw-r--r-- | indexer/indexer_tests/polyline_point_to_int64_test.cpp | 48 |
5 files changed, 51 insertions, 132 deletions
diff --git a/indexer/indexer_tests/CMakeLists.txt b/indexer/indexer_tests/CMakeLists.txt index 3e49a1e8ed..3fcf24f0d7 100644 --- a/indexer/indexer_tests/CMakeLists.txt +++ b/indexer/indexer_tests/CMakeLists.txt @@ -22,7 +22,7 @@ set( mwm_set_test.cpp osm_editor_test.cpp osm_editor_test.hpp - point_to_int64_test.cpp + polyline_point_to_int64_test.cpp postcodes_matcher_tests.cpp rank_table_test.cpp scales_test.cpp diff --git a/indexer/indexer_tests/geometry_coding_test.cpp b/indexer/indexer_tests/geometry_coding_test.cpp index 57ddad2a49..251e65c1e8 100644 --- a/indexer/indexer_tests/geometry_coding_test.cpp +++ b/indexer/indexer_tests/geometry_coding_test.cpp @@ -1,7 +1,6 @@ #include "testing/testing.hpp" #include "indexer/geometry_coding.hpp" -#include "indexer/point_to_int64.hpp" #include "geometry/mercator.hpp" #include "indexer/coding_params.hpp" @@ -12,6 +11,7 @@ #include "geometry/simplification.hpp" #include "coding/byte_stream.hpp" +#include "coding/point_to_integer.hpp" #include "coding/varint.hpp" #include "coding/writer.hpp" diff --git a/indexer/indexer_tests/indexer_tests.pro b/indexer/indexer_tests/indexer_tests.pro index 2bfd28cd1a..e324f2a352 100644 --- a/indexer/indexer_tests/indexer_tests.pro +++ b/indexer/indexer_tests/indexer_tests.pro @@ -47,7 +47,7 @@ SOURCES += \ interval_index_test.cpp \ mwm_set_test.cpp \ osm_editor_test.cpp \ - point_to_int64_test.cpp \ + polyline_point_to_int64_test.cpp \ postcodes_matcher_tests.cpp \ rank_table_test.cpp \ scales_test.cpp \ diff --git a/indexer/indexer_tests/point_to_int64_test.cpp b/indexer/indexer_tests/point_to_int64_test.cpp deleted file mode 100644 index 84bf3ce544..0000000000 --- a/indexer/indexer_tests/point_to_int64_test.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "testing/testing.hpp" - -#include "indexer/indexer_tests/test_polylines.hpp" - -#include "indexer/cell_id.hpp" - -#include "base/logging.hpp" - -#include "std/cmath.hpp" -#include "std/utility.hpp" - - -namespace -{ - double const g_eps = MercatorBounds::GetCellID2PointAbsEpsilon(); - uint32_t const g_coordBits = POINT_COORD_BITS; - - void CheckEqualPoints(m2::PointD const & p1, m2::PointD const & p2) - { - TEST(fabs(p1.x - p2.x) < g_eps && fabs(p1.y - p2.y) < g_eps, (p1, p2)); - - TEST_GREATER_OR_EQUAL(p1.x, -180.0, ()); - TEST_GREATER_OR_EQUAL(p1.y, -180.0, ()); - TEST_LESS_OR_EQUAL(p1.x, 180.0, ()); - TEST_LESS_OR_EQUAL(p1.y, 180.0, ()); - - TEST_GREATER_OR_EQUAL(p2.x, -180.0, ()); - TEST_GREATER_OR_EQUAL(p2.y, -180.0, ()); - TEST_LESS_OR_EQUAL(p2.x, 180.0, ()); - TEST_LESS_OR_EQUAL(p2.y, 180.0, ()); - } -} - -UNIT_TEST(PointToInt64_Smoke) -{ - m2::PointD const arr[] = { {1.25, 1.3}, {180, 90}, {-180, -90}, {0, 0} }; - - for (size_t i = 0; i < ARRAY_SIZE(arr); ++i) - CheckEqualPoints(arr[i], Int64ToPoint(PointToInt64(arr[i], g_coordBits), g_coordBits)); -} - -UNIT_TEST(PointToInt64_Grid) -{ - int const delta = 5; - for (int ix = -180; ix <= 180; ix += delta) - for (int iy = -180; iy <= 180; iy += delta) - { - m2::PointD const pt(ix, iy); - int64_t const id = PointToInt64(pt, g_coordBits); - m2::PointD const pt1 = Int64ToPoint(id, g_coordBits); - - CheckEqualPoints(pt, pt1); - - int64_t const id1 = PointToInt64(pt1, g_coordBits); - TEST_EQUAL(id, id1, (pt, pt1)); - } -} - -UNIT_TEST(PointToInt64_Bounds) -{ - double const arrEps[] = { -1.0E-2, -1.0E-3, -1.0E-4, 0, 1.0E-4, 1.0E-3, 1.0E-2 }; - - m2::PointD const arrPt[] = { {0, 0}, - {-180, -180}, {-180, 180}, {180, 180}, {180, -180}, - {-90, -90}, {-90, 90}, {90, 90}, {90, -90} - }; - - for (size_t iP = 0; iP < ARRAY_SIZE(arrPt); ++iP) - for (size_t iX = 0; iX < ARRAY_SIZE(arrEps); ++iX) - for (size_t iY = 0; iY < ARRAY_SIZE(arrEps); ++iY) - { - m2::PointD const pt(arrPt[iP].x + arrEps[iX], arrPt[iP].y + arrEps[iY]); - m2::PointD const pt1 = Int64ToPoint(PointToInt64(pt, g_coordBits), g_coordBits); - - TEST(fabs(pt.x - pt1.x) <= (fabs(arrEps[iX]) + g_eps) && - fabs(pt.y - pt1.y) <= (fabs(arrEps[iY]) + g_eps), (pt, pt1)); - } -} - -UNIT_TEST(PointToInt64_DataSet1) -{ - for (size_t i = 0; i < ARRAY_SIZE(index_test::arr1); ++i) - { - m2::PointD const pt(index_test::arr1[i].x, index_test::arr1[i].y); - int64_t const id = PointToInt64(pt, g_coordBits); - m2::PointD const pt1 = Int64ToPoint(id, g_coordBits); - - CheckEqualPoints(pt, pt1); - - int64_t const id1 = PointToInt64(pt1, g_coordBits); - TEST_EQUAL(id, id1, (pt, pt1)); - } -} - -UNIT_TEST(PointD2PointU_Epsilons) -{ - m2::PointD const arrPt[] = { {-180, -180}, {-180, 180}, {180, 180}, {180, -180} }; - m2::PointD const arrD[] = { {1, 1}, {1, -1}, {-1, -1}, {-1, 1} }; - size_t const count = ARRAY_SIZE(arrPt); - - /* - double eps = 1.0; - for (; true; eps = eps / 10.0) - { - size_t i = 0; - for (; i < count; ++i) - { - m2::PointU p = PointD2PointU(arrPt[i].x, arrPt[i].y, g_coordBits); - m2::PointU p1 = PointD2PointU(arrPt[i].x + arrD[i].x * eps, - arrPt[i].y + arrD[i].y * eps, - g_coordBits); - - if (p != p1) break; - } - if (i == count) break; - } - - LOG(LINFO, ("Epsilon = ", eps)); - */ - - for (size_t i = 0; i < count; ++i) - { - m2::PointU const p1 = PointD2PointU(arrPt[i].x, arrPt[i].y, g_coordBits); - m2::PointU const p2(p1.x + arrD[i].x, p1.y + arrD[i].y); - m2::PointD const p3 = PointU2PointD(p2, g_coordBits); - - LOG(LINFO, ("Dx = ", p3.x - arrPt[i].x, "Dy = ", p3.y - arrPt[i].y)); - } -} diff --git a/indexer/indexer_tests/polyline_point_to_int64_test.cpp b/indexer/indexer_tests/polyline_point_to_int64_test.cpp new file mode 100644 index 0000000000..ff0524fee1 --- /dev/null +++ b/indexer/indexer_tests/polyline_point_to_int64_test.cpp @@ -0,0 +1,48 @@ +#include "testing/testing.hpp" + +#include "indexer/indexer_tests/test_polylines.hpp" + +#include "indexer/cell_id.hpp" + +#include "coding/point_to_integer.hpp" + +#include "base/logging.hpp" + +#include "std/cmath.hpp" +#include "std/utility.hpp" + +namespace +{ +double const g_eps = MercatorBounds::GetCellID2PointAbsEpsilon(); +uint32_t const g_coordBits = POINT_COORD_BITS; + +void CheckEqualPoints(m2::PointD const & p1, m2::PointD const & p2) +{ + TEST(p1.EqualDxDy(p2, g_eps), (p1, p2)); + + TEST_GREATER_OR_EQUAL(p1.x, -180.0, ()); + TEST_GREATER_OR_EQUAL(p1.y, -180.0, ()); + TEST_LESS_OR_EQUAL(p1.x, 180.0, ()); + TEST_LESS_OR_EQUAL(p1.y, 180.0, ()); + + TEST_GREATER_OR_EQUAL(p2.x, -180.0, ()); + TEST_GREATER_OR_EQUAL(p2.y, -180.0, ()); + TEST_LESS_OR_EQUAL(p2.x, 180.0, ()); + TEST_LESS_OR_EQUAL(p2.y, 180.0, ()); +} +} + +UNIT_TEST(PointToInt64_DataSet1) +{ + for (size_t i = 0; i < ARRAY_SIZE(index_test::arr1); ++i) + { + m2::PointD const pt(index_test::arr1[i].x, index_test::arr1[i].y); + int64_t const id = PointToInt64(pt, g_coordBits); + m2::PointD const pt1 = Int64ToPoint(id, g_coordBits); + + CheckEqualPoints(pt, pt1); + + int64_t const id1 = PointToInt64(pt1, g_coordBits); + TEST_EQUAL(id, id1, (pt, pt1)); + } +} |