Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Sorokin <sorok-roma@yandex.ru>2014-07-29 12:30:13 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:22:27 +0300
commit5ba211579142c460139a70f47756a21471216a78 (patch)
treed3ff9a962235de42c136f8ad633fe5e25984a615 /geometry/geometry_tests/spline_test.cpp
parent6e77c3c4a8c62bfe88e7769023a8045dd33a9ff0 (diff)
tests for Spline::iterator
Diffstat (limited to 'geometry/geometry_tests/spline_test.cpp')
-rw-r--r--geometry/geometry_tests/spline_test.cpp193
1 files changed, 193 insertions, 0 deletions
diff --git a/geometry/geometry_tests/spline_test.cpp b/geometry/geometry_tests/spline_test.cpp
new file mode 100644
index 0000000000..ac0d5a0dea
--- /dev/null
+++ b/geometry/geometry_tests/spline_test.cpp
@@ -0,0 +1,193 @@
+#include "../../base/SRC_FIRST.hpp"
+#include "../../testing/testing.hpp"
+#include "equality.hpp"
+#include "../spline.hpp"
+
+using m2::Spline;
+using m2::PointF;
+
+void TestPointFDir(PointF const & dst, PointF const & src)
+{
+ float len1 = dst.Length();
+ float 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));
+
+ Spline spl;
+ spl.FromArray(path);
+ float const sqrt2 = sqrtf(2.0f);
+ Spline::iterator itr;
+ PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f);
+ PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f);
+ 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);
+
+ 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));
+
+ PointF dir12(1.0f, 0.0f);
+ Spline spl2;
+ spl2.FromArray(path);
+ itr.Attach(spl2);
+ TestPointFDir(itr.m_avrDir, dir1);
+ itr.Step(sqrt2 * 80.0f + 40.0f);
+ TestPointFDir(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);
+}
+
+UNIT_TEST(UsualDirections)
+{
+ vector<PointF> path;
+ path.push_back(PointF(0, 0));
+ path.push_back(PointF(40, 40));
+ path.push_back(PointF(80, 0));
+
+ Spline spl;
+ spl.FromArray(path);
+ float const sqrt2 = sqrtf(2.0f);
+ Spline::iterator itr;
+ PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f);
+ PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f);
+ 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);
+
+ 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));
+
+ PointF dir12(1.0f, 0.0f);
+ Spline spl2;
+ spl2.FromArray(path);
+ itr.Attach(spl2);
+ TestPointFDir(itr.m_dir, dir1);
+ itr.Step(sqrt2 * 80.0f + 35.0f);
+ TestPointFDir(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);
+}
+
+UNIT_TEST(Positions)
+{
+ vector<PointF> path;
+ path.push_back(PointF(0, 0));
+ path.push_back(PointF(40, 40));
+ path.push_back(PointF(80, 0));
+
+ Spline spl;
+ Spline spl0;
+ Spline spl4;
+ spl.FromArray(path);
+ spl0 = spl4 = spl;
+ float const sqrt2 = sqrtf(2.0f);
+ 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));
+ 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));
+
+ 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));
+
+ Spline spl2;
+ spl2.FromArray(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));
+ 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));
+}
+
+UNIT_TEST(BeginAgain)
+{
+ vector<PointF> path;
+ path.push_back(PointF(0, 0));
+ path.push_back(PointF(40, 40));
+ path.push_back(PointF(80, 0));
+
+ Spline spl;
+ spl.FromArray(path);
+ float const sqrt2 = sqrtf(2.0f);
+ Spline::iterator itr;
+ PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f);
+ PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f);
+ itr.Attach(spl);
+ TEST_EQUAL(itr.beginAgain(), false, ());
+ itr.Step(90.0f);
+ TEST_EQUAL(itr.beginAgain(), false, ());
+ itr.Step(90.0f);
+ TEST_EQUAL(itr.beginAgain(), true, ());
+ itr.Step(190.0f);
+ 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));
+
+ Spline spl2;
+ spl2.FromArray(path);
+ itr.Attach(spl2);
+ TEST_EQUAL(itr.beginAgain(), false, ());
+ itr.Step(90.0f);
+ TEST_EQUAL(itr.beginAgain(), false, ());
+ itr.Step(90.0f);
+ TEST_EQUAL(itr.beginAgain(), true, ());
+ itr.Step(190.0f);
+ TEST_EQUAL(itr.beginAgain(), true, ());
+}
+