Merge pull request #1177 from vissarion/fix/within_segment_pole

[within] Fix the case when a segment has as an endpoint a pole
This commit is contained in:
Vissarion Fisikopoulos 2023-07-27 15:03:27 +03:00 committed by GitHub
commit 0ecc1263c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 268 additions and 122 deletions

View File

@ -3,8 +3,9 @@
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013-2017 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2013-2021.
// Modifications copyright (c) 2013-2021 Oracle and/or its affiliates.
// This file was modified by Oracle on 2013-2023.
// Modifications copyright (c) 2013-2023 Oracle and/or its affiliates.
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
@ -273,11 +274,9 @@ protected:
calc_t const anti_p_lon = p_lon + (p_lon <= c0 ? pi : -pi);
eq1 = eq1_strict // lon strictly equal to s1
|| (eq1_anti = longitudes_equal<units_t>(s1_lon, anti_p_lon)) // anti-lon strictly equal to s1
|| math::equals(math::abs(s1_lat), half_pi); // s1 is pole
|| (eq1_anti = longitudes_equal<units_t>(s1_lon, anti_p_lon)); // anti-lon strictly equal to s1
eq2 = eq2_strict // lon strictly equal to s2
|| (eq2_anti = longitudes_equal<units_t>(s2_lon, anti_p_lon)) // anti-lon strictly equal to s2
|| math::equals(math::abs(s2_lat), half_pi); // s2 is pole
|| (eq2_anti = longitudes_equal<units_t>(s2_lon, anti_p_lon)); // anti-lon strictly equal to s2
// segment overlapping pole
calc_t const s_lon_diff = math::longitude_distance_signed<units_t>(s1_lon, s2_lon);
@ -293,6 +292,28 @@ protected:
}
}
// check whether point is on a segment with a pole endpoint
if (math::longitude_distance_signed<units_t>(s2_lon, p_lon) == c0)
{
bool const s1_north = math::equals(get<1>(seg1), half_pi);
bool const s1_south = math::equals(get<1>(seg1), -half_pi);
if (s1_north || s1_south)
{
state.m_touches = s1_south ? s2_lat > p_lat : s2_lat < p_lat;
return state.m_touches;
}
}
if (math::longitude_distance_signed<units_t>(s1_lon, p_lon) == c0)
{
bool const s2_north = math::equals(get<1>(seg2), half_pi);
bool const s2_south = math::equals(get<1>(seg2), -half_pi);
if (s2_north || s2_south)
{
state.m_touches = s2_south ? s1_lat > p_lat : s1_lat < p_lat;
return state.m_touches;
}
}
// Both equal p -> segment vertical
// The only thing which has to be done is check if point is ON segment
if (eq1 && eq2)
@ -361,7 +382,17 @@ protected:
// If needed (eq1 && eq2 ? 0) could be returned
calc_t const c0 = 0;
calc_t const c2 = 2;
calc_t const pi = constants::half_period();
calc_t const half_pi = pi / c2;
bool const s1_is_pole = math::equals(std::abs(get<1>(seg1)), half_pi);
bool const s2_is_pole = math::equals(std::abs(get<1>(seg2)), half_pi);
if (s1_is_pole && s2_is_pole)
{
return count_info(0, false);
}
calc_t const p = get<0>(point);
calc_t const s1 = get<0>(seg1);

View File

@ -1,6 +1,6 @@
// Boost.Geometry
// Copyright (c) 2016-2022 Oracle and/or its affiliates.
// Copyright (c) 2016-2023 Oracle and/or its affiliates.
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
@ -110,7 +110,7 @@ void test_point_polygon()
std::is_same<typename bg::cs_tag<P>::type, bg::geographic_tag>::value,
bg::strategy::within::geographic_winding<P>,
bg::strategy::within::spherical_winding<P>
> s;
> ws;
using poly = bg::model::polygon<P>;
@ -121,7 +121,7 @@ void test_point_polygon()
test_geometry<P, poly>("POINT(-179 0)",
"POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
false,
s);
ws);
test_geometry<P, poly>("POINT(1 0)",
"POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
@ -129,7 +129,233 @@ void test_point_polygon()
test_geometry<P, poly>("POINT(1 0)",
"POLYGON((0 0, 0 2, 2 0, 0 -2, 0 0))",
true,
s);
ws);
using Point = P;
// Segment going through pole
{
bg::model::polygon<Point> poly_n1;
bg::read_wkt("POLYGON((-90 80,90 80,90 70,-90 70, -90 80))", poly_n1);
// Points on segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 85), poly_n1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, 85), poly_n1, ws), true);
// Points on pole
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, 90), poly_n1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, 90), poly_n1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, 90), poly_n1, ws), true);
}
// Segment going through pole
{
bg::model::polygon<Point> poly_n2;
bg::read_wkt("POLYGON((-90 80,90 70,0 70,-90 80))", poly_n2);
// Points on segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 85), poly_n2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, 75), poly_n2, ws), true);
// Points outside but on the same level as segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 75), poly_n2, ws), false);
}
// Possibly invalid, 2-segment polygon with segment going through pole
/*{
bg::model::polygon<Point> poly_n;
bg::read_wkt("POLYGON((-90 80,90 70,-90 80))", poly_n);
// Point within
BOOST_CHECK_EQUAL(bg::within(Point(0, 89), poly_n), true);
// Points on segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 85), poly_n), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, 75), poly_n), true);
// Points outside but on the same level as segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 75), poly_n), false);
}*/
// Segment endpoints on North pole with arbitrary longitudes
{
bg::model::polygon<Point> poly_n4;
bg::read_wkt("POLYGON((45 90,45 80,-10 80,45 90))", poly_n4);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, 85), poly_n4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, 85), poly_n4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, 85), poly_n4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, 85), poly_n4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, 85), poly_n4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-5, 85), poly_n4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, 70), poly_n4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, 70), poly_n4, ws), false);
// the same polygon but with two points representing the pole
bg::model::polygon<Point> poly_n4b;
bg::read_wkt("POLYGON((45 90,45 80,-10 80,60 90,45 90))", poly_n4b);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, 85), poly_n4b, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, 85), poly_n4b, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, 85), poly_n4b, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, 85), poly_n4b, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, 85), poly_n4b, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-5, 85), poly_n4b, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, 70), poly_n4b, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, 70), poly_n4b, ws), false);
bg::model::polygon<Point> poly_n5;
bg::read_wkt("POLYGON((0 90,-10 80,45 80,0 90))", poly_n5);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, 85), poly_n5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, 85), poly_n5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, 85), poly_n5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(1, 85), poly_n5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, 85), poly_n5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, 85), poly_n5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, 85), poly_n5, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-5, 85), poly_n5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, 70), poly_n5, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, 70), poly_n5, ws), false);
bg::model::polygon<Point> poly_n_4edges;
bg::read_wkt("POLYGON((0 90,-10 70,5 60,20 80,0 90))", poly_n_4edges);
BOOST_CHECK_EQUAL(bg::covered_by(Point(3, 89), poly_n_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, 87), poly_n_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, 86), poly_n_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(15, 84), poly_n_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, 61), poly_n_4edges, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(15, 81), poly_n_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(7, 50), poly_n_4edges, ws), false);
bg::model::polygon<Point> poly_n_5edges;
bg::read_wkt("POLYGON((0 90,-10 70,5 60,10 85,20 80,0 90))", poly_n_5edges);
BOOST_CHECK_EQUAL(bg::covered_by(Point(3, 89), poly_n_5edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, 87), poly_n_5edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, 86), poly_n_5edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(15, 84), poly_n_5edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, 61), poly_n_5edges, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(15, 81), poly_n_5edges, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(7, 50), poly_n_5edges, ws), false);
}
// Segment going through pole
{
bg::model::polygon<Point> poly_s1;
bg::read_wkt("POLYGON((-90 -80,-90 -70,90 -70,90 -80,-90 -80))", poly_s1);
// Points on segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, -85), poly_s1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, -85), poly_s1, ws), true);
// Points on pole
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, -90), poly_s1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, -90), poly_s1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, -90), poly_s1, ws), true);
}
// Segment endpoints on South pole with arbitrary longitudes
{
bg::model::polygon<Point> poly_s2;
bg::read_wkt("POLYGON((45 -90,0 -80,45 -80,45 -90))", poly_s2);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, -85), poly_s2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, -85), poly_s2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, -85), poly_s2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, -85), poly_s2, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-5, -85), poly_s2, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, -70), poly_s2, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, -70), poly_s2, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-5, -70), poly_s2, ws), false);
bg::model::polygon<Point> poly_s3;
bg::read_wkt("POLYGON((45 -90,-10 -80,45 -80,45 -90))", poly_s3);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, -85), poly_s3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, -85), poly_s3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, -85), poly_s3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(1, -85), poly_s3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, -85), poly_s3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, -85), poly_s3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, -85), poly_s3, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-5, -85), poly_s3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, -70), poly_s3, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, -70), poly_s3, ws), false);
bg::model::polygon<Point> poly_s5;
bg::read_wkt("POLYGON((0 -90,-10 -80,45 -80,0 -90))", poly_s5);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, -85), poly_s5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, -85), poly_s5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, -85), poly_s5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(1, -85), poly_s5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, -85), poly_s5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, -85), poly_s5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, -85), poly_s5, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-5, -85), poly_s5, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, -70), poly_s5, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, -70), poly_s5, ws), false);
bg::model::polygon<Point> poly_s4;
bg::read_wkt("POLYGON((0 -89,-10 -80,45 -80,0 -89))", poly_s4);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, -85), poly_s4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, -85), poly_s4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, -85), poly_s4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, -85), poly_s4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, -85), poly_s4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-5, -85), poly_s4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(30, -71), poly_s4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(50, -70), poly_s4, ws), false);
//more complex examples
bg::model::polygon<Point> poly_s_complex_4edges;
bg::read_wkt("POLYGON((0 -90,-10 -70,5 -60,20 -80,0 -90))", poly_s_complex_4edges);
BOOST_CHECK_EQUAL(bg::covered_by(Point(3, -89), poly_s_complex_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, -87), poly_s_complex_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, -86), poly_s_complex_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(15, -84), poly_s_complex_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, -61), poly_s_complex_4edges, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(15, -81), poly_s_complex_4edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(7, -50), poly_s_complex_4edges, ws), false);
bg::model::polygon<Point> poly_s_complex_5edges;
bg::read_wkt("POLYGON((0 -90,-10 -70,5 -60,10 -85,20 -80,0 -90))", poly_s_complex_5edges);
BOOST_CHECK_EQUAL(bg::covered_by(Point(3, -89), poly_s_complex_5edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, -87), poly_s_complex_5edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-10, -86), poly_s_complex_5edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(15, -84), poly_s_complex_5edges, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(-1, -61), poly_s_complex_5edges, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(15, -81), poly_s_complex_5edges, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(7, -50), poly_s_complex_5edges, ws), false);
}
// Polygon covering nearly half of the globe but no poles
{
bg::model::polygon<Point> poly_h1;
bg::read_wkt("POLYGON((170 0, 170 -80,10 -80,0 -80,0 -20,10 -20,10 20,0 20,0 80,10 80,170 80,170 0))", poly_h1);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 90), poly_h1, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 85), poly_h1, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 50), poly_h1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 0), poly_h1, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -50), poly_h1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -85), poly_h1, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -90), poly_h1, ws), false);
}
// Polygon covering more than half of the globe with both holes
{
bg::model::polygon<Point> poly_h2;
bg::read_wkt("POLYGON((180 0, 180 -80,0 -80,10 -80,10 -20,0 -20,0 20,10 20,10 80,0 80,180 80,180 0))", poly_h2);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 90), poly_h2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 85), poly_h2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 50), poly_h2, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 0), poly_h2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -50), poly_h2, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -85), poly_h2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -90), poly_h2, ws), true);
}
// Polygon covering around half of the globe covering south pole
{
bg::model::polygon<Point> poly_h3;
bg::read_wkt("POLYGON((180 0, 180 -80,0 -80,0 -20,10 -20,10 20,0 20,0 80,10 80,170 80,180 0))", poly_h3);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 90), poly_h3, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 85), poly_h3, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 50), poly_h3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 0), poly_h3, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -50), poly_h3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -85), poly_h3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -90), poly_h3, ws), true);
}
// Polygon covering around half of the globe covering north pole
{
bg::model::polygon<Point> poly_h4;
bg::read_wkt("POLYGON((180 0, 170 -80,10 -80,10 -20,0 -20,0 20,10 20,10 80,0 80,180 80,180 0))", poly_h4);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 90), poly_h4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 85), poly_h4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 50), poly_h4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 0), poly_h4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -50), poly_h4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -85), poly_h4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -90), poly_h4, ws), false);
}
}
template <typename P>

View File

@ -63,7 +63,7 @@ void test_p_l()
test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1))", true);
test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1),(0 0,1 0))", false);
test_geometry<P, mls>("POINT(1 1)", "MULTILINESTRING((0 0, 1 1),(1 1, 2 2))", true);
test_geometry<P, mls>("POINT(1 1)", "MULTILINESTRING((0 0, 1 1),(2 2, 3 3))", false);
@ -252,117 +252,6 @@ void test_spherical_geographic()
BOOST_CHECK_EQUAL(bg::within(pt_n23, poly_n, ws), false);
BOOST_CHECK_EQUAL(bg::within(pt_n24, poly_n, ws), false);
}
// TODO: Move to covered_by tests
// Segment going through pole
{
bg::model::polygon<Point> poly_n1;
bg::read_wkt("POLYGON((-90 80,90 80,90 70,-90 70, -90 80))", poly_n1);
// Points on segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 85), poly_n1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, 85), poly_n1, ws), true);
// Points on pole
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, 90), poly_n1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, 90), poly_n1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, 90), poly_n1, ws), true);
}
// Segment going through pole
{
bg::model::polygon<Point> poly_n2;
bg::read_wkt("POLYGON((-90 80,90 70,0 70,-90 80))", poly_n2);
// Points on segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 85), poly_n2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, 75), poly_n2, ws), true);
// Points outside but on the same level as segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 75), poly_n2, ws), false);
}
// Possibly invalid, 2-segment polygon with segment going through pole
/*{
bg::model::polygon<Point> poly_n;
bg::read_wkt("POLYGON((-90 80,90 70,-90 80))", poly_n);
// Point within
BOOST_CHECK_EQUAL(bg::within(Point(0, 89), poly_n), true);
// Points on segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 85), poly_n), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, 75), poly_n), true);
// Points outside but on the same level as segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, 75), poly_n), false);
}*/
// Segment endpoints on pole with arbitrary longitudes
{
bg::model::polygon<Point> poly_n3;
bg::read_wkt("POLYGON((45 90,45 80,0 80,45 90))", poly_n3);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, 85), poly_n3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, 85), poly_n3, ws), true);
}
// Segment going through pole
{
bg::model::polygon<Point> poly_s1;
bg::read_wkt("POLYGON((-90 -80,-90 -70,90 -70,90 -80,-90 -80))", poly_s1);
// Points on segment
BOOST_CHECK_EQUAL(bg::covered_by(Point(-90, -85), poly_s1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, -85), poly_s1, ws), true);
// Points on pole
BOOST_CHECK_EQUAL(bg::covered_by(Point(90, -90), poly_s1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, -90), poly_s1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, -90), poly_s1, ws), true);
}
// Segment endpoints on pole with arbitrary longitudes
{
bg::model::polygon<Point> poly_s2;
bg::read_wkt("POLYGON((45 -90,0 -80,45 -80,45 -90))", poly_s2);
BOOST_CHECK_EQUAL(bg::covered_by(Point(0, -85), poly_s2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(45, -85), poly_s2, ws), true);
}
// Polygon covering nearly half of the globe but no poles
{
bg::model::polygon<Point> poly_h1;
bg::read_wkt("POLYGON((170 0, 170 -80,10 -80,0 -80,0 -20,10 -20,10 20,0 20,0 80,10 80,170 80,170 0))", poly_h1);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 90), poly_h1, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 85), poly_h1, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 50), poly_h1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 0), poly_h1, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -50), poly_h1, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -85), poly_h1, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -90), poly_h1, ws), false);
}
// Polygon covering more than half of the globe with both holes
{
bg::model::polygon<Point> poly_h2;
bg::read_wkt("POLYGON((180 0, 180 -80,0 -80,10 -80,10 -20,0 -20,0 20,10 20,10 80,0 80,180 80,180 0))", poly_h2);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 90), poly_h2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 85), poly_h2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 50), poly_h2, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 0), poly_h2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -50), poly_h2, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -85), poly_h2, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -90), poly_h2, ws), true);
}
// Polygon covering around half of the globe covering south pole
{
bg::model::polygon<Point> poly_h3;
bg::read_wkt("POLYGON((180 0, 180 -80,0 -80,0 -20,10 -20,10 20,0 20,0 80,10 80,170 80,180 0))", poly_h3);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 90), poly_h3, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 85), poly_h3, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 50), poly_h3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 0), poly_h3, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -50), poly_h3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -85), poly_h3, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -90), poly_h3, ws), true);
}
// Polygon covering around half of the globe covering north pole
{
bg::model::polygon<Point> poly_h4;
bg::read_wkt("POLYGON((180 0, 170 -80,10 -80,10 -20,0 -20,0 20,10 20,10 80,0 80,180 80,180 0))", poly_h4);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 90), poly_h4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 85), poly_h4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 50), poly_h4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, 0), poly_h4, ws), true);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -50), poly_h4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -85), poly_h4, ws), false);
BOOST_CHECK_EQUAL(bg::covered_by(Point(5, -90), poly_h4, ws), false);
}
}
void test_large_integers()