diff options
author | Roman Sorokin <sorok-roma@yandex.ru> | 2014-09-29 12:32:01 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:27:50 +0300 |
commit | bea1a69200fa4defb585cf34a242d12b95834fef (patch) | |
tree | cb9097add46266a336bef6dc74c26eb388cef85a /geometry/geometry_tests | |
parent | 786c69a7d16bde4aa7edef180cfb51ad9d871703 (diff) |
Spline rewritten for double
Diffstat (limited to 'geometry/geometry_tests')
-rw-r--r-- | geometry/geometry_tests/spline_test.cpp | 226 |
1 files changed, 113 insertions, 113 deletions
diff --git a/geometry/geometry_tests/spline_test.cpp b/geometry/geometry_tests/spline_test.cpp index 2d881e7b00..6f70967732 100644 --- a/geometry/geometry_tests/spline_test.cpp +++ b/geometry/geometry_tests/spline_test.cpp @@ -4,204 +4,204 @@ #include "../spline.hpp" using m2::Spline; -using m2::PointF; +using m2::PointD; -void TestPointFDir(PointF const & dst, PointF const & src) +void TestPointDDir(PointD const & dst, PointD const & src) { - float len1 = dst.Length(); - float len2 = src.Length(); + 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, ()); } UNIT_TEST(SmoothedDirections) { - vector<PointF> path; - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 0)); + vector<PointD> path; + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 0)); Spline spl(path); - float const sqrt2 = sqrtf(2.0f); + double const sqrt2 = sqrt(2.0); Spline::iterator itr; - PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f); - PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f); + PointD dir1(sqrt2 / 2.0, sqrt2 / 2.0); + PointD dir2(sqrt2 / 2.0, -sqrt2 / 2.0); itr.Attach(spl); - TestPointFDir(itr.m_avrDir, dir1); - itr.Step(sqrt2 * 30.0f); - TestPointFDir(itr.m_avrDir, dir1); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_avrDir, dir1 * 0.25f + dir2 * 0.75f); - itr.Step(sqrt2 * 10.0f); - TestPointFDir(itr.m_avrDir, dir2); + TestPointDDir(itr.m_avrDir, dir1); + itr.Step(sqrt2 * 30.0); + TestPointDDir(itr.m_avrDir, dir1); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_avrDir, dir1 * 0.25 + dir2 * 0.75); + itr.Step(sqrt2 * 10.0); + TestPointDDir(itr.m_avrDir, dir2); path.clear(); - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 40)); - path.push_back(PointF(120, 0)); + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 40)); + path.push_back(PointD(120, 0)); - PointF dir12(1.0f, 0.0f); + PointD dir12(1.0, 0.0); Spline spl2(path); itr.Attach(spl2); - TestPointFDir(itr.m_avrDir, dir1); - itr.Step(sqrt2 * 80.0f + 40.0f); - TestPointFDir(itr.m_avrDir, dir12); + TestPointDDir(itr.m_avrDir, dir1); + itr.Step(sqrt2 * 80.0 + 40.0); + TestPointDDir(itr.m_avrDir, dir12); itr.Attach(spl2); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_avrDir, dir1); - itr.Step(80.0f); - TestPointFDir(itr.m_avrDir, dir12 * 0.5f + dir2 * 0.5f); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_avrDir, dir1); + itr.Step(80.0); + TestPointDDir(itr.m_avrDir, dir12 * 0.5 + dir2 * 0.5); } UNIT_TEST(UsualDirections) { - vector<PointF> path; - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 0)); + vector<PointD> path; + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 0)); Spline spl(path); - float const sqrt2 = sqrtf(2.0f); + double const sqrt2 = sqrtf(2.0); Spline::iterator itr; - PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f); - PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f); + PointD dir1(sqrt2 / 2.0, sqrt2 / 2.0); + PointD dir2(sqrt2 / 2.0, -sqrt2 / 2.0); itr.Attach(spl); - TestPointFDir(itr.m_dir, dir1); - itr.Step(sqrt2 * 30.0f); - TestPointFDir(itr.m_dir, dir1); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_dir, dir2); + TestPointDDir(itr.m_dir, dir1); + itr.Step(sqrt2 * 30.0); + TestPointDDir(itr.m_dir, dir1); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_dir, dir2); path.clear(); - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 40)); - path.push_back(PointF(120, 0)); + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 40)); + path.push_back(PointD(120, 0)); - PointF dir12(1.0f, 0.0f); + PointD dir12(1.0, 0.0); Spline spl2(path); itr.Attach(spl2); - TestPointFDir(itr.m_dir, dir1); - itr.Step(sqrt2 * 80.0f + 35.0f); - TestPointFDir(itr.m_dir, dir2); + TestPointDDir(itr.m_dir, dir1); + itr.Step(sqrt2 * 80.0 + 35.0); + TestPointDDir(itr.m_dir, dir2); itr.Attach(spl2); - itr.Step(sqrt2 * 45.0f); - TestPointFDir(itr.m_dir, dir12); - itr.Step(80.0f); - TestPointFDir(itr.m_dir, dir2); + itr.Step(sqrt2 * 45.0); + TestPointDDir(itr.m_dir, dir12); + itr.Step(80.0); + TestPointDDir(itr.m_dir, dir2); } UNIT_TEST(Positions) { - vector<PointF> path; - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 0)); + vector<PointD> path; + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 0)); Spline spl0(path); Spline spl4; spl4 = spl0; - float const sqrt2 = sqrtf(2.0f); + double const sqrt2 = sqrt(2.0); Spline::iterator itr; itr.Attach(spl0); - TestPointFDir(itr.m_pos, PointF(0, 0)); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(40, 40)); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(80, 0)); + TestPointDDir(itr.m_pos, PointD(0, 0)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(40, 40)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(80, 0)); itr.Attach(spl4); - TestPointFDir(itr.m_pos, PointF(0, 0)); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(40, 40)); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(80, 0)); + TestPointDDir(itr.m_pos, PointD(0, 0)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(40, 40)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(80, 0)); path.clear(); - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 40)); - path.push_back(PointF(120, 0)); + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 40)); + path.push_back(PointD(120, 0)); Spline spl2(path); Spline spl3 = spl2; itr.Attach(spl3); - TestPointFDir(itr.m_pos, PointF(0, 0)); - itr.Step(sqrt2 * 80.0f + 40.0f); - TestPointFDir(itr.m_pos, PointF(120, 0)); + TestPointDDir(itr.m_pos, PointD(0, 0)); + itr.Step(sqrt2 * 80.0 + 40.0); + TestPointDDir(itr.m_pos, PointD(120, 0)); itr.Attach(spl2); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(40, 40)); - itr.Step(2.0f); - TestPointFDir(itr.m_pos, PointF(42, 40)); - itr.Step(20.0f); - TestPointFDir(itr.m_pos, PointF(62, 40)); - itr.Step(18.0f); - TestPointFDir(itr.m_pos, PointF(80, 40)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(40, 40)); + itr.Step(2.0); + TestPointDDir(itr.m_pos, PointD(42, 40)); + itr.Step(20.0); + TestPointDDir(itr.m_pos, PointD(62, 40)); + itr.Step(18.0); + TestPointDDir(itr.m_pos, PointD(80, 40)); } UNIT_TEST(BeginAgain) { - vector<PointF> path; - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 0)); + vector<PointD> path; + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 0)); Spline spl(path); - float const sqrt2 = sqrtf(2.0f); + double const sqrt2 = sqrtf(2.0); Spline::iterator itr; - PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f); - PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f); + PointD dir1(sqrt2 / 2.0, sqrt2 / 2.0); + PointD dir2(sqrt2 / 2.0, -sqrt2 / 2.0); itr.Attach(spl); TEST_EQUAL(itr.BeginAgain(), false, ()); - itr.Step(90.0f); + itr.Step(90.0); TEST_EQUAL(itr.BeginAgain(), false, ()); - itr.Step(90.0f); + itr.Step(90.0); TEST_EQUAL(itr.BeginAgain(), true, ()); - itr.Step(190.0f); + itr.Step(190.0); TEST_EQUAL(itr.BeginAgain(), true, ()); path.clear(); - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 40)); - path.push_back(PointF(120, 0)); + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 40)); + path.push_back(PointD(120, 0)); Spline spl2(path); itr.Attach(spl2); TEST_EQUAL(itr.BeginAgain(), false, ()); - itr.Step(90.0f); + itr.Step(90.0); TEST_EQUAL(itr.BeginAgain(), false, ()); - itr.Step(90.0f); + itr.Step(90.0); TEST_EQUAL(itr.BeginAgain(), true, ()); - itr.Step(190.0f); + itr.Step(190.0); TEST_EQUAL(itr.BeginAgain(), true, ()); } UNIT_TEST(Length) { - vector<PointF> path; - PointF const p1(27.5536633f, 64.2492523f); - PointF const p2(27.5547638f, 64.2474289f); - PointF const p3(27.5549412f, 64.2471237f); - PointF const p4(27.5559044f, 64.2456436f); - PointF const p5(27.556284f, 64.2451782f); + vector<PointD> path; + PointD const p1(27.5536633, 64.2492523); + PointD const p2(27.5547638, 64.2474289); + PointD const p3(27.5549412, 64.2471237); + PointD const p4(27.5559044, 64.2456436); + PointD const p5(27.556284, 64.2451782); path.push_back(p1); path.push_back(p2); path.push_back(p3); path.push_back(p4); path.push_back(p5); Spline spl(path); - float len1 = spl.GetLength(); - float l1 = p1.Length(p2); - float l2 = p2.Length(p3); - float l3 = p3.Length(p4); - float l4 = p4.Length(p5); - float len2 = l1 + l2 + l3 + l4; + double len1 = spl.GetLength(); + double l1 = p1.Length(p2); + double l2 = p2.Length(p3); + double l3 = p3.Length(p4); + double l4 = p4.Length(p5); + double len2 = l1 + l2 + l3 + l4; TEST_ALMOST_EQUAL(len1, len2, ()); } |