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:
authorrachytski <siarhei.rachytski@gmail.com>2011-10-03 15:09:28 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:25:24 +0300
commit5d830d56494790a93533a9498c2d81cfd0632848 (patch)
treea69e336b5f4d163e5d89685a7cda0465f67090d7 /geometry/geometry_tests/anyrect_test.cpp
parentba7b5963e026d94becb96305d6329a7db430bf30 (diff)
renamed AARect into AnyRect. renamed corresponding files.
Diffstat (limited to 'geometry/geometry_tests/anyrect_test.cpp')
-rw-r--r--geometry/geometry_tests/anyrect_test.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/geometry/geometry_tests/anyrect_test.cpp b/geometry/geometry_tests/anyrect_test.cpp
new file mode 100644
index 0000000000..e998fa0108
--- /dev/null
+++ b/geometry/geometry_tests/anyrect_test.cpp
@@ -0,0 +1,72 @@
+#include "../../base/SRC_FIRST.hpp"
+
+#include "../../testing/testing.hpp"
+
+#include "../any_rect2d.hpp"
+
+#include "../../std/cmath.hpp"
+
+UNIT_TEST(AnyRect_TestConvertTo)
+{
+ m2::AnyRectD r(m2::PointD(0, 0), math::pi / 4, m2::RectD(0, 0, 10, 10));
+
+ m2::PointD pt1(100, 0);
+
+ double const sqrt2 = sqrt(2.0);
+ TEST(r.ConvertTo(pt1).EqualDxDy(m2::PointD(100 / sqrt2, -100 / sqrt2), 10e-5), ());
+ TEST(r.ConvertTo(m2::PointD(100, 100)).EqualDxDy(m2::PointD(100 * sqrt2, 0), 10e-5), ());
+
+ m2::AnyRectD r1(m2::PointD(100, 100), math::pi / 4, m2::RectD(0, 0, 10, 10));
+
+ m2::PointD pt(100, 100 + 50 * sqrt2);
+
+ TEST(r1.ConvertTo(pt).EqualDxDy(m2::PointD(50, 50), 10e-5), ());
+}
+
+UNIT_TEST(AnyRect_TestConvertFrom)
+{
+ m2::AnyRectD r(m2::PointD(100, 100), math::pi / 6, m2::RectD(0, 0, 10, 10));
+
+ double const sqrt3 = sqrt(3.0);
+ TEST(r.ConvertFrom(m2::PointD(50, 0)).EqualDxDy(m2::PointD(100 + 50 * sqrt3 / 2 , 100 + 50 * 1 / 2.0), 10e-5), ());
+ TEST(r.ConvertTo(m2::PointD(100 + 50 * sqrt3 / 2, 100 + 50 * 1.0 / 2)).EqualDxDy(m2::PointD(50, 0), 10e-5), ());
+}
+
+UNIT_TEST(AnyRect_ZeroRect)
+{
+ m2::AnyRectD r0(m2::RectD(0, 0, 0, 0));
+ m2::AnyRectD r1(m2::Offset(r0, m2::PointD(300.0, 300.0)));
+ m2::AnyRectD r2(m2::Inflate(r0, 2.0, 2.0));
+}
+
+UNIT_TEST(AnyRect_TestIntersection)
+{
+ m2::AnyRectD r0(m2::PointD(93.196, 104.21), 1.03, m2::RectD(2, 0, 4, 15));
+ m2::AnyRectD r1(m2::PointD(99.713, 116.02), -1.03, m2::RectD(0, 0, 14, 14));
+
+ m2::PointD pts[4];
+ r0.GetGlobalPoints(pts);
+ r1.ConvertTo(pts, 4);
+ m2::RectD r2(pts[0].x, pts[0].y, pts[0].x, pts[0].y);
+ r2.Add(pts[1]);
+ r2.Add(pts[2]);
+ r2.Add(pts[3]);
+
+ TEST(r1.GetLocalRect().IsIntersect(r2) == false, ());
+}
+
+UNIT_TEST(AnyRect_TestIsIntersect)
+{
+ m2::AnyRectD r0(m2::PointD(100, 100), math::pi / 6, m2::RectD(0, 0, 50, 20));
+ m2::AnyRectD r1(m2::PointD(100, 100), math::pi / 6, m2::RectD(0, -10, 50, 10));
+ m2::AnyRectD r2(m2::PointD(100, 100), math::pi / 6, m2::RectD(0, -21, 50, -1));
+
+ TEST(r0.IsIntersect(r1), ());
+ TEST(r1.IsIntersect(r2), ());
+ TEST(!r0.IsIntersect(r2), ());
+ TEST(r1.IsIntersect(r2), ());
+
+ m2::AnyRectD r3(m2::PointD(50, 50), math::pi / 8, m2::RectD(0, 0, 80, 30));
+ TEST(r0.IsIntersect(r3), ());
+}
+