[DEV] add v1.76.0

This commit is contained in:
2021-10-05 21:37:46 +02:00
parent a97e9ae7d4
commit d0115b733d
45133 changed files with 4744437 additions and 1026325 deletions

View File

@@ -0,0 +1,27 @@
# Boost.Geometry (aka GGL, Generic Geometry Library)
#
# Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
# Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
# Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
#
# This file was modified by Oracle on 2014, 2015, 2016.
# Modifications copyright (c) 2014-2016, Oracle and/or its affiliates.
#
# Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
# Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
test-suite boost-geometry-algorithms-within
:
[ run within.cpp : : : : algorithms_within ]
[ run within_areal_areal.cpp : : : : algorithms_within_areal_areal ]
[ run within_linear_areal.cpp : : : : algorithms_within_linear_areal ]
[ run within_linear_linear.cpp : : : : algorithms_within_linear_linear ]
[ run within_multi.cpp : : : : algorithms_within_multi ]
[ run within_pointlike_geometry.cpp : : : : algorithms_within_pointlike_geometry ]
[ run within_sph.cpp : : : : algorithms_within_sph ]
[ run within_sph_geo.cpp : : : : algorithms_within_sph_geo ]
;

View File

@@ -0,0 +1,163 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014, 2015, 2017, 2019.
// Modifications copyright (c) 2014-2019 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_TEST_WITHIN_HPP
#define BOOST_GEOMETRY_TEST_WITHIN_HPP
#include <boost/variant/variant.hpp>
#include <geometry_test_common.hpp>
#include <boost/geometry/algorithms/covered_by.hpp>
#include <boost/geometry/algorithms/within.hpp>
#include <boost/geometry/core/ring_type.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/strategies/strategies.hpp>
struct no_strategy {};
template <typename Geometry1, typename Geometry2, typename Strategy>
bool call_within(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Strategy const& strategy)
{
return bg::within(geometry1, geometry2, strategy);
}
template <typename Geometry1, typename Geometry2>
bool call_within(Geometry1 const& geometry1,
Geometry2 const& geometry2,
no_strategy)
{
return bg::within(geometry1, geometry2);
}
template <typename Geometry1, typename Geometry2, typename Strategy>
void check_geometry(Geometry1 const& geometry1,
Geometry2 const& geometry2,
std::string const& wkt1,
std::string const& wkt2,
bool expected,
Strategy const& strategy)
{
bool detected = call_within(geometry1, geometry2, strategy);
BOOST_CHECK_MESSAGE(detected == expected,
"within: " << wkt1
<< " in " << wkt2
<< " -> Expected: " << expected
<< " detected: " << detected);
}
template <typename Geometry1, typename Geometry2>
void test_geometry(std::string const& wkt1,
std::string const& wkt2, bool expected)
{
Geometry1 geometry1;
Geometry2 geometry2;
bg::read_wkt(wkt1, geometry1);
bg::read_wkt(wkt2, geometry2);
boost::variant<Geometry1> v1(geometry1);
boost::variant<Geometry2> v2(geometry2);
typedef typename bg::strategy::within::services::default_strategy
<
Geometry1, Geometry2
>::type strategy_type;
check_geometry(geometry1, geometry2, wkt1, wkt2, expected, strategy_type());
check_geometry(geometry1, geometry2, wkt1, wkt2, expected, no_strategy());
check_geometry(v1, geometry2, wkt1, wkt2, expected, no_strategy());
check_geometry(geometry1, v2, wkt1, wkt2, expected, no_strategy());
check_geometry(v1, v2, wkt1, wkt2, expected, no_strategy());
}
template <typename Point, bool Clockwise, bool Closed>
void test_ordered_ring(std::string const& wkt_point,
std::string const& wkt_geometry, bool expected, bool on_border)
{
typedef bg::model::ring<Point, Clockwise, Closed> ring_type;
ring_type ring;
Point point;
bg::read_wkt(wkt_geometry, ring);
if ( BOOST_GEOMETRY_CONDITION(! Clockwise) )
{
std::reverse(boost::begin(ring), boost::end(ring));
}
bg::read_wkt(wkt_point, point);
bool detected = bg::within(point, ring);
BOOST_CHECK_MESSAGE(detected == expected,
"within: " << wkt_point
<< " in " << wkt_geometry
<< " -> Expected: " << expected
<< " detected: " << detected
<< " clockwise: " << int(Clockwise)
<< " closed: " << int(Closed)
);
// other strategy (note that this one cannot detect OnBorder
// (without modifications)
bg::strategy::within::franklin<Point> franklin;
detected = bg::within(point, ring, franklin);
if (! on_border)
{
BOOST_CHECK_MESSAGE(detected == expected,
"within: " << wkt_point
<< " in " << wkt_geometry
<< " -> Expected: " << expected
<< " detected: " << detected
<< " clockwise: " << int(Clockwise)
<< " closed: " << int(Closed)
);
}
bg::strategy::within::crossings_multiply<Point> cm;
detected = bg::within(point, ring, cm);
if (! on_border)
{
BOOST_CHECK_MESSAGE(detected == expected,
"within: " << wkt_point
<< " in " << wkt_geometry
<< " -> Expected: " << expected
<< " detected: " << detected
<< " clockwise: " << int(Clockwise)
<< " closed: " << int(Closed)
);
}
}
template <typename Point>
void test_ring(std::string const& wkt_point,
std::string const& wkt_geometry,
bool expected, bool on_border)
{
test_ordered_ring<Point, true, true>(wkt_point, wkt_geometry, expected, on_border);
test_ordered_ring<Point, false, true>(wkt_point, wkt_geometry, expected, on_border);
test_ordered_ring<Point, true, false>(wkt_point, wkt_geometry, expected, on_border);
test_ordered_ring<Point, false, false>(wkt_point, wkt_geometry, expected, on_border);
test_geometry<Point, bg::model::polygon<Point> >(wkt_point, wkt_geometry, expected);
}
#endif

View File

@@ -0,0 +1,143 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014-2020.
// Modifications copyright (c) 2014-2020 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_within.hpp"
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/multi_point.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
template <typename P1, typename P2>
void test_point_box()
{
typedef bg::model::box<P1> box_type1;
typedef bg::model::box<P2> box_type2;
test_geometry<P1, box_type2>("POINT(1 1)", "BOX(0 0,2 2)", true);
test_geometry<P1, box_type2>("POINT(0 0)", "BOX(0 0,2 2)", false);
test_geometry<P1, box_type2>("POINT(2 2)", "BOX(0 0,2 2)", false);
test_geometry<P1, box_type2>("POINT(0 1)", "BOX(0 0,2 2)", false);
test_geometry<P1, box_type2>("POINT(1 0)", "BOX(0 0,2 2)", false);
test_geometry<P1, box_type2>("POINT(3 3)", "BOX(1 1,4 4)", true);
test_geometry<P2, box_type1>("POINT(3 3)", "BOX(0 0,5 5)", true);
test_geometry<box_type1, box_type2>("BOX(1 1,2 2)", "BOX(0 0,3 3)", true);
test_geometry<box_type1, box_type2>("BOX(0 0,3 3)", "BOX(1 1,2 2)", false);
test_geometry<box_type1, box_type2>("BOX(1 1,3 3)", "BOX(0 0,3 3)", true);
test_geometry<box_type1, box_type2>("BOX(3 1,3 3)", "BOX(0 0,3 3)", false);
test_geometry<box_type1, box_type2>("BOX(1 1,4 4)", "BOX(0 0,5 5)", true);
test_geometry<box_type2, box_type1>("BOX(0 0,5 5)", "BOX(1 1,4 4)", false);
/*
test_within_code<P, box_type>("POINT(1 1)", "BOX(0 0,2 2)", 1);
test_within_code<P, box_type>("POINT(1 0)", "BOX(0 0,2 2)", 0);
test_within_code<P, box_type>("POINT(0 1)", "BOX(0 0,2 2)", 0);
test_within_code<P, box_type>("POINT(0 3)", "BOX(0 0,2 2)", -1);
test_within_code<P, box_type>("POINT(3 3)", "BOX(0 0,2 2)", -1);
test_within_code<box_type, box_type>("BOX(1 1,2 2)", "BOX(0 0,3 3)", 1);
test_within_code<box_type, box_type>("BOX(0 1,2 2)", "BOX(0 0,3 3)", 0);
test_within_code<box_type, box_type>("BOX(1 0,2 2)", "BOX(0 0,3 3)", 0);
test_within_code<box_type, box_type>("BOX(1 1,2 3)", "BOX(0 0,3 3)", 0);
test_within_code<box_type, box_type>("BOX(1 1,3 2)", "BOX(0 0,3 3)", 0);
test_within_code<box_type, box_type>("BOX(1 1,3 4)", "BOX(0 0,3 3)", -1);
*/
}
void test_point_box_3d()
{
typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> point_type;
typedef boost::geometry::model::box<point_type> box_type;
box_type box(point_type(0, 0, 0), point_type(4, 4, 4));
BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 2), box), true);
BOOST_CHECK_EQUAL(bg::within(point_type(2, 4, 2), box), false);
BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 4), box), false);
BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 5), box), false);
box_type box2(point_type(2, 2, 2), point_type(3, 3, 3));
BOOST_CHECK_EQUAL(bg::within(box2, box), true);
}
template <typename P1, typename P2>
void test_point_poly()
{
typedef boost::geometry::model::polygon<P1> poly1;
typedef boost::geometry::model::polygon<P2> poly2;
test_geometry<P1, poly2>("POINT(3 3)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
test_geometry<P2, poly1>("POINT(3 3)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
}
template <typename P1, typename P2>
void test_all()
{
test_point_box<P1, P2>();
test_point_poly<P1, P2>();
}
template <typename P>
void test_all()
{
test_all<P, P>();
}
void test_strategy()
{
// Test by explicitly specifying a strategy
typedef bg::model::d2::point_xy<double> point_type;
typedef bg::model::box<point_type> box_type;
point_type p(3, 3);
box_type b(point_type(0, 0), point_type(5, 5));
box_type b0(point_type(0, 0), point_type(5, 0));
bool r = bg::within(p, b,
bg::strategy::within::cartesian_point_box());
BOOST_CHECK_EQUAL(r, true);
r = bg::within(b0, b0,
bg::strategy::within::cartesian_box_box());
BOOST_CHECK_EQUAL(r, false);
r = bg::within(p, b,
bg::strategy::within::cartesian_point_box_by_side<>());
BOOST_CHECK_EQUAL(r, true);
}
int test_main( int , char* [] )
{
typedef boost::geometry::model::d2::point_xy<double> xyd;
typedef boost::geometry::model::d2::point_xy<float> xyf;
typedef boost::geometry::model::d2::point_xy<int> xyi;
typedef boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> p2d;
test_all<xyd, p2d>();
test_all<xyf, p2d>();
test_all<xyi, xyd>();
test_all<xyi>();
test_all<xyd>();
test_point_box_3d();
test_strategy();
return 0;
}

View File

@@ -0,0 +1,101 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014, 2015, 2016.
// Modifications copyright (c) 2014-2016 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_within.hpp"
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
template <typename P1, typename P2>
void test_a_a()
{
typedef bg::model::polygon<P1> poly1;
typedef bg::model::ring<P1> ring1;
typedef bg::model::multi_polygon<poly1> mpoly1;
typedef bg::model::polygon<P2> poly2;
typedef bg::model::ring<P2> ring2;
typedef bg::model::multi_polygon<poly2> mpoly2;
test_geometry<ring1, ring2>("POLYGON((0 0,0 2,2 2,2 0,0 0))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
test_geometry<ring1, poly2>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
test_geometry<poly1, ring2>("POLYGON((0 0,0 6,6 6,6 0,0 0))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false);
test_geometry<poly1, poly2>("POLYGON((0 0,0 9,9 9,9 0,0 0),(3 3,6 3,6 6,3 6,3 3))",
"POLYGON((0 0,0 9,9 9,9 0,0 0),(3 3,6 3,6 6,3 6,3 3))", true);
test_geometry<poly1, poly2>("POLYGON((0 0,0 9,9 9,9 0,0 0),(3 3,6 3,6 6,3 6,3 3))",
"POLYGON((0 0,0 9,9 9,9 0,0 0),(4 4,5 4,5 5,4 5,4 4))", true);
test_geometry<poly1, poly2>("POLYGON((1 1,1 8,8 8,8 1,1 1),(3 3,6 3,6 6,3 6,3 3))",
"POLYGON((0 0,0 9,9 9,9 0,0 0),(3 3,6 3,6 6,3 6,3 3))", true);
test_geometry<poly1, poly2>("POLYGON((1 1,1 8,8 8,8 1,1 1),(3 3,6 3,6 6,3 6,3 3))",
"POLYGON((0 0,0 9,9 9,9 0,0 0),(4 4,5 4,5 5,4 5,4 4))", true);
test_geometry<ring1, mpoly2>("POLYGON((0 0,0 2,2 2,2 0,0 0))",
"MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", true);
test_geometry<poly1, mpoly2>("POLYGON((0 0,0 2,2 2,2 0,0 0))",
"MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", true);
test_geometry<mpoly1, ring2>("MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))",
"POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
test_geometry<mpoly1, poly2>("MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((15 15,15 110,110 110,110 15,15 15)))",
"POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
test_geometry<mpoly1, poly2>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))",
"POLYGON((0 0,0 10,10 10,10 0,0 0),(3 3,4 3,4 4,3 4,3 3))", false);
test_geometry<mpoly1, mpoly2>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))",
"MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))", true);
test_geometry<mpoly1, mpoly2>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))",
"MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", true);
test_geometry<mpoly1, mpoly2>("MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))",
"MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))", false);
// https://svn.boost.org/trac/boost/ticket/10912
test_geometry<poly1, poly2>("POLYGON((0 0,0 5,5 5,5 0,0 0))",
"POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2),(6 6,8 6,8 8,6 8,6 6))",
false);
test_geometry<poly1, poly2>("POLYGON((0 0,0 10,10 10,10 0,0 0))",
"POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,2 4,4 4,4 2,2 2))",
false);
test_geometry<poly1, mpoly2>("POLYGON((0 0,0 5,5 5,5 0,0 0))",
"MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
true);
test_geometry<poly1, mpoly2>("POLYGON((0 0,0 10,10 10,10 0,0 0))",
"MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))",
true);
}
template <typename P1, typename P2>
void test_all()
{
test_a_a<P1, P2>();
}
template <typename P>
void test_all()
{
test_a_a<P, P>();
}
int test_main( int , char* [] )
{
test_all<bg::model::d2::point_xy<int> >();
test_all<bg::model::d2::point_xy<double> >();
test_all<bg::model::d2::point_xy<double>, bg::model::point<double, 2, bg::cs::cartesian> >();
return 0;
}

View File

@@ -0,0 +1,122 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014, 2015, 2016.
// Modifications copyright (c) 2014-2016 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_within.hpp"
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
template <typename P1, typename P2>
void test_l_a()
{
typedef bg::model::linestring<P1> ls;
typedef bg::model::multi_linestring<ls> mls;
typedef bg::model::polygon<P2> poly;
typedef bg::model::ring<P2> ring;
typedef bg::model::multi_polygon<poly> mpoly;
// B,I
test_geometry<ls, ring>("LINESTRING(0 0, 2 2)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
// B,I
test_geometry<ls, poly>("LINESTRING(0 0, 2 2)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
// I
test_geometry<ls, poly>("LINESTRING(1 1, 2 2)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
// I,E
test_geometry<ls, poly>("LINESTRING(1 1, 6 6)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false);
// B
test_geometry<ls, poly>("LINESTRING(0 0, 5 0)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false);
test_geometry<ls, poly>("LINESTRING(0 0, 0 5)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false);
// E
test_geometry<ls, poly>("LINESTRING(6 0, 6 5)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false);
// BIBIB
test_geometry<ls, mpoly>("LINESTRING(0 0, 10 10)", "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", true);
// BIBEBIB
test_geometry<ls, mpoly>("LINESTRING(0 0, 10 10)", "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((6 6,5 10,10 10,10 5,6 6)))", false);
// MySQL report 18.12.2014 (https://svn.boost.org/trac/boost/ticket/10887)
test_geometry<ls, mpoly>("LINESTRING(5 -2,5 2)",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
true);
test_geometry<ls, mpoly>("LINESTRING(5 -2,5 5)",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
true);
test_geometry<ls, mpoly>("LINESTRING(5 -2,5 0)",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
true);
// MySQL report 18.12.2014 - extended
test_geometry<ls, mpoly>("LINESTRING(5 -2,5 0)",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)),((5 0,7 1,7 -1,5 0)))",
true);
test_geometry<ls, mpoly>("LINESTRING(0 0,5 0)",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)),((5 0,7 1,7 -1,5 0)))",
false);
test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
true);
test_geometry<mls, mpoly>("MULTILINESTRING((0 0,0 1,5 0),(0 0,0 -1,5 0))",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
false);
test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(6 -2,5 0))",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
true);
test_geometry<mls, mpoly>("MULTILINESTRING((0 0,0 1,5 0),(0 -1,5 0))",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
false);
test_geometry<mls, mpoly>("MULTILINESTRING((0 0,5 0),(5 -2,5 0))",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
false);
test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,5 0),(0 0,5 0))",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
false);
// BI
test_geometry<mls, poly>("MULTILINESTRING((0 0,2 2),(2 2,3 3))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true);
// I E
test_geometry<mls, poly>("MULTILINESTRING((1 1,2 2),(6 6,7 7))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false);
// I I
test_geometry<mls, mpoly>("MULTILINESTRING((1 1,5 5),(6 6,7 7))",
"MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))",
true);
// I E
test_geometry<mls, mpoly>("MULTILINESTRING((1 1,5 5),(11 11,12 12))",
"MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))",
false);
}
template <typename P1, typename P2>
void test_all()
{
test_l_a<P1, P2>();
}
template <typename P>
void test_all()
{
test_l_a<P, P>();
}
int test_main( int , char* [] )
{
test_all<bg::model::d2::point_xy<int> >();
test_all<bg::model::d2::point_xy<double> >();
test_all<bg::model::d2::point_xy<double>, bg::model::point<double, 2, bg::cs::cartesian> >();
return 0;
}

View File

@@ -0,0 +1,104 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014, 2015, 2016.
// Modifications copyright (c) 2014-2016 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_within.hpp"
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>
template <typename P1, typename P2>
void test_l_l()
{
typedef bg::model::linestring<P1> ls1;
typedef bg::model::multi_linestring<ls1> mls1;
typedef bg::model::linestring<P2> ls2;
typedef bg::model::multi_linestring<ls2> mls2;
test_geometry<ls1, ls2>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true);
test_geometry<ls1, ls2>("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true);
test_geometry<ls1, ls2>("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(0 0, 2 2, 3 2)", true);
test_geometry<ls1, ls2>("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(3 2, 2 2, 0 0)", true);
test_geometry<ls1, ls2>("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(3 2, 2 2, 0 0)", true);
test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", true);
test_geometry<ls1, ls2>("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(0 0, 2 2, 4 2)", true);
test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(4 2, 2 2, 0 0)", true);
test_geometry<ls1, ls2>("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(4 2, 2 2, 0 0)", true);
test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false);
test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false);
test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false);
test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 3 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false);
test_geometry<ls1, ls2>("LINESTRING(0 1, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false);
test_geometry<ls1, ls2>("LINESTRING(0 1, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false);
test_geometry<ls1, ls2>("LINESTRING(1 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false);
test_geometry<ls1, ls2>("LINESTRING(1 0, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false);
// duplicated points
test_geometry<ls1, ls2>("LINESTRING(1 1, 2 2, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", true);
test_geometry<ls1, ls2>("LINESTRING(1 1, 1 1, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", true);
test_geometry<ls1, ls2>("LINESTRING(0 0, 0 0, 0 0, 1 1, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 3 3)",
"LINESTRING(0 0, 2 2, 4 4)", true);
// invalid linestrings
// test_geometry<ls1, ls2>("LINESTRING(0 0)", "LINESTRING(0 0)", false);
// test_geometry<ls1, ls2>("LINESTRING(1 1)", "LINESTRING(0 0, 2 2)", true);
// test_geometry<ls1, ls2>("LINESTRING(0 0)", "LINESTRING(0 0, 2 2)", false);
// test_geometry<ls1, ls2>("LINESTRING(0 0, 1 1)", "LINESTRING(0 0)", false);
// spikes
// FOR NOW DISABLED
/*test_geometry<ls1, ls2>("LINESTRING(0 0,5 0,3 0,6 0)", "LINESTRING(0 0,6 0)", true);
test_geometry<ls1, ls2>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,3 3,6 3)", true);
test_geometry<ls1, ls2>("LINESTRING(0 0,3 3,6 3)", "LINESTRING(0 0,2 2,3 3,1 1)", false);
test_geometry<ls1, ls2>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,4 4,6 3)", true);
test_geometry<ls1, ls2>("LINESTRING(0 0,4 4,6 3)", "LINESTRING(0 0,2 2,3 3,1 1)", false);
test_geometry<ls1, ls2>("LINESTRING(0 0,2 2,3 3,1 1,5 3)", "LINESTRING(0 0,3 3,6 3)", false);*/
test_geometry<ls1, mls2>("LINESTRING(1 1, 2 2)", "MULTILINESTRING((0 0, 2 2),(3 3, 4 4))", true);
test_geometry<mls1, ls2>("MULTILINESTRING((0 0, 2 2),(3 3, 4 4))", "LINESTRING(0 0, 5 5)", true);
test_geometry<mls1, mls2>("MULTILINESTRING((1 1, 2 2),(3 3, 4 4))", "MULTILINESTRING((1 1, 2 2),(2 2, 5 5))", true);
}
template <typename P1, typename P2>
void test_all()
{
test_l_l<P1, P2>();
}
template <typename P>
void test_all()
{
test_l_l<P, P>();
}
int test_main( int , char* [] )
{
test_all<bg::model::d2::point_xy<int> >();
test_all<bg::model::d2::point_xy<double> >();
test_all<bg::model::d2::point_xy<double>, bg::model::point<double, 2, bg::cs::cartesian> >();
return 0;
}

View File

@@ -0,0 +1,50 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <geometry_test_common.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/algorithms/correct.hpp>
#include <boost/geometry/algorithms/within.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
#include "test_within.hpp"
template <typename P>
void test_all()
{
typedef bg::model::multi_polygon<bg::model::polygon<P> > mp;
// test multi-with-one-polygon (trivial case)
test_geometry<P, mp>("POINT(1 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", true);
test_geometry<P, mp>("POINT(3 3)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false);
test_geometry<P, mp>("POINT(0 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false);
test_geometry<P, mp>("POINT(4 4)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false);
// test if it is in one of them
std::string multi("MULTIPOLYGON("
"((0 0,0 2,2 2,2 0,0 0))"
"((3 3,3 6,6 6,6 3,3 3))"
")");
test_geometry<P, mp>("POINT(4 4)", multi, true);
test_geometry<P, mp>("POINT(1 1)", multi, true);
test_geometry<P, mp>("POINT(0 1)", multi, false);
}
int test_main( int , char* [] )
{
//test_all<bg::model::d2::point_xy<int> >();
test_all<bg::model::d2::point_xy<double> >();
return 0;
}

View File

@@ -0,0 +1,456 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014, 2015, 2016, 2017.
// Modifications copyright (c) 2014-2017 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_within.hpp"
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/multi_point.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
template <typename P>
void test_p_p()
{
typedef bg::model::multi_point<P> mpt;
test_geometry<P, P>("POINT(0 0)", "POINT(0 0)", true);
test_geometry<P, P>("POINT(0 0)", "POINT(1 1)", false);
test_geometry<P, mpt>("POINT(0 0)", "MULTIPOINT(0 0, 1 1)", true);
test_geometry<P, mpt>("POINT(0 0)", "MULTIPOINT(1 1, 2 2)", false);
test_geometry<mpt, P>("MULTIPOINT(0 0)", "POINT(0 0)", true);
test_geometry<mpt, P>("MULTIPOINT(0 0, 1 1)", "POINT(0 0)", false);
test_geometry<mpt, P>("MULTIPOINT(0 0, 1 1)", "POINT(2 2)", false);
test_geometry<mpt, mpt>("MULTIPOINT(0 0)", "MULTIPOINT(0 0, 1 1)", true);
test_geometry<mpt, mpt>("MULTIPOINT(0 0, 1 1)", "MULTIPOINT(0 0, 1 1)", true);
test_geometry<mpt, mpt>("MULTIPOINT(0 0, 1 1)", "MULTIPOINT(0 0)", false);
test_geometry<mpt, mpt>("MULTIPOINT(0 0, 1 1)", "MULTIPOINT(1 1, 2 2)", false);
test_geometry<mpt, mpt>("MULTIPOINT(0 0, 1 1)", "MULTIPOINT(2 2, 3 4)", false);
}
template <typename P>
void test_p_l()
{
typedef bg::model::multi_point<P> mpt;
typedef bg::model::segment<P> seg;
typedef bg::model::linestring<P> ls;
typedef bg::model::multi_linestring<ls> mls;
test_geometry<P, seg>("POINT(1 1)", "LINESTRING(0 0, 2 2)", true);
test_geometry<P, seg>("POINT(0 0)", "LINESTRING(0 0, 1 1)", false);
test_geometry<P, seg>("POINT(1 0)", "LINESTRING(0 0, 1 1)", false);
test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0,1 1,2 2)", false);
test_geometry<P, ls>("POINT(3 3)", "LINESTRING(0 0,1 1,2 2)", false);
test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0,2 2,3 3)", true);
test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0, 2 2)", true);
test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0, 1 1)", false);
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);
test_geometry<mpt, seg>("MULTIPOINT(0 0, 1 1)", "LINESTRING(0 0, 2 2)", true);
test_geometry<mpt, ls>("MULTIPOINT(0 0, 2 2)", "LINESTRING(0 0, 2 2)", false);
test_geometry<mpt, ls>("MULTIPOINT(1 1, 3 3)", "LINESTRING(0 0, 2 2)", false);
test_geometry<mpt, mls>("MULTIPOINT(0 0, 1 1)", "MULTILINESTRING((0 0, 2 2),(2 2, 3 3))", true);
test_geometry<mpt, mls>("MULTIPOINT(0 0, 2 2)", "MULTILINESTRING((0 0, 2 2),(2 2, 3 3))", true);
test_geometry<mpt, mls>("MULTIPOINT(0 0, 3 3)", "MULTILINESTRING((0 0, 2 2),(2 2, 3 3))", false);
test_geometry<mpt, mls>("MULTIPOINT(1 1, 4 4)", "MULTILINESTRING((0 0, 2 2),(2 2, 3 3))", false);
}
template <typename P>
void test_p_a()
{
typedef bg::model::multi_point<P> mpt;
typedef bg::model::ring<P> ring;
typedef bg::model::polygon<P> poly;
typedef bg::model::multi_polygon<poly> mpoly;
// trivial case
test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true, false);
// on border/corner
test_ring<P>("POINT(0 0)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true);
test_ring<P>("POINT(0 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true);
// aligned to segment/vertex
test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", true, false);
test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", true, false);
// same polygon, but point on border
test_ring<P>("POINT(3 3)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", false, true);
test_ring<P>("POINT(3 3)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", false, true);
// holes
test_geometry<P, poly>("POINT(2 2)",
"POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1))", false);
// Real-life problem (solved now), point is in the middle, 409623 is also a coordinate
// on the border, has been wrong in the past (2009)
test_ring<P>("POINT(146383 409623)",
"POLYGON((146351 410597,146521 410659,147906 410363,148088 410420"
",148175 410296,148281 409750,148215 409623,148154 409666,148154 409666"
",148130 409625,148035 409626,148035 409626,148008 409544,147963 409510"
",147993 409457,147961 409352,147261 408687,147008 408586,145714 408840"
",145001 409033,144486 409066,144616 409308,145023 410286,145254 410488"
",145618 410612,145618 410612,146015 410565,146190 410545,146351 410597))",
true, false);
test_geometry<P, mpoly>("POINT(2 2)",
"MULTIPOLYGON(((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1)),((5 5,5 9,9 9,9 5,5 5)))", false);
test_geometry<P, mpoly>("POINT(1 1)",
"MULTIPOLYGON(((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1)),((5 5,5 9,9 9,9 5,5 5)))", false);
test_geometry<P, mpoly>("POINT(1 1)",
"MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0),(2 2,4 2,4 4,2 4,2 2)),((5 5,5 9,9 9,9 5,5 5)))", true);
test_geometry<P, mpoly>("POINT(6 6)",
"MULTIPOLYGON(((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1)),((5 5,5 9,9 9,9 5,5 5)))", true);
test_geometry<P, poly>("POINT(6 4)",
"POLYGON((0 5, 5 0, 6 1, 5 2, 8 4, 5 6, 6 7, 5 8, 6 9, 5 10, 0 5))", true);
test_geometry<P, poly>("POINT(4 6)",
"POLYGON((5 0, 0 5, 1 6, 2 5, 4 8, 6 5, 7 6, 8 5, 9 6, 10 5, 5 0))", true);
test_geometry<mpt, ring>("MULTIPOINT(0 0, 1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true);
test_geometry<mpt, poly>("MULTIPOINT(0 0, 2 2)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false);
test_geometry<mpt, poly>("MULTIPOINT(1 1, 3 3)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false);
test_geometry<mpt, mpoly>("MULTIPOINT(0 0, 1 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", true);
test_geometry<mpt, mpoly>("MULTIPOINT(0 0, 2 2)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", false);
test_geometry<mpt, mpoly>("MULTIPOINT(0 0, 3 3)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", false);
test_geometry<mpt, mpoly>("MULTIPOINT(1 1, 4 4)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((2 2,2 3,3 3,3 2,2 2)))", false);
}
template <typename P>
void test_all()
{
test_p_p<P>();
test_p_l<P>();
test_p_a<P>();
}
template <typename Point>
void test_spherical_geographic()
{
bg::model::polygon<Point> wrangel;
typename boost::mpl::if_
<
boost::is_same<typename bg::cs_tag<Point>::type, bg::geographic_tag>,
bg::strategy::within::geographic_winding<Point>,
bg::strategy::within::spherical_winding<Point>
>::type ws;
typename boost::mpl::if_
<
boost::is_same<typename bg::cs_tag<Point>::type, bg::geographic_tag>,
bg::strategy::side::geographic<>,
bg::strategy::side::spherical_side_formula<>
>::type ss;
boost::ignore_unused(ws, ss);
// SQL Server check (no geography::STWithin, so check with intersection trick)
/*
with q as (
select geography::STGeomFromText('POLYGON((-178.569 71.5641,-179.034 71.5977,-179.305 71.5514,-179.629 71.5772,-180 71.5358,179.53 71.4383,178.872 71.2175,178.618 71.0355,178.791 70.7964,179.273 70.8886,179.678 70.8955,-180 70.9972,-179.274 70.9078,-178.819 70.98,-177.939 71.0375,-177.62 71.1166,-177.439 71.2269,-177.503 71.2775,-177.833 71.3461,-178.018 71.4497,-178.569 71.5641))',4326) as wrangel
)
select wrangel.STArea()/1000000.0
,geography::STGeomFromText('POINT(-179.3 71.27)',4326).STIntersection(wrangel).STAsText() as workaround_within_1
,geography::STGeomFromText('POINT(-179.9 70.95)',4326).STIntersection(wrangel).STAsText() as workaround_within_2
,geography::STGeomFromText('POINT(179.9 70.95)',4326).STIntersection(wrangel).STAsText() as workaround_within_3
from q
-> 7669.10402181435 POINT (-179.3 71.27) GEOMETRYCOLLECTION EMPTY GEOMETRYCOLLECTION EMPTY
PostGIS knows Within for Geography neither, and the intersection trick gives the same result
*/
bg::read_wkt("POLYGON((-178.568604 71.564148,-178.017548 71.449692,-177.833313 71.3461,-177.502838 71.277466 ,-177.439453 71.226929,-177.620026 71.116638,-177.9389 71.037491,-178.8186 70.979965,-179.274445 70.907761,-180 70.9972,179.678314 70.895538,179.272766 70.888596,178.791016 70.7964,178.617737 71.035538,178.872192 71.217484,179.530273 71.4383 ,-180 71.535843 ,-179.628601 71.577194,-179.305298 71.551361,-179.03421 71.597748,-178.568604 71.564148))", wrangel);
bool within = bg::within(Point(-179.3, 71.27), wrangel);
BOOST_CHECK_EQUAL(within, true);
within = bg::within(Point(-179.9, 70.95), wrangel);
BOOST_CHECK_EQUAL(within, false);
within = bg::within(Point(179.9, 70.95), wrangel);
BOOST_CHECK_EQUAL(within, false);
// Test using great circle mapper
// http://www.gcmap.com/mapui?P=5E52N-9E53N-7E50N-5E52N,7E52.5N,8E51.5N,6E51N
bg::model::polygon<Point> triangle;
bg::read_wkt("POLYGON((5 52,9 53,7 50,5 52))", triangle);
BOOST_CHECK_EQUAL(bg::within(Point(7, 52.5), triangle, ws), true);
BOOST_CHECK_EQUAL(bg::within(Point(8.0, 51.5), triangle, ws), false);
BOOST_CHECK_EQUAL(bg::within(Point(6.0, 51.0), triangle, ws), false);
// northern hemisphere
{
bg::model::polygon<Point> poly_n;
bg::read_wkt("POLYGON((10 50,30 50,30 40,10 40, 10 50))", poly_n);
Point pt_n1(20, 50.00001);
Point pt_n2(20, 40.00001);
BOOST_CHECK_EQUAL(ss.apply(poly_n.outer()[0], poly_n.outer()[1], pt_n1), -1); // right of segment
BOOST_CHECK_EQUAL(ss.apply(poly_n.outer()[2], poly_n.outer()[3], pt_n2), 1); // left of segment
BOOST_CHECK_EQUAL(bg::within(pt_n1, poly_n, ws), true);
BOOST_CHECK_EQUAL(bg::within(pt_n2, poly_n, ws), false);
}
// southern hemisphere
{
bg::model::polygon<Point> poly_s;
bg::read_wkt("POLYGON((10 -40,30 -40,30 -50,10 -50, 10 -40))", poly_s);
Point pt_s1(20, -40.00001);
Point pt_s2(20, -50.00001);
BOOST_CHECK_EQUAL(ss.apply(poly_s.outer()[0], poly_s.outer()[1], pt_s1), 1); // left of segment
BOOST_CHECK_EQUAL(ss.apply(poly_s.outer()[2], poly_s.outer()[3], pt_s2), -1); // right of segment
BOOST_CHECK_EQUAL(bg::within(pt_s1, poly_s, ws), false);
BOOST_CHECK_EQUAL(bg::within(pt_s2, poly_s, ws), true);
}
// crossing antimeridian, northern hemisphere
{
bg::model::polygon<Point> poly_n;
bg::read_wkt("POLYGON((170 50,-170 50,-170 40,170 40, 170 50))", poly_n);
Point pt_n11(180, 50.00001);
Point pt_n12(-180, 50.00001);
Point pt_n13(179, 50.00001);
Point pt_n14(-179, 50.00001);
Point pt_n21(180, 40.00001);
Point pt_n22(-180, 40.00001);
Point pt_n23(179, 40.00001);
Point pt_n24(-179, 40.00001);
BOOST_CHECK_EQUAL(bg::within(pt_n11, poly_n, ws), true);
BOOST_CHECK_EQUAL(bg::within(pt_n12, poly_n, ws), true);
BOOST_CHECK_EQUAL(bg::within(pt_n13, poly_n, ws), true);
BOOST_CHECK_EQUAL(bg::within(pt_n14, poly_n, ws), true);
BOOST_CHECK_EQUAL(bg::within(pt_n21, poly_n, ws), false);
BOOST_CHECK_EQUAL(bg::within(pt_n22, poly_n, ws), false);
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()
{
typedef bg::model::point<int, 2, bg::cs::cartesian> int_point_type;
typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type;
std::string const polygon_li = "POLYGON((1872000 528000,1872000 192000,1536119 192000,1536000 528000,1200000 528000,1200000 863880,1536000 863880,1872000 863880,1872000 528000))";
bg::model::polygon<int_point_type> int_poly;
bg::model::polygon<double_point_type> double_poly;
bg::read_wkt(polygon_li, int_poly);
bg::read_wkt(polygon_li, double_poly);
std::string const point_li = "POINT(1592000 583950)";
int_point_type int_point;
double_point_type double_point;
bg::read_wkt(point_li, int_point);
bg::read_wkt(point_li, double_point);
bool wi = bg::within(int_point, int_poly);
bool wd = bg::within(double_point, double_poly);
BOOST_CHECK_MESSAGE(wi == wd, "within<a double> different from within<an int>");
}
void test_tickets()
{
typedef boost::geometry::model::d2::point_xy<double> pt;
typedef boost::geometry::model::ring<pt> ring;
// https://svn.boost.org/trac/boost/ticket/9628
{
ring r;
r.push_back(pt(-19155.669324773193,54820.312032458620));
r.push_back(pt(-13826.169324773080,54820.312032458627));
r.push_back(pt(-13826.169324773078,52720.312032458663));
r.push_back(pt(-12755.169324773129,52720.312032458663));
r.push_back(pt(-12755.169324773129,51087.312032458671));
r.push_back(pt(-12760.669324773080,51087.312032458671));
r.push_back(pt(-12760.669324773082,51070.312032458627));
r.push_back(pt(-19155.669324779392,51070.312032458620));
r.push_back(pt(-19155.669324773193,54820.312032458620));
pt p( -12260.669324773118, 54820.312032458634 );
//boost::geometry::correct(r);
bool within = boost::geometry::within(p, r);
BOOST_CHECK_EQUAL(within, false);
}
// similar
{
ring r;
r.push_back(pt(-14155.6,54820.312032458620));
r.push_back(pt(-13826.1,54820.312032458625));
r.push_back(pt(-12155.6,53720.3));
r.push_back(pt(-14155.6,54820.312032458620));
pt p( -13826.0, 54820.312032458634 );
bool within = boost::geometry::within(p, r);
BOOST_CHECK_EQUAL(within, false);
}
// https://svn.boost.org/trac/boost/ticket/10234
{
pt p;
ring r;
bg::read_wkt("POINT(0.1377 5.00)", p);
bg::read_wkt("POLYGON((0.1277 4.97, 0.1277 5.00, 0.1278 4.9999999999999982, 0.1278 4.97, 0.1277 4.97))", r);
bool within = boost::geometry::within(p, r);
BOOST_CHECK_EQUAL(within, false);
bool covered_by = boost::geometry::covered_by(p, r);
BOOST_CHECK_EQUAL(covered_by, false);
}
}
int test_main( int , char* [] )
{
test_large_integers();
test_all<bg::model::d2::point_xy<int> >();
test_all<bg::model::d2::point_xy<double> >();
test_spherical_geographic<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
test_spherical_geographic<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
test_tickets();
return 0;
}

View File

@@ -0,0 +1,269 @@
// Boost.Geometry
// Copyright (c) 2016 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_within.hpp"
#include <algorithms/overlay/overlay_cases.hpp>
#include <algorithms/overlay/multi_overlay_cases.hpp>
#include <boost/geometry/geometries/geometries.hpp>
template <typename P>
void test_polygon_polygon()
{
typedef bg::model::polygon<P> poly;
typedef bg::model::ring<P> ring;
test_geometry<ring, ring>(case_1[0], case_1[1],
false);
test_geometry<ring, poly>(case_1[0], case_1[1],
false);
test_geometry<poly, poly>(case_1[0], case_1[1],
false);
test_geometry<poly, poly>(case_2[0], case_2[1],
false);
test_geometry<poly, poly>(case_3_sph[0], case_3_sph[1],
true);
test_geometry<poly, poly>(case_3_2_sph[0], case_3_2_sph[1],
true);
test_geometry<poly, poly>(case_4[0], case_4[1],
false);
test_geometry<poly, poly>(case_5[0], case_5[1],
false);
test_geometry<poly, poly>(case_6_sph[0], case_6_sph[1],
false);
test_geometry<poly, poly>(case_6_sph[1], case_6_sph[0],
true);
test_geometry<poly, poly>(case_7[0], case_7[1],
false);
test_geometry<poly, poly>(case_8_sph[0], case_8_sph[1],
false);
test_geometry<poly, poly>(case_9_sph[0], case_9_sph[1],
false);
test_geometry<poly, poly>(case_10_sph[0], case_10_sph[1],
false);
test_geometry<poly, poly>(case_11_sph[0], case_11_sph[1],
false);
test_geometry<poly, poly>(case_11_sph[1], case_11_sph[0],
true);
test_geometry<poly, poly>(case_12[0], case_12[1],
false);
test_geometry<poly, poly>(case_13_sph[0], case_13_sph[1],
false);
test_geometry<poly, poly>(case_14_sph[0], case_14_sph[1],
false);
test_geometry<poly, poly>(case_15_sph[0], case_15_sph[1],
false);
test_geometry<poly, poly>(case_16_sph[0], case_16_sph[1],
false);
test_geometry<poly, poly>(case_17_sph[0], case_17_sph[1],
false);
test_geometry<poly, poly>(case_17_sph[1], case_17_sph[0],
true);
test_geometry<poly, poly>(case_18_sph[0], case_18_sph[1],
false);
test_geometry<poly, poly>(case_18_sph[1], case_18_sph[0],
true);
}
template <typename P>
void test_polygon_multi_polygon()
{
typedef bg::model::polygon<P> poly;
typedef bg::model::ring<P> ring;
typedef bg::model::multi_polygon<poly> mpoly;
test_geometry<ring, mpoly>(case_1[0], case_multi_2[0],
false);
test_geometry<poly, mpoly>(case_2[0], case_multi_2[0],
false);
}
template <typename P>
void test_multi_polygon_multi_polygon()
{
typedef bg::model::polygon<P> poly;
typedef bg::model::multi_polygon<poly> mpoly;
test_geometry<mpoly, mpoly>(case_multi_2[0], case_multi_2[1],
false);
}
template <typename P>
void test_linestring_polygon()
{
typedef bg::model::linestring<P> ls;
typedef bg::model::polygon<P> poly;
typedef bg::model::polygon<P> ring;
test_geometry<ls, poly>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
test_geometry<ls, ring>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
test_geometry<ls, poly>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
test_geometry<ls, poly>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true);
test_geometry<ls, poly>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false);
test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)",
"POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
true);
test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)",
"POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))",
true);
test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)",
"POLYGON((0 0,0 10,10 10,10 0,0 0))",
false);
}
template <typename P>
void test_linestring_multi_polygon()
{
typedef bg::model::linestring<P> ls;
typedef bg::model::polygon<P> poly;
typedef bg::model::multi_polygon<poly> mpoly;
test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,10 9)",
"MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)))",
false);
}
template <typename P>
void test_multi_linestring_polygon()
{
typedef bg::model::linestring<P> ls;
typedef bg::model::multi_linestring<ls> mls;
typedef bg::model::polygon<P> poly;
typedef bg::model::ring<P> ring;
test_geometry<mls, poly>("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))",
"POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))",
false);
test_geometry<mls, ring>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))",
"POLYGON((5 5,5 15,15 15,15 5,5 5))",
false);
test_geometry<mls, poly>("MULTILINESTRING((3 10.031432746397092, 1 5, 1 10.013467818052765, 3 4, 7 8, 6 10.035925377760330, 10 2))",
"POLYGON((0 0,0 10,10 10,10 0,0 0))",
true);
}
template <typename P>
void test_multi_linestring_multi_polygon()
{
typedef bg::model::linestring<P> ls;
typedef bg::model::polygon<P> poly;
typedef bg::model::multi_linestring<ls> mls;
typedef bg::model::multi_polygon<poly> mpoly;
test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(2 2,5 5,2 8,2 2))",
"MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2)))",
false);
test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10),(10 10,0 10,0 0),(20 20,50 50,20 80,20 20))",
"MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))",
false);
test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))",
"MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))",
true);
}
template <typename P>
void test_linestring_linestring()
{
typedef bg::model::linestring<P> ls;
test_geometry<ls, ls>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true);
test_geometry<ls, ls>("LINESTRING(1 0,2 2,2 3)", "LINESTRING(0 0, 2 2, 3 2)", false);
}
template <typename P>
void test_linestring_multi_linestring()
{
typedef bg::model::linestring<P> ls;
typedef bg::model::multi_linestring<ls> mls;
test_geometry<ls, mls>("LINESTRING(0 0,10 0)",
"MULTILINESTRING((1 0,2 0),(1 1,2 1))",
false);
test_geometry<ls, mls>("LINESTRING(0 0,5 0,5 5,0 5,0 0)",
"MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5))",
true);
}
template <typename P>
void test_multi_linestring_multi_linestring()
{
typedef bg::model::linestring<P> ls;
typedef bg::model::multi_linestring<ls> mls;
test_geometry<mls, mls>("MULTILINESTRING((0 0,0 0,18 0,18 0,19 0,19 0,19 0,30 0,30 0))",
"MULTILINESTRING((0 10,5 0,20 0,20 0,30 0))",
false);
}
template <typename P>
void test_point_polygon()
{
typedef bg::model::polygon<P> poly;
// https://svn.boost.org/trac/boost/ticket/9162
test_geometry<P, poly>("POINT(0 90)",
"POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
true);
test_geometry<P, poly>("POINT(-120 21)",
"POLYGON((30 0,30 30,90 30, 90 0, 30 0))",
false);
// extended
test_geometry<P, poly>("POINT(0 -90)",
"POLYGON((0 -80,90 -80, -180 -80, -90 -80, 0 -80))",
true);
test_geometry<P, poly>("POINT(0 89)",
"POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
true);
test_geometry<P, poly>("POINT(-180 89)",
"POLYGON((0 80,-90 80, -180 80, 90 80, 0 80))",
true);
}
template <typename P>
void test_all()
{
test_polygon_polygon<P>();
test_polygon_multi_polygon<P>();
test_multi_polygon_multi_polygon<P>();
test_linestring_polygon<P>();
test_linestring_multi_polygon<P>();
test_multi_linestring_polygon<P>();
test_multi_linestring_multi_polygon<P>();
test_linestring_linestring<P>();
test_linestring_multi_linestring<P>();
test_multi_linestring_multi_linestring<P>();
test_point_polygon<P>();
}
int test_main( int , char* [] )
{
test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
return 0;
}

View File

@@ -0,0 +1,137 @@
// Boost.Geometry
// Copyright (c) 2016-2020 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "test_within.hpp"
#include <boost/geometry/geometries/geometries.hpp>
template <typename Point>
void test_point_box_by_side()
{
// Test spherical boxes
// See also http://www.gcmap.com/mapui?P=1E45N-19E45N-19E55N-1E55N-1E45N,10E55.1N,10E45.1N
typedef bg::model::box<Point> box_t;
std::conditional_t
<
std::is_same<typename bg::cs_tag<Point>::type, bg::geographic_tag>::value,
bg::strategy::within::geographic_point_box_by_side<>,
bg::strategy::within::spherical_point_box_by_side<>
> by_side;
box_t box;
bg::read_wkt("POLYGON((1 45,19 55))", box);
BOOST_CHECK_EQUAL(bg::within(Point(10, 55.1), box, by_side), true);
BOOST_CHECK_EQUAL(bg::within(Point(10, 55.2), box, by_side), true);
BOOST_CHECK_EQUAL(bg::within(Point(10, 55.3), box, by_side), true);
BOOST_CHECK_EQUAL(bg::within(Point(10, 55.4), box, by_side), false);
BOOST_CHECK_EQUAL(bg::within(Point(10, 45.1), box, by_side), false);
BOOST_CHECK_EQUAL(bg::within(Point(10, 45.2), box, by_side), false);
BOOST_CHECK_EQUAL(bg::within(Point(10, 45.3), box, by_side), false);
BOOST_CHECK_EQUAL(bg::within(Point(10, 45.4), box, by_side), true);
bg::strategy::within::spherical_point_box s;
BOOST_CHECK_EQUAL(bg::within(Point(10, 44.9), box, s), false);
BOOST_CHECK_EQUAL(bg::within(Point(10, 45.0), box, s), false);
BOOST_CHECK_EQUAL(bg::within(Point(10, 45.1), box, s), true);
BOOST_CHECK_EQUAL(bg::within(Point(10, 49.9), box, s), true);
BOOST_CHECK_EQUAL(bg::within(Point(10, 55.0), box, s), false);
BOOST_CHECK_EQUAL(bg::within(Point(10, 55.1), box, s), false);
// By default Box is not a polygon in spherical CS, edges are defined by small circles
BOOST_CHECK_EQUAL(bg::within(Point(10, 45.1), box), true);
BOOST_CHECK_EQUAL(bg::within(Point(10, 54.9), box), true);
BOOST_CHECK_EQUAL(bg::within(Point(10, 55), box), false);
BOOST_CHECK_EQUAL(bg::within(Point(10, 45), box), false);
// Crossing the dateline (Near Tuvalu)
// http://www.gcmap.com/mapui?P=178E10S-178W10S-178W6S-178E6S-178E10S,180W5.999S,180E9.999S
// http://en.wikipedia.org/wiki/Tuvalu
box_t tuvalu(Point(178, -10), Point(-178, -6));
BOOST_CHECK_EQUAL(bg::within(Point(180, -8), tuvalu, by_side), true);
BOOST_CHECK_EQUAL(bg::within(Point(-180, -8), tuvalu, by_side), true);
BOOST_CHECK_EQUAL(bg::within(Point(180, -5.999), tuvalu, by_side), false);
BOOST_CHECK_EQUAL(bg::within(Point(180, -10.001), tuvalu, by_side), true);
// The above definition of a Box is not valid
// min should be lesser than max
// By default Box is not a polygon in spherical CS, edges are defined by small circles
box_t tuvalu2(Point(178, -10), Point(182, -6));
BOOST_CHECK_EQUAL(bg::within(Point(180, -8), tuvalu2), true);
BOOST_CHECK_EQUAL(bg::within(Point(-180, -8), tuvalu2), true);
BOOST_CHECK_EQUAL(bg::within(Point(180, -6.001), tuvalu2), true);
BOOST_CHECK_EQUAL(bg::within(Point(180, -5.999), tuvalu2), false);
BOOST_CHECK_EQUAL(bg::within(Point(180, -9.999), tuvalu2), true);
BOOST_CHECK_EQUAL(bg::within(Point(180, -10.001), tuvalu2), false);
}
template <typename P>
void test_point_box()
{
typedef bg::model::box<P> box_t;
test_geometry<P, box_t>("POINT(0 0)", "BOX(0 0, 1 1)", false);
test_geometry<P, box_t>("POINT(1 1)", "BOX(0 0, 2 2)", true);
test_geometry<P, box_t>("POINT(180 1)", "BOX(170 0, 190 2)", true);
test_geometry<P, box_t>("POINT(-180 1)", "BOX(170 0, 190 2)", true);
test_geometry<P, box_t>("POINT(180 1)", "BOX(170 0, 180 2)", false);
test_geometry<P, box_t>("POINT(-180 1)", "BOX(170 0, 180 2)", false);
test_geometry<P, box_t>("POINT(179 1)", "BOX(170 0, 190 2)", true);
test_geometry<P, box_t>("POINT(-179 1)", "BOX(170 0, 190 2)", true);
test_geometry<P, box_t>("POINT(179 1)", "BOX(170 0, 180 2)", true);
test_geometry<P, box_t>("POINT(-179 1)", "BOX(170 0, 180 2)", false);
test_geometry<P, box_t>("POINT(169 1)", "BOX(170 0, 180 2)", false);
test_point_box_by_side<P>();
}
template <typename P>
void test_box_box()
{
typedef bg::model::box<P> box_t;
test_geometry<box_t, box_t>("BOX(0 0, 1 1)", "BOX(0 0, 1 1)", true);
test_geometry<box_t, box_t>("BOX(-170 0,-160 1)", "BOX(-180 0, 180 1)", true);
test_geometry<box_t, box_t>("BOX(-170 0,-160 1)", "BOX(170 0, 200 1)", true);
test_geometry<box_t, box_t>("BOX(-170 0,-150 1)", "BOX(170 0, 200 1)", false);
test_geometry<box_t, box_t>("BOX(0 0,1 1)", "BOX(170 0, 370 1)", true);
test_geometry<box_t, box_t>("BOX(0 0,10 1)", "BOX(170 0, 370 1)", true);
test_geometry<box_t, box_t>("BOX(-180 0,10 1)", "BOX(170 0, 370 1)", true);
test_geometry<box_t, box_t>("BOX(-180 0,20 1)", "BOX(170 0, 370 1)", false);
test_geometry<box_t, box_t>("BOX(10 0,20 1)", "BOX(170 0, 370 1)", false);
test_geometry<box_t, box_t>("BOX(160 0,180 1)", "BOX(170 0, 370 1)", false);
test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 190 1)", true); // invalid?
test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 191 1)", true); // invalid?
test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(179 0, 190 1)", true);
test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(181 0, 190 1)", false); // invalid?
test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 189 1)", false); // invalid?
}
template <typename P>
void test_cs()
{
test_point_box<P>();
test_box_box<P>();
}
int test_main( int , char* [] )
{
test_cs<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
test_cs<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
return 0;
}