diff options
author | vng <viktor.govako@gmail.com> | 2011-06-11 00:18:19 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:19:19 +0300 |
commit | ffa039a8498e214d4e8375d46c04fc11829eab43 (patch) | |
tree | ae3215a744667050d3070e92aa4c6dba5873be29 /geometry/geometry_tests/intersect_test.cpp | |
parent | 34365e4e2c41bed3b81947ad04682b723e5f7df5 (diff) |
Minor code fixes for Rect-Point intersection.
Diffstat (limited to 'geometry/geometry_tests/intersect_test.cpp')
-rw-r--r-- | geometry/geometry_tests/intersect_test.cpp | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/geometry/geometry_tests/intersect_test.cpp b/geometry/geometry_tests/intersect_test.cpp index 803b5a1b33..052e09334a 100644 --- a/geometry/geometry_tests/intersect_test.cpp +++ b/geometry/geometry_tests/intersect_test.cpp @@ -9,8 +9,14 @@ #include "../../base/start_mem_debug.hpp" + using namespace test; +namespace +{ + typedef m2::PointD P; +} + m2::PointD get_point(m2::RectD const & r, int ind) { switch (ind % 4) @@ -25,7 +31,7 @@ m2::PointD get_point(m2::RectD const & r, int ind) } } -void make_section_longer(m2::PointD & p1, m2::PointD & p2, double sm = 10.0) +void make_section_longer(m2::PointD & p1, m2::PointD & p2, double sm) { if (p1.x == p2.x) { @@ -54,20 +60,17 @@ void check_full_equal(m2::RectD const & r, m2::PointD const & p1, m2::PointD con { m2::PointD pp1 = p1; m2::PointD pp2 = p2; - make_section_longer(pp1, pp2); + make_section_longer(pp1, pp2, 1000.0); TEST(m2::Intersect(r, pp1, pp2), ()); TEST(comp(pp1, p1) && comp(pp2, p2), ()); } -void check_inside(m2::RectD const & r, m2::PointD p1, m2::PointD p2) +void check_inside(m2::RectD const & r, m2::PointD const & p1, m2::PointD const & p2) { - double const sm = p1.Length(p2) / 4.0; - make_section_longer(p1, p2, -sm); - m2::PointD pp1 = p1; m2::PointD pp2 = p2; - TEST(m2::Intersect(r, p1, p2), ()); + TEST(m2::Intersect(r, pp1, pp2), ()); TEST((pp1 == p1) && (pp2 == p2), ()); } @@ -120,7 +123,7 @@ void check_eps_boundaries(m2::RectD const & r, double eps = 1.0E-6) check_inside(r, get_point(rr, i), get_point(rr, i+1)); } -UNIT_TEST(IntersectRectSection) +UNIT_TEST(IntersectRect_Section) { m2::RectD r(-1, -1, 2, 2); check_intersect_boundaries(r); @@ -128,3 +131,43 @@ UNIT_TEST(IntersectRectSection) check_sides(r); check_eps_boundaries(r); } + +namespace +{ + void check_point_in_rect(m2::RectD const & r, m2::PointD const & p) + { + m2::PointD p1 = p; + m2::PointD p2 = p; + + TEST(m2::Intersect(r, p1, p2), ()); + TEST(p == p1 && p == p2, ()); + } +} + +UNIT_TEST(IntersectRect_Point) +{ + { + m2::RectD r(-100, -100, 200, 200); + for (int i = 0; i < 4; ++i) + { + check_point_in_rect(r, get_point(r, i)); + check_point_in_rect(r, (get_point(r, i) + get_point(r, i+1)) / 2.0); + } + } + + { + m2::RectD r(-1000, -1000, 1000, 1000); + double const eps = 1.0E-6; + P sm[] = { P(-eps, -eps), P(-eps, eps), P(eps, eps), P(eps, -eps) }; + for (int i = 0; i < 4; ++i) + { + P p1 = get_point(r, i); + P p2 = p1 - sm[i]; + check_inside(r, p1, p2); + + p1 = p1 + sm[i]; + p2 = p1 + sm[i]; + TEST(!m2::Intersect(r, p1, p2), ()); + } + } +} |