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:
authorAlex Zolotarev <deathbaba@gmail.com>2011-01-16 19:51:09 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:10:15 +0300
commitce2e1baa9cfea1ecf9e1f12bec4d069487d763d7 (patch)
tree1d29ca564322af173c6172fe8e0be31776f7b2f0 /geometry/geometry_tests/region_test.cpp
parente5af392fc53cba0c94d7194951029a86ca9b5263 (diff)
Added m2::Region for 2d polygons
Diffstat (limited to 'geometry/geometry_tests/region_test.cpp')
-rw-r--r--geometry/geometry_tests/region_test.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/geometry/geometry_tests/region_test.cpp b/geometry/geometry_tests/region_test.cpp
new file mode 100644
index 0000000000..46b1887095
--- /dev/null
+++ b/geometry/geometry_tests/region_test.cpp
@@ -0,0 +1,70 @@
+#include "../../testing/testing.hpp"
+
+#include "../../base/macros.hpp"
+
+#include "../region2d.hpp"
+
+template<class TPoint>
+void Test()
+{
+ m2::Region<TPoint> region;
+
+ typedef TPoint P;
+
+ // rectangular polygon
+ {
+ P const data[] = { P(1, 1), P(10, 1), P(10, 10), P(1, 10) };
+ region.Assign(data, data + ARRAY_SIZE(data));
+ }
+ TEST_EQUAL(region.Rect(), m2::Rect<typename TPoint::value_type>(1, 1, 10, 10), ());
+
+ TEST(region.Contains(P(1, 1)), ());
+ TEST(region.Contains(P(2, 2)), ());
+ TEST(region.Contains(P(10, 5)), ());
+ TEST(region.Contains(P(1, 6)), ());
+ TEST(!region.Contains(P(0, 0)), ());
+ TEST(!region.Contains(P(100, 0)), ());
+
+ // triangle
+ {
+ P const data[] = {P(1, 1), P(10, 1), P(10, 10), P(1, 10)};
+ region.Assign(data, data + ARRAY_SIZE(data));
+ }
+
+}
+
+UNIT_TEST(Region_Contains)
+{
+ Test<m2::PointU>();
+ Test<m2::PointD>();
+ Test<m2::PointF>();
+ Test<m2::PointI>();
+
+ // negative triangle
+ {
+ typedef m2::PointI P;
+ m2::Region<P> region;
+ P const data[] = { P(1, -1), P(-2, -2), P(-3, 1) };
+ region.Assign(data, data + ARRAY_SIZE(data));
+
+ TEST_EQUAL(region.Rect(), m2::Rect<P::value_type>(-3, -2, 1, 1), ());
+
+ TEST(region.Contains(P(-2, -2)), ());
+ TEST(region.Contains(P(-2, 0)), ());
+ TEST(!region.Contains(P(0, 0)), ());
+ }
+
+ {
+ typedef m2::PointI P;
+ m2::Region<P> region;
+ P const data[] = { P(1, -1), P(3, 0), P(3, 3), P(0, 3), P(0, 2), P(0, 1), P(2, 2) };
+ region.Assign(data, data + ARRAY_SIZE(data));
+
+ TEST_EQUAL(region.Rect(), m2::Rect<P::value_type>(0, -1, 3, 3), ());
+
+ TEST(region.Contains(P(2, 2)), ());
+ TEST(region.Contains(P(1, 3)), ());
+ TEST(region.Contains(P(3, 1)), ());
+ TEST(!region.Contains(P(1, 1)), ());
+ }
+}