Merge branch 'develop' of https://github.com/boostorg/geometry into feature/is_simple

This commit is contained in:
Menelaos Karavelas
2014-05-14 16:29:50 +03:00
92 changed files with 8508 additions and 1099 deletions

View File

@@ -31,6 +31,12 @@ test-suite boost-geometry-algorithms
[ run difference_pl_pl.cpp ]
[ run disjoint.cpp ]
[ run distance.cpp : : : <toolset>msvc:<cxxflags>/bigobj ]
[ run distance_areal_areal.cpp ]
[ run distance_linear_areal.cpp ]
[ run distance_linear_linear.cpp ]
[ run distance_pointlike_areal.cpp ]
[ run distance_pointlike_linear.cpp ]
[ run distance_pointlike_pointlike.cpp ]
[ run envelope.cpp ]
[ run equals.cpp ]
[ run expand.cpp ]
@@ -41,6 +47,7 @@ test-suite boost-geometry-algorithms
[ run intersects.cpp : : : <toolset>msvc:<cxxflags>/bigobj ]
[ run length.cpp ]
[ run make.cpp ]
[ run num_points.cpp ]
[ run overlaps.cpp ]
[ run perimeter.cpp ]
[ run point_on_surface.cpp ]

View File

@@ -1,9 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
@@ -13,6 +13,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <string>
#include <sstream>
#include <algorithms/test_distance.hpp>
@@ -29,6 +30,13 @@
#include <test_geometries/custom_segment.hpp>
#include <test_geometries/wrapped_boost_array.hpp>
// includes for multi-geometries
#include <boost/geometry/multi/geometries/multi_point.hpp>
#include <boost/geometry/multi/geometries/multi_linestring.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/geometry/multi/io/wkt/read.hpp>
BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
@@ -196,6 +204,105 @@ void test_distance_array_as_linestring()
}
// code moved from the distance unit test in multi/algorithms -- start
template <typename Geometry1, typename Geometry2>
void test_distance(std::string const& wkt1, std::string const& wkt2, double expected)
{
Geometry1 g1;
Geometry2 g2;
bg::read_wkt(wkt1, g1);
bg::read_wkt(wkt2, g2);
typename bg::default_distance_result<Geometry1, Geometry2>::type d = bg::distance(g1, g2);
BOOST_CHECK_CLOSE(d, expected, 0.0001);
}
template <typename Geometry1, typename Geometry2, typename Strategy>
void test_distance(Strategy const& strategy, std::string const& wkt1,
std::string const& wkt2, double expected)
{
Geometry1 g1;
Geometry2 g2;
bg::read_wkt(wkt1, g1);
bg::read_wkt(wkt2, g2);
typename bg::default_distance_result<Geometry1, Geometry2>::type d = bg::distance(g1, g2, strategy);
BOOST_CHECK_CLOSE(d, expected, 0.0001);
}
template <typename P>
void test_2d()
{
typedef bg::model::multi_point<P> mp;
typedef bg::model::multi_linestring<bg::model::linestring<P> > ml;
test_distance<P, P>("POINT(0 0)", "POINT(1 1)", sqrt(2.0));
test_distance<P, mp>("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
test_distance<mp, P>("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
test_distance<mp, mp>("MULTIPOINT((1 1),(1 0),(0 2))", "MULTIPOINT((2 2),(2 3))", sqrt(2.0));
test_distance<P, ml>("POINT(0 0)", "MULTILINESTRING((1 1,2 2),(1 0,2 0),(0 2,0 3))", 1.0);
test_distance<ml, P>("MULTILINESTRING((1 1,2 2),(1 0,2 0),(0 2,0 3))", "POINT(0 0)", 1.0);
test_distance<ml, mp>("MULTILINESTRING((1 1,2 2),(1 0,2 0),(0 2,0 3))", "MULTIPOINT((0 0),(1 1))", 0.0);
// Test with a strategy
bg::strategy::distance::pythagoras<> pyth;
test_distance<P, P>(pyth, "POINT(0 0)", "POINT(1 1)", sqrt(2.0));
test_distance<P, mp>(pyth, "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
test_distance<mp, P>(pyth, "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
}
template <typename P>
void test_3d()
{
typedef bg::model::multi_point<P> mp;
test_distance<P, P>("POINT(0 0 0)", "POINT(1 1 1)", sqrt(3.0));
test_distance<P, mp>("POINT(0 0 0)", "MULTIPOINT((1 1 1),(1 0 0),(0 1 2))", 1.0);
test_distance<mp, mp>("MULTIPOINT((1 1 1),(1 0 0),(0 0 2))", "MULTIPOINT((2 2 2),(2 3 4))", sqrt(3.0));
}
template <typename P1, typename P2>
void test_mixed()
{
typedef bg::model::multi_point<P1> mp1;
typedef bg::model::multi_point<P2> mp2;
test_distance<P1, P2>("POINT(0 0)", "POINT(1 1)", sqrt(2.0));
test_distance<P1, mp1>("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
test_distance<P1, mp2>("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
test_distance<P2, mp1>("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
test_distance<P2, mp2>("POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
// Test automatic reversal
test_distance<mp1, P1>("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
test_distance<mp1, P2>("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
test_distance<mp2, P1>("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
test_distance<mp2, P2>("MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
// Test multi-multi using different point types for each
test_distance<mp1, mp2>("MULTIPOINT((1 1),(1 0),(0 2))", "MULTIPOINT((2 2),(2 3))", sqrt(2.0));
// Test with a strategy
using namespace bg::strategy::distance;
test_distance<P1, P2>(pythagoras<>(), "POINT(0 0)", "POINT(1 1)", sqrt(2.0));
test_distance<P1, mp1>(pythagoras<>(), "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
test_distance<P1, mp2>(pythagoras<>(), "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
test_distance<P2, mp1>(pythagoras<>(), "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
test_distance<P2, mp2>(pythagoras<>(), "POINT(0 0)", "MULTIPOINT((1 1),(1 0),(0 2))", 1.0);
// Most interesting: reversal AND a strategy (note that the stategy must be reversed automatically
test_distance<mp1, P1>(pythagoras<>(), "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
test_distance<mp1, P2>(pythagoras<>(), "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
test_distance<mp2, P1>(pythagoras<>(), "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
test_distance<mp2, P2>(pythagoras<>(), "MULTIPOINT((1 1),(1 0),(0 2))", "POINT(0 0)", 1.0);
}
// code moved from the distance unit test in multi/algorithms -- end
template <typename P>
@@ -264,10 +371,22 @@ void test_empty_input()
bg::model::linestring<P> line_empty;
bg::model::polygon<P> poly_empty;
bg::model::ring<P> ring_empty;
bg::model::multi_point<P> mp_empty;
bg::model::multi_linestring<bg::model::linestring<P> > ml_empty;
test_empty_input(p, line_empty);
test_empty_input(p, poly_empty);
test_empty_input(p, ring_empty);
test_empty_input(p, mp_empty);
test_empty_input(p, ml_empty);
test_empty_input(mp_empty, mp_empty);
// Test behaviour if one of the inputs is empty
bg::model::multi_point<P> mp;
mp.push_back(p);
test_empty_input(mp_empty, mp);
test_empty_input(mp, mp_empty);
}
void test_large_integers()
@@ -335,5 +454,23 @@ int test_main(int, char* [])
test_empty_input<bg::model::d2::point_xy<int> >();
// below are the test cases moved here from the distance unit test
// in test/multi/algorithms
test_2d<boost::tuple<float, float> >();
test_2d<bg::model::d2::point_xy<float> >();
test_2d<bg::model::d2::point_xy<double> >();
test_3d<boost::tuple<float, float, float> >();
test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
test_mixed<bg::model::d2::point_xy<float>, bg::model::d2::point_xy<double> >();
#ifdef HAVE_TTMATH
test_2d<bg::model::d2::point_xy<ttmath_big> >();
test_mixed<bg::model::d2::point_xy<ttmath_big>, bg::model::d2::point_xy<double> >();
#endif
test_empty_input<bg::model::d2::point_xy<int> >();
return 0;
}

View File

@@ -0,0 +1,20 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_distance_all
#endif
#include "distance_pointlike_pointlike.cpp"
#include "distance_pointlike_linear.cpp"
#include "distance_pointlike_areal.cpp"
#include "distance_linear_linear.cpp"
#include "distance_linear_areal.cpp"
#include "distance_areal_areal.cpp"

View File

@@ -0,0 +1,281 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#include <iostream>
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_distance_areal_areal
#endif
#include <boost/test/included/unit_test.hpp>
#include "test_distance_common.hpp"
typedef bg::model::point<int,2,bg::cs::cartesian> int_point_type;
typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
typedef bg::model::polygon<point_type, false> polygon_type;
typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
typedef bg::model::box<int_point_type> int_box_type;
typedef bg::model::box<point_type> box_type;
namespace services = bg::strategy::distance::services;
typedef bg::default_distance_result<point_type>::type return_type;
typedef bg::strategy::distance::projected_point<> point_segment_strategy;
typedef bg::strategy::distance::pythagoras_box_box<> box_box_strategy;
//===========================================================================
template <typename Strategy>
void test_distance_polygon_polygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "polygon/polygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<polygon_type, polygon_type> tester;
tester::apply("polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
"polygon((-5 20,5 20,5 25,-5 25,-5 20))",
10, 100, strategy);
tester::apply("polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
"polygon((-5 20,-5 5,5 5,5 20,-5 20))",
0, 0, strategy);
tester::apply("polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
"polygon((-5 20,-5 -20,5 -20,5 20,-5 20))",
0, 0, strategy);
tester::apply("polygon((-10 -10,10 -10,10 10,-10 10,-10 -10),\
(-5 -5,-5 5,5 5,5 -5,-5 -5))",
"polygon((-1 -1,0 0,-1 0,-1 -1))",
4, 16, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_polygon_multipolygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "polygon/multipolygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
polygon_type, multi_polygon_type
> tester;
tester::apply("polygon((12 0,14 0,19 0,19.9 -1,12 0))",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0.1, 0.01, strategy, true);
tester::apply("polygon((19 0,19.9 -1,12 0,20.5 0.5,19 0))",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy, true);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipolygon_multipolygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multipolygon/multipolygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
multi_polygon_type, multi_polygon_type
> tester;
tester::apply("multipolygon(((12 0,14 0,14 1,12 0)),\
((18 0,19 0,19.9 -1,18 0)))",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0.1, 0.01, strategy);
tester::apply("multipolygon(((18 0,19 0,19.9 -1,18 0)),\
((12 0,14 0,20.5 0.5,12 0)))",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_box_box(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "box/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<int_box_type, int_box_type> int_tester;
typedef test_distance_of_geometries<box_type, box_type> tester;
int_tester::apply(make_box2d<int_box_type>(5, 5, 10, 10),
make_box2d<int_box_type>(0, 0, 1, 1),
sqrt(32.0), 32, strategy);
tester::apply(make_box2d<box_type>(5, 5, 10, 10),
make_box2d<box_type>(0, 0, 1, 1),
sqrt(32.0), 32, strategy);
tester::apply(make_box2d<box_type>(3, 8, 13, 18),
make_box2d<box_type>(0, 0, 5, 5),
3, 9, strategy);
tester::apply(make_box2d<box_type>(5, 5, 10, 10),
make_box2d<box_type>(0, 0, 5, 5),
0, 0, strategy);
tester::apply(make_box2d<box_type>(5, 5, 10, 10),
make_box2d<box_type>(0, 0, 6, 6),
0, 0, strategy);
tester::apply(make_box2d<box_type>(3, 5, 13, 15),
make_box2d<box_type>(0, 0, 5, 5),
0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_polygon_box(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "polygon/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<polygon_type, box_type> tester;
tester::apply("polygon((10 10,10 5,5 5,5 10,10 10))",
make_box2d<box_type>(0, 0, 1, 1),
sqrt(32.0), 32, strategy);
tester::apply("polygon((10 10,10 5,5 5,5 10,10 10))",
make_box2d<box_type>(0, 0, 5, 5),
0, 0, strategy);
tester::apply("polygon((10 10,10 5,5 5,5 10,10 10))",
make_box2d<box_type>(0, 0, 6, 6),
0, 0, strategy);
tester::apply("polygon((10 10,15 5,10 0,5 5,10 10))",
make_box2d<box_type>(5, 0, 7.5, 2.5),
0, 0, strategy);
tester::apply("polygon((10 10,15 5,10 0,5 5,10 10))",
make_box2d<box_type>(5, 0, 6, 1),
sqrt(4.5), 4.5, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipolygon_box(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multipolygon/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<multi_polygon_type, box_type> tester;
tester::apply("multipolygon(((-10 -10,-10 -9,-9 -9,-9 -10,-10 -10)),\
((2 2,2 3,3 3,3 2,2 2)))",
make_box2d<box_type>(0, 0, 1, 1),
sqrt(2.0), 2, strategy);
tester::apply("multipolygon(((-10 -10,-10 -9,-9 -9,-9 -10,-10 -10)),\
((2 2,2 3,3 3,3 2,2 2)))",
make_box2d<box_type>(0, 0, 2, 2),
0, 0, strategy);
tester::apply("multipolygon(((-10 -10,-10 -9,-9 -9,-9 -10,-10 -10)),\
((2 2,2 3,3 3,3 2,2 2)))",
make_box2d<box_type>(0, 0, 2.5, 2),
0, 0, strategy);
}
//===========================================================================
template <typename Point, typename Strategy>
void test_more_empty_input_areal_areal(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "testing on empty inputs... " << std::flush;
#endif
bg::model::polygon<Point> polygon_empty;
bg::model::multi_polygon<bg::model::polygon<Point> > multipolygon_empty;
bg::model::polygon<Point> polygon =
from_wkt<bg::model::polygon<Point> >("polygon((0 0,1 0,0 1))");
// 1st geometry is empty
test_empty_input(polygon_empty, polygon, strategy);
test_empty_input(multipolygon_empty, polygon, strategy);
// 2nd geometry is empty
test_empty_input(polygon, polygon_empty, strategy);
test_empty_input(polygon, multipolygon_empty, strategy);
// both geometries are empty
test_empty_input(polygon_empty, polygon_empty, strategy);
test_empty_input(polygon_empty, multipolygon_empty, strategy);
test_empty_input(multipolygon_empty, polygon_empty, strategy);
test_empty_input(multipolygon_empty, multipolygon_empty, strategy);
#ifdef GEOMETRY_TEST_DEBUG
std::cout << "done!" << std::endl;
#endif
}
//===========================================================================
BOOST_AUTO_TEST_CASE( test_all_polygon_polygon )
{
test_distance_polygon_polygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_polygon_multipolygon )
{
test_distance_polygon_multipolygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipolygon_multipolygon )
{
test_distance_multipolygon_multipolygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_box_box )
{
test_distance_box_box(box_box_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_polygon_box )
{
test_distance_polygon_box(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipolygon_box )
{
test_distance_multipolygon_box(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_empty_input_areal_areal )
{
test_more_empty_input_areal_areal<point_type>(point_segment_strategy());
}

View File

@@ -0,0 +1,787 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#include <iostream>
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_distance_linear_areal
#endif
#include <boost/test/included/unit_test.hpp>
#include "test_distance_common.hpp"
typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
typedef bg::model::point<int,2,bg::cs::cartesian> int_point_type;
typedef bg::model::segment<point_type> segment_type;
typedef bg::model::segment<int_point_type> int_segment_type;
typedef bg::model::linestring<point_type> linestring_type;
typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
typedef bg::model::polygon<point_type, false> polygon_type;
typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
typedef bg::model::box<point_type> box_type;
typedef bg::model::box<int_point_type> int_box_type;
namespace services = bg::strategy::distance::services;
typedef bg::default_distance_result<point_type>::type return_type;
typedef bg::strategy::distance::pythagoras<> point_point_strategy;
typedef bg::strategy::distance::projected_point<> point_segment_strategy;
//===========================================================================
template <typename Strategy>
void test_distance_segment_polygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "segment/polygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<segment_type, polygon_type> tester;
tester::apply(make_segment<segment_type>(-1, 20, 1, 20),
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
10, 100, strategy);
tester::apply(make_segment<segment_type>(1, 20, 2, 40),
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
10, 100, strategy);
tester::apply(make_segment<segment_type>(-1, 20, -1, 5),
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
0, 0, strategy);
tester::apply(make_segment<segment_type>(-1, 20, -1, -20),
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_linestring_polygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "linestring/polygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<linestring_type, polygon_type> tester;
tester::apply("linestring(-1 20,1 20,1 30)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
10, 100, strategy, true);
tester::apply("linestring(-1 20,1 20,1 5)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
0, 0, strategy, true);
tester::apply("linestring(-1 20,1 20,1 -20)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
0, 0, strategy, true);
}
//===========================================================================
template <typename Strategy>
void test_distance_multilinestring_polygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multilinestring/polygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
multi_linestring_type, polygon_type
> tester;
tester::apply("multilinestring((-100 -100,-90 -90),(-1 20,1 20,1 30))",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
10, 100, strategy, true);
tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 5))",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
0, 0, strategy, true);
tester::apply("multilinestring((-1 20,1 20,1 30),(-1 20,1 20,1 -20))",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
0, 0, strategy, true);
}
//===========================================================================
template <typename Strategy>
void test_distance_segment_multipolygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "segment/multipolygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
segment_type, multi_polygon_type
> tester;
tester::apply(make_segment<segment_type>(-1, 20, 1, 20),
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((0 22,-1 30, 2 40,0 22)))",
2, 4, strategy);
tester::apply(make_segment<segment_type>(12, 0, 14, 0),
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
2, 4, strategy);
tester::apply(make_segment<segment_type>(12, 0, 20.5, 0.5),
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy);
tester::apply(make_segment<segment_type>(12, 0, 50, 0),
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_linestring_multipolygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "linestring/multipolygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
linestring_type, multi_polygon_type
> tester;
tester::apply("linestring(-1 20,1 20)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((0 22,-1 30, 2 40,0 22)))",
2, 4, strategy, true);
tester::apply("linestring(12 0,14 0)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
2, 4, strategy, true);
tester::apply("linestring(12 0,20.5 0.5)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy, true);
tester::apply("linestring(12 0,50 0)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy, true);
}
//===========================================================================
template <typename Strategy>
void test_distance_multilinestring_multipolygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multilinestring/multipolygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
multi_linestring_type, multi_polygon_type
> tester;
tester::apply("multilinestring((12 0,14 0),(19 0,19.9 -1))",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10)))",
0.1, 0.01, strategy, true);
tester::apply("multilinestring((19 0,19.9 -1),(12 0,20.5 0.5))",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy, true);
}
//===========================================================================
template <typename Strategy>
void test_distance_segment_box(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "2D segment/box distance tests" << std::endl;
#endif
typedef int_box_type B;
typedef segment_type S;
typedef int_segment_type IS;
typedef test_distance_of_geometries<B, S> tester;
typedef test_distance_of_geometries<B, IS> itester;
// segments that intersect the box
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 0.5, 0.5, 0.75),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 0.5, 1.5, 0.75),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, -1, 0.5, 2),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 1, 1.5, 0.75),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(2, 0, 0, 2),
0, 0, strategy);
// segment that has closest point on box boundary
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(4, 0.5, 5, 0.75),
3, 9, strategy);
// segment that has closest point on box corner
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(4, 0, 0, 4),
sqrt(2), 2, strategy);
itester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<IS>(-4, 0, 0, -4),
sqrt(8), 8, strategy);
itester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<IS>(-8, 4, 4, -8),
sqrt(8), 8, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-4, 0, 0, 4),
1.5 * sqrt(2), 4.5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-4, 0, 1, 5),
1.5 * sqrt(2), 4.5, strategy);
itester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<IS>(0, -2, 3, 1),
0.5 * sqrt(2), 0.5, strategy);
itester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<IS>(0, -2, 2, 2),
0, 0, strategy);
// horizontal segments
itester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<IS>(-2, -1, -1, -1),
sqrt(2), 2, strategy);
itester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<IS>(-1, -1, 0, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-0.5, -1, 0.5, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, -1, 0.75, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, -1, 1.25, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, -1, 2, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(2, -1, 3, -1),
sqrt(2), 2, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -1, 2, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 0, -1, 0),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 0, 0, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-0.5, 0, 0.5, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 0, 0.75, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 0, 1.25, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 0, 2, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(2, 0, 3, 0),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 0, 2, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 0.5, -1, 0.5),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 0.5, 0, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-0.5, 0.5, 0.5, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 0.5, 0.75, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 0.5, 1.25, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 0.5, 2, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(2, 0.5, 3, 0.5),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 0.5, 2, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 1, -1, 1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 1, 0, 1),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-0.5, 1, 0.5, 1),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 1, 0.75, 1),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 1, 1.25, 1),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 1, 2, 1),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(2, 1, 3, 1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 1, 2, 1),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 3, -1, 3),
sqrt(5), 5, strategy);
itester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<IS>(-1, 3, 0, 3),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-0.5, 3, 0.5, 3),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 3, 0.75, 3),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 3, 1.25, 3),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 3, 2, 3),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(2, 3, 3, 3),
sqrt(5), 5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 3, 2, 3),
2, 4, strategy);
// vertical segments
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, -2, -1, -1),
sqrt(2), 2, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, -1, -1, 0),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, -0.5, -1, 0.5),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 0.5, -1, 0.75),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 0.5, -1, 1.25),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 1, -1, 2),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 2, -1, 3),
sqrt(2), 2, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, -2, -1, 2),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, -2, 0, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, -1, 0, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, -0.5, 0, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, 0.5, 0, 0.75),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, 0.5, 0, 1.25),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, 1, 0, 2),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, 2, 0, 3),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, -2, 0, 2),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, -2, 0.5, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, -1, 0.5, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, -0.5, 0.5, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 0.5, 0.5, 0.75),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 0.5, 0.5, 1.25),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 1, 0.5, 2),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 2, 0.5, 3),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, -2, 0.5, 2),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, -2, 1, -1),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, -1, 1, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, -0.5, 1, 0.5),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 0.5, 1, 0.75),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 0.5, 1, 1.25),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 1, 1, 2),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 2, 1, 3),
1, 1, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, -2, 1, 2),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, -2, 3, -1),
sqrt(5), 5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, -1, 3, 0),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, -0.5, 3, 0.5),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, 0.5, 3, 0.75),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, 0.5, 3, 1.25),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, 1, 3, 2),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, 2, 3, 3),
sqrt(5), 5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, -2, 3, 2),
2, 4, strategy);
// positive slope
itester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<IS>(-2, -2, -1, -1),
sqrt(2), 2, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 0, -0.5),
0.5, 0.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 0.5, -0.5),
0.5, 0.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 1, -0.5),
0.5, 0.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 2, 0),
sqrt(0.2), 0.2, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 4, 1),
sqrt(0.2), 0.2, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, -1.5, 0),
1.5, 2.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, -1.5, 0.5),
1.5, 2.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, -1.5, 1),
1.5, 2.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 0, 2),
sqrt(0.2), 0.2, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 1, 4),
sqrt(0.2), 0.2, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 4, 2),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 2, 4),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 4, 3),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 3, 4),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, 3, 3),
0, 0, strategy);
// negative slope
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, -2, -1, -3),
sqrt(8), 8, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-3, -1, 0, -4),
sqrt(8), 8, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 0.75, -1.5, 0.5),
1.5, 2.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 1.5, -1.5, 0.5),
1.5, 2.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 2, 0.75, 1.5),
0.5, 0.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 2, 0.75, 1.5),
0.5, 0.25, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, 2, 2, 0),
0, 0, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0, 3, 3, 0),
sqrt(0.5), 0.5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 4, 4, -1),
sqrt(0.5), 0.5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, 4, 0, 3),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-2, 5, -1, 4),
sqrt(10), 10, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(3, -1, 4, -4),
sqrt(5), 5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(1, 2, 2, 1),
sqrt(0.5), 0.5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, -2, 2, -3),
2, 4, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, -2, 0, -3),
sqrt(5), 5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, -2, 0.5, -3.5),
sqrt(5), 5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(-1, -2, 0.5, -3.5),
sqrt(5), 5, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 3, 2.5, 2),
sqrt(2.45), 2.45, strategy);
tester::apply(make_box2d<B>(0, 0, 1, 1),
make_segment<S>(0.5, 1.5, 1.5, -1.5),
0, 0, strategy);
// test degenerate segment
tester::apply(make_box2d<B>(0, 0, 2, 2),
make_segment<S>(4, 1, 4, 1),
2, 4, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_linestring_box(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "linestring/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<linestring_type, box_type> tester;
// linestrings that intersect the box
tester::apply("linestring(-1 0.5,0.5 0.75)",
make_box2d<box_type>(0, 0, 1, 1),
0, 0, strategy);
tester::apply("linestring(-1 0.5,1.5 0.75)",
make_box2d<box_type>(0, 0, 1, 1),
0, 0, strategy);
// linestring that has closest point on box boundary
tester::apply("linestring(4 0.5,5 0.75)",
make_box2d<box_type>(0, 0, 1, 1),
3, 9, strategy);
// linestring that has closest point on box corner
tester::apply("linestring(4 0,0 4)",
make_box2d<box_type>(0, 0, 1, 1),
sqrt(2), 2, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multilinestring_box(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multilinestring/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<multi_linestring_type, box_type> tester;
// multilinestring that intersects the box
tester::apply("multilinestring((-1 0.5,0.5 0.75),(4 0.5,5 0.75))",
make_box2d<box_type>(0, 0, 1, 1),
0, 0, strategy);
// multilinestring that has closest point on box boundary
tester::apply("multilinestring((4 0.5,5 0.75))",
make_box2d<box_type>(0, 0, 1, 1),
3, 9, strategy);
// multilinestring that has closest point on box corner
tester::apply("multilinestring((5 0,0 5),(4 0,0 4))",
make_box2d<box_type>(0, 0, 1, 1),
sqrt(2), 2, strategy);
}
//===========================================================================
template <typename Point, typename Strategy>
void test_more_empty_input_linear_areal(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "testing on empty inputs... " << std::flush;
#endif
bg::model::linestring<Point> line_empty;
bg::model::polygon<Point> polygon_empty;
bg::model::multi_linestring<bg::model::linestring<Point> > multiline_empty;
bg::model::multi_polygon<bg::model::polygon<Point> > multipolygon_empty;
bg::model::linestring<Point> line =
from_wkt<bg::model::linestring<Point> >("linestring(0 0,1 1)");
bg::model::polygon<Point> polygon =
from_wkt<bg::model::polygon<Point> >("polygon((0 0,1 0,0 1))");
// 1st geometry is empty
test_empty_input(line_empty, polygon, strategy);
test_empty_input(multiline_empty, polygon, strategy);
// 2nd geometry is empty
test_empty_input(line, polygon_empty, strategy);
test_empty_input(line, multipolygon_empty, strategy);
// both geometries are empty
test_empty_input(line_empty, polygon_empty, strategy);
test_empty_input(line_empty, multipolygon_empty, strategy);
test_empty_input(multiline_empty, polygon_empty, strategy);
test_empty_input(multiline_empty, multipolygon_empty, strategy);
#ifdef GEOMETRY_TEST_DEBUG
std::cout << "done!" << std::endl;
#endif
}
//===========================================================================
BOOST_AUTO_TEST_CASE( test_all_segment_polygon )
{
test_distance_segment_polygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_linestring_polygon )
{
test_distance_linestring_polygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multilinestring_polygon )
{
test_distance_multilinestring_polygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_segment_multipolygon )
{
test_distance_segment_multipolygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_linestring_multipolygon )
{
test_distance_linestring_multipolygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multilinestring_multipolygon )
{
test_distance_multilinestring_multipolygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_segment_box )
{
test_distance_segment_box(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_linestring_box )
{
test_distance_linestring_box(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multilinestring_box )
{
test_distance_multilinestring_box(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_empty_input_linear_areal )
{
test_more_empty_input_linear_areal<point_type>(point_segment_strategy());
}

View File

@@ -0,0 +1,280 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#include <iostream>
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_distance_linear_linear
#endif
#include <boost/test/included/unit_test.hpp>
#include "test_distance_common.hpp"
typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
typedef bg::model::segment<point_type> segment_type;
typedef bg::model::linestring<point_type> linestring_type;
typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
namespace services = bg::strategy::distance::services;
typedef bg::default_distance_result<point_type>::type return_type;
typedef bg::strategy::distance::projected_point<> point_segment_strategy;
//===========================================================================
template <typename Strategy>
void test_distance_segment_segment(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "segment/segment distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<segment_type, segment_type> tester;
tester::apply(make_segment<segment_type>(0, 0, 10, 0),
make_segment<segment_type>(4, 2, 4, 0.5),
return_type(0.5), return_type(0.25), strategy);
tester::apply(make_segment<segment_type>(0, 0, 10, 0),
make_segment<segment_type>(4, 2, 4, -0.5),
return_type(0), return_type(0), strategy);
tester::apply(make_segment<segment_type>(0, 0, 10, 0),
make_segment<segment_type>(4, 2, 0, 0),
return_type(0), return_type(0), strategy);
tester::apply(make_segment<segment_type>(0, 0, 10, 0),
make_segment<segment_type>(-2, 3, 1, 2),
return_type(2), return_type(4), strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_segment_linestring(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "segment/linestring distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<segment_type, linestring_type> tester;
tester::apply(make_segment<segment_type>(-1, -1, -2, -2),
"linestring(2 1,1 2,4 0)",
sqrt(12.5), 12.5, strategy);
tester::apply(make_segment<segment_type>(1, 1, 2, 2),
"linestring(2 1,1 2,4 0)",
0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_linestring_linestring(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "linestring/linestring distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
linestring_type, linestring_type
> tester;
// It is not obvious that linestrings with only one point are valid
tester::apply("linestring(1 1)", "linestring(2 1)",
1, 1, strategy);
tester::apply("linestring(1 1,3 1)", "linestring(2 1)",
0, 0, strategy);
tester::apply("linestring(1 1)", "linestring(0 0,-2 0,2 -2,2 0)",
sqrt(2.0), 2, strategy);
tester::apply("linestring(1 1,1 1)", "linestring(2 1,2 1)",
1, 1, strategy);
tester::apply("linestring(1 1,1 1,1 1)", "linestring(2 1,2 1,2 1,2 1)",
1, 1, strategy);
tester::apply("linestring(1 1,3 1)", "linestring(2 1,2 1)",
0, 0, strategy);
tester::apply("linestring(1 1,1 1)", "linestring(0 0,-2 0,2 -2,2 0)",
sqrt(2.0), 2, strategy);
tester::apply("linestring(1 1,3 1)", "linestring(2 1, 4 1)",
0, 0, strategy);
tester::apply("linestring(1 1,2 2,3 3)", "linestring(2 1,1 2,4 0)",
0, 0, strategy);
tester::apply("linestring(1 1,2 2,3 3)", "linestring(1 0,2 -1,4 0)",
1, 1, strategy);
tester::apply("linestring(1 1,2 2,3 3)",
"linestring(1 -10,2 0,2.1 -10,4 0)",
sqrt(2.0), 2, strategy);
tester::apply("linestring(1 1,2 2,3 3)",
"linestring(1 -10,2 1.9,2.1 -10,4 0)",
sqrt(0.005), 0.005, strategy);
tester::apply("linestring(1 1,1 2)", "linestring(0 0,-2 0,2 -2,2 0)",
sqrt(2.0), 2, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_segment_multilinestring(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "segment/multilinestring distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
segment_type, multi_linestring_type
> tester;
tester::apply(make_segment<segment_type>(-1, -1, -2, -2),
"multilinestring((2 1,1 2),(4 0,4 10))",
sqrt(12.5), 12.5, strategy);
tester::apply(make_segment<segment_type>(1, 1, 2, 2),
"multilinestring((2 1,1 2),(4 0,4 10))",
0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_linestring_multilinestring(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "linestring/multilinestring distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
linestring_type, multi_linestring_type
> tester;
tester::apply("linestring(1 1,2 2,3 3)",
"multilinestring((2 1,1 2,4 0),(1 -10,2 1.9,2.1 -10,4 0))",
0, 0, strategy, true);
tester::apply("linestring(1 1,2 2,3 3)",
"multilinestring((1 -10,2 0,2.1 -10,4 0),(1 -10,2 1.9,2.1 -10,4 0))",
sqrt(0.005), 0.005, strategy, true);
}
//===========================================================================
template <typename Strategy>
void test_distance_multilinestring_multilinestring(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multilinestring/multilinestring distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
multi_linestring_type, multi_linestring_type
> tester;
tester::apply("multilinestring((0 0,0 1,1 1),(10 0,11 1,12 2))",
"multilinestring((0.5 0.5,0.75 0.75),(11 0,11 7))",
0, 0, strategy);
tester::apply("multilinestring((0 0,0 1,1 1),(10 0,11 1,12 2))",
"multilinestring((0.5 0.5,0.75 0.75),(11 0,11 0.9))",
sqrt(0.005), 0.005, strategy);
tester::apply("multilinestring((0 0,0 1,1 1),(10 0,11 1,12 2))",
"multilinestring((0.5 0.5,0.75 0.75),(11.1 0,11.1 0.9))",
sqrt(0.02), 0.02, strategy);
}
//===========================================================================
template <typename Point, typename Strategy>
void test_more_empty_input_linear_linear(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "testing on empty inputs... " << std::flush;
#endif
bg::model::linestring<Point> line_empty;
bg::model::multi_linestring<bg::model::linestring<Point> > multiline_empty;
bg::model::linestring<Point> line =
from_wkt<bg::model::linestring<Point> >("linestring(0 0,1 1)");
// 1st geometry is empty
test_empty_input(line_empty, line, strategy);
test_empty_input(multiline_empty, line, strategy);
// 2nd geometry is empty
test_empty_input(line, line_empty, strategy);
test_empty_input(line, multiline_empty, strategy);
// both geometries are empty
test_empty_input(line_empty, line_empty, strategy);
test_empty_input(line_empty, multiline_empty, strategy);
test_empty_input(multiline_empty, multiline_empty, strategy);
#ifdef GEOMETRY_TEST_DEBUG
std::cout << "done!" << std::endl;
#endif
}
//===========================================================================
BOOST_AUTO_TEST_CASE( test_all_segment_segment )
{
test_distance_segment_segment(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_segment_linestring )
{
test_distance_segment_linestring(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_linestring_linestring )
{
test_distance_linestring_linestring(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_segment_multilinestring )
{
test_distance_segment_multilinestring(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_linestring_multilinestring )
{
test_distance_linestring_multilinestring(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multilinestring_multilinestring )
{
test_distance_multilinestring_multilinestring(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_empty_input_linear_linear )
{
test_more_empty_input_linear_linear<point_type>(point_segment_strategy());
}

View File

@@ -0,0 +1,575 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#include <iostream>
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_distance_pointlike_areal
#endif
#include <boost/test/included/unit_test.hpp>
#include "test_distance_common.hpp"
typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
typedef bg::model::multi_point<point_type> multi_point_type;
typedef bg::model::point<double,3,bg::cs::cartesian> point_type_3d;
typedef bg::model::multi_point<point_type_3d> multi_point_type_3d;
typedef bg::model::polygon<point_type, false> polygon_type;
typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
typedef bg::model::box<point_type> box_type;
typedef bg::model::box<point_type_3d> box_type_3d;
namespace services = bg::strategy::distance::services;
typedef bg::default_distance_result<point_type>::type return_type;
typedef bg::strategy::distance::pythagoras<> point_point_strategy;
typedef bg::strategy::distance::projected_point<> point_segment_strategy;
typedef bg::strategy::distance::pythagoras_point_box<> point_box_strategy;
//===========================================================================
template <typename Strategy>
void test_distance_point_polygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "point/polygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<point_type, polygon_type> tester;
tester::apply("point(0 -20)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
10, 100, strategy);
tester::apply("point(12 0)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
2, 4, strategy);
tester::apply("point(0 0)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
0, 0, strategy);
tester::apply("point(0 0)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10),\
(-5 -5,-5 5,5 5,5 -5,-5 -5))",
5, 25, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_point_multipolygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "point/multipolygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<point_type, multi_polygon_type> tester;
tester::apply("point(0 -20)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((0 22,-1 30,2 40,0 22)))",
10, 100, strategy);
tester::apply("point(12 0)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
2, 4, strategy);
tester::apply("point(0 0)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy);
tester::apply("point(0 0)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10),\
(-5 -5,-5 5,5 5,5 -5,-5 -5)),\
((100 0,101 0,101 1,100 1,100 0)))",
5, 25, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipoint_polygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multipoint/polygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<multi_point_type, polygon_type> tester;
tester::apply("multipoint(0 -20,0 -15)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
5, 25, strategy);
tester::apply("multipoint(16 0,12 0)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
2, 4, strategy);
tester::apply("multipoint(0 0,5 5,4 4)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
0, 0, strategy);
tester::apply("multipoint(0 0,2 0)",
"polygon((-10 -10,10 -10,10 10,-10 10,-10 -10),\
(-5 -5,-5 5,5 5,5 -5,-5 -5))",
3, 9, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipoint_multipolygon(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multipoint/multipolygon distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
multi_point_type, multi_polygon_type
> tester;
tester::apply("multipoint(0 -20,0 -15)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((0 22,-1 30,2 40,0 22)))",
5, 25, strategy);
tester::apply("multipoint(16 0,12 0)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
2, 4, strategy);
tester::apply("multipoint(0 0,4 4,5 5)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
((20 -1,21 2,30 -10,20 -1)))",
0, 0, strategy);
tester::apply("multipoint(0 0,2 0)",
"multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10),\
(-5 -5,-5 5,5 5,5 -5,-5 -5)),\
((100 0,101 0,101 1,100 1,100 0)))",
3, 9, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_point_box_2d(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "2D point/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<box_type, point_type> tester;
// point inside box
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(0 0)", 0, 0, strategy);
// points on box corners
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(-1 -1)", 0, 0, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(-1 1)", 0, 0, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(1 -1)", 0, 0, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(1 1)", 0, 0, strategy);
// points on box boundary edges
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(0 -1)", 0, 0, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(-1 0)", 0, 0, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(1 0)", 0, 0, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(0 1)", 0, 0, strategy);
// points outside box
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(0 4)", 3, 9, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(0.5 4)", 3, 9, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(-0.5 5)", 4, 16, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(3 0.25)", 2, 4, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(-3 -0.25)", 2, 4, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(3 5)", sqrt(20), 20, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(-5 -4)", 5, 25, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(2 -2)", sqrt(2), 2, strategy);
tester::apply(make_box2d<box_type>(-1, -1, 1, 1),
"point(-3 4)", sqrt(13), 13, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_point_box_different_point_types(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "2D point/box distance tests with different points"
<< std::endl;
#endif
typedef point_type double_point;
typedef box_type double_box;
typedef bg::model::point<int,2,bg::cs::cartesian> int_point;
typedef bg::model::box<int_point> int_box;
test_distance_of_geometries
<
int_point, int_box
>::apply("point(0 0)",
make_box2d<int_box>(1, 1, 2, 2),
sqrt(2), 2, strategy);
test_distance_of_geometries
<
double_point, int_box
>::apply("point(0.5 0)",
make_box2d<int_box>(1, -1, 2, 1),
0.5, 0.25, strategy);
test_distance_of_geometries
<
double_point, double_box
>::apply("point(1.5 0)",
make_box2d<double_box>(1, -1, 2, 1),
0, 0, strategy);
test_distance_of_geometries
<
double_point, int_box
>::apply("point(1.5 0)",
make_box2d<int_box>(1, -1, 2, 1),
0, 0, strategy);
test_distance_of_geometries
<
int_point, double_box
>::apply("point(1 0)",
make_box2d<double_box>(0.5, -1, 1.5, 1),
0, 0, strategy);
test_distance_of_geometries
<
int_point, double_box
>::apply("point(0 0)",
make_box2d<double_box>(0.5, -1, 1.5, 1),
0.5, 0.25, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_point_box_3d(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "3D point/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<box_type_3d, point_type_3d> tester;
// point inside box
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 0 0)", 0, 0, strategy);
// points on box corners
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 -1 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 -1 1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 1 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 1 1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 -1 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 -1 1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 1 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 1 1)", 0, 0, strategy);
// points on box boundary edges
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 -1 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 -1 1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 1 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 1 1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 0 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 0 1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 0 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 0 1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 -1 0)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 1 0)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 -1 0)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 1 0)", 0, 0, strategy);
// point on box faces
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 0 -1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 0 1)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 -1 0)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 1 0)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-1 0 0)", 0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(1 0 0)", 0, 0, strategy);
// points outside box -- closer to box corners
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-2 -3 -4)", sqrt(14), 14, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-2 -3 3)", 3, 9, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-2 5 -2)", sqrt(18), 18, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-2 5 3)", sqrt(21), 21, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(4 -6 -3)", sqrt(38), 38, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(4 -6 4)", sqrt(43), 43, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(4 7 -2)", sqrt(46), 46, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(4 7 8)", sqrt(94), 94, strategy);
// points closer to box facets
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 0 10)", 9, 81, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 0 -5)", 4, 16, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 7 0)", 6, 36, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 -6 0)", 5, 25, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(4 0 0)", 3, 9, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-3 0 0)", 2, 4, strategy);
// points closer to box edges
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 -4 -5)", 5, 25, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 -3 6)", sqrt(29), 29, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 2 -7)", sqrt(37), 37, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(0 8 7)", sqrt(85), 85, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-4 0 -4)", sqrt(18), 18, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-3 0 5)", sqrt(20), 20, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(2 0 -6)", sqrt(26), 26, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(8 0 6)", sqrt(74), 74, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-5 -5 0)", sqrt(32), 32, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(-4 6 0)", sqrt(34), 34, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(3 -7 0)", sqrt(40), 40, strategy);
tester::apply(make_box3d<box_type_3d>(-1, -1, -1, 1, 1, 1),
"point(9 7 0)", 10, 100, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipoint_box_2d(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "2D multipoint/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<box_type, multi_point_type> tester;
// at least one point inside the box
tester::apply(make_box2d<box_type>(0, 0, 10, 10),
"multipoint(0 0,-1 -1,20 20)",
0, 0, strategy);
tester::apply(make_box2d<box_type>(0, 0, 10, 10),
"multipoint(1 1,-1 -1,20 20)",
0, 0, strategy);
tester::apply(make_box2d<box_type>(0, 0, 10, 10),
"multipoint(1 1,2 2,3 3)",
0, 0, strategy);
// all points outside the box
tester::apply(make_box2d<box_type>(0, 0, 10, 10),
"multipoint(-1 -1,20 20)",
sqrt(2), 2, strategy);
tester::apply(make_box2d<box_type>(0, 0, 10, 10),
"multipoint(5 13, 50 50)",
3, 9, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipoint_box_3d(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "3D multipoint/box distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
box_type_3d, multi_point_type_3d
> tester;
// at least one point inside the box
tester::apply(make_box3d<box_type_3d>(0, 0, 0, 10, 10, 10),
"multipoint(0 0 0,-1 -1 -1,20 20 20)",
0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(0, 0, 0, 10, 10, 10),
"multipoint(1 1 1,-1 -1 -1,20 20 20)",
0, 0, strategy);
tester::apply(make_box3d<box_type_3d>(0, 0, 0, 10, 10, 10),
"multipoint(1 1 1,2 2 2,3 3 3)",
0, 0, strategy);
// all points outside the box
tester::apply(make_box3d<box_type_3d>(0, 0, 0, 10, 10, 10),
"multipoint(-1 -1 -1,20 20 20)",
sqrt(3), 3, strategy);
tester::apply(make_box3d<box_type_3d>(0, 0, 0, 10, 10, 10),
"multipoint(5 5 13,50 50 50)",
3, 9, strategy);
}
//===========================================================================
template <typename Point, typename Strategy>
void test_more_empty_input_pointlike_areal(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "testing on empty inputs... " << std::flush;
#endif
bg::model::multi_point<Point> multipoint_empty;
bg::model::polygon<Point> polygon_empty;
bg::model::multi_polygon<bg::model::polygon<Point> > multipolygon_empty;
Point point = from_wkt<Point>("point(0 0)");
bg::model::polygon<Point> polygon =
from_wkt<bg::model::polygon<Point> >("polygon((0 0,1 0,0 1))");
// 1st geometry is empty
test_empty_input(multipoint_empty, polygon, strategy);
// 2nd geometry is empty
test_empty_input(point, polygon_empty, strategy);
test_empty_input(point, multipolygon_empty, strategy);
// both geometries are empty
test_empty_input(multipoint_empty, polygon_empty, strategy);
test_empty_input(multipoint_empty, multipolygon_empty, strategy);
#ifdef GEOMETRY_TEST_DEBUG
std::cout << "done!" << std::endl;
#endif
}
//===========================================================================
BOOST_AUTO_TEST_CASE( test_all_point_polygon )
{
test_distance_point_polygon(point_point_strategy()); // back-compatibility
test_distance_point_polygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_point_multipolygon )
{
test_distance_point_multipolygon(point_point_strategy()); // back-compatibility
test_distance_point_multipolygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipoint_polygon )
{
test_distance_multipoint_polygon(point_point_strategy()); // back-compatibility
test_distance_multipoint_polygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipoint_multipolygon )
{
test_distance_multipoint_multipolygon(point_point_strategy()); // back-compatibility
test_distance_multipoint_multipolygon(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_point_box_2d )
{
point_box_strategy pb_strategy;
test_distance_point_box_2d(pb_strategy);
test_distance_point_box_different_point_types(pb_strategy);
}
BOOST_AUTO_TEST_CASE( test_all_point_box_3d )
{
test_distance_point_box_3d(point_box_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipoint_box_2d )
{
test_distance_multipoint_box_2d(point_box_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipoint_box_3d )
{
test_distance_multipoint_box_3d(point_box_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_areal )
{
test_more_empty_input_pointlike_areal
<
point_type
>(point_segment_strategy());
}

View File

@@ -0,0 +1,264 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#include <iostream>
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_distance_pointlike_linear
#endif
#include <boost/test/included/unit_test.hpp>
#include "test_distance_common.hpp"
typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
typedef bg::model::multi_point<point_type> multi_point_type;
typedef bg::model::segment<point_type> segment_type;
typedef bg::model::linestring<point_type> linestring_type;
typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
namespace services = bg::strategy::distance::services;
typedef bg::default_distance_result<point_type>::type return_type;
typedef bg::strategy::distance::pythagoras<> point_point_strategy;
typedef bg::strategy::distance::projected_point<> point_segment_strategy;
//===========================================================================
template <typename Strategy>
void test_distance_point_segment(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "point/segment distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<point_type, segment_type> tester;
tester::apply("point(0 0)", "segment(2 0,3 0)", 2, 4, strategy);
tester::apply("point(2.5 3)", "segment(2 0,3 0)", 3, 9, strategy);
tester::apply("point(2 0)", "segment(2 0,3 0)", 0, 0, strategy);
tester::apply("point(3 0)", "segment(2 0,3 0)", 0, 0, strategy);
tester::apply("point(2.5 0)", "segment(2 0,3 0)", 0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_point_linestring(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "point/linestring distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<point_type, linestring_type> tester;
tester::apply("point(0 0)", "linestring(2 0)", 2, 4, strategy);
tester::apply("point(0 0)", "linestring(2 0,3 0)", 2, 4, strategy);
tester::apply("point(2.5 3)", "linestring(2 0,3 0)", 3, 9, strategy);
tester::apply("point(2 0)", "linestring(2 0,3 0)", 0, 0, strategy);
tester::apply("point(3 0)", "linestring(2 0,3 0)", 0, 0, strategy);
tester::apply("point(2.5 0)", "linestring(2 0,3 0)", 0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_point_multilinestring(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "point/multilinestring distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
point_type, multi_linestring_type
> tester;
tester::apply("point(0 0)",
"multilinestring((-5 0,-3 0),(2 0,3 0))",
2, 4, strategy);
tester::apply("point(2.5 3)",
"multilinestring((-5 0,-3 0),(2 0,3 0))",
3, 9, strategy);
tester::apply("point(2 0)",
"multilinestring((-5 0,-3 0),(2 0,3 0))",
0, 0, strategy);
tester::apply("point(3 0)",
"multilinestring((-5 0,-3 0),(2 0,3 0))",
0, 0, strategy);
tester::apply("point(2.5 0)",
"multilinestring((-5 0,-3 0),(2 0,3 0))",
0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_linestring_multipoint(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "linestring/multipoint distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
linestring_type, multi_point_type
> tester;
tester::apply("linestring(2 0,0 2,100 100)",
"multipoint(0 0,1 0,0 1,1 1)",
0, 0, strategy);
tester::apply("linestring(4 0,0 4,100 100)",
"multipoint(0 0,1 0,0 1,1 1)",
sqrt(2.0), 2, strategy);
tester::apply("linestring(1 1,2 2,100 100)",
"multipoint(0 0,1 0,0 1,1 1)",
0, 0, strategy);
tester::apply("linestring(3 3,4 4,100 100)",
"multipoint(0 0,1 0,0 1,1 1)",
sqrt(8.0), 8, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipoint_multilinestring(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multipoint/multilinestring distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
multi_point_type, multi_linestring_type
> tester;
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
"multilinestring((2 0,0 2),(2 2,3 3))",
0, 0, strategy);
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
"multilinestring((3 0,0 3),(4 4,5 5))",
0.5 * sqrt(2.0), 0.5, strategy);
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
"multilinestring((4 4,5 5),(1 1,2 2))",
0, 0, strategy);
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
"multilinestring((3 3,4 4),(4 4,5 5))",
sqrt(8.0), 8, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipoint_segment(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multipoint/segment distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<multi_point_type, segment_type> tester;
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
make_segment<segment_type>(2, 0, 0, 2),
0, 0, strategy);
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
make_segment<segment_type>(4, 0, 0, 4),
sqrt(2.0), 2, strategy);
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
make_segment<segment_type>(1, 1, 2, 2),
0, 0, strategy);
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
make_segment<segment_type>(3, 3, 4, 4),
sqrt(8.0), 8, strategy);
}
//===========================================================================
template <typename Point, typename Strategy>
void test_more_empty_input_pointlike_linear(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "testing on empty inputs... " << std::flush;
#endif
bg::model::linestring<Point> line_empty;
bg::model::multi_point<Point> multipoint_empty;
bg::model::multi_linestring<bg::model::linestring<Point> > multiline_empty;
Point point = from_wkt<Point>("point(0 0)");
bg::model::linestring<Point> line =
from_wkt<bg::model::linestring<Point> >("linestring(0 0,1 1)");
// 1st geometry is empty
test_empty_input(multipoint_empty, line, strategy);
// 2nd geometry is empty
test_empty_input(point, line_empty, strategy);
test_empty_input(point, multiline_empty, strategy);
// both geometries are empty
test_empty_input(multipoint_empty, line_empty, strategy);
test_empty_input(multipoint_empty, multiline_empty, strategy);
#ifdef GEOMETRY_TEST_DEBUG
std::cout << "done!" << std::endl;
#endif
}
//===========================================================================
//===========================================================================
//===========================================================================
BOOST_AUTO_TEST_CASE( test_all_point_segment )
{
test_distance_point_segment(point_point_strategy()); // back-compatibility
test_distance_point_segment(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_point_linestring )
{
test_distance_point_linestring(point_point_strategy()); // back-compatibility
test_distance_point_linestring(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_point_multilinestring )
{
test_distance_point_multilinestring(point_point_strategy()); // back-compatibility
test_distance_point_multilinestring(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_linestring_multipoint )
{
test_distance_linestring_multipoint(point_point_strategy()); // back-compatibility
test_distance_linestring_multipoint(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipoint_multilinestring )
{
test_distance_multipoint_multilinestring(point_point_strategy()); // back-compatibility
test_distance_multipoint_multilinestring(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipoint_segment )
{
test_distance_multipoint_segment(point_segment_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_linear )
{
test_more_empty_input_pointlike_linear
<
point_type
>(point_segment_strategy());
}

View File

@@ -0,0 +1,143 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#include <iostream>
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_distance_pointlike_pointlike
#endif
#include <boost/test/included/unit_test.hpp>
#include "test_distance_common.hpp"
typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
typedef bg::model::multi_point<point_type> multi_point_type;
namespace services = bg::strategy::distance::services;
typedef bg::default_distance_result<point_type>::type return_type;
typedef bg::strategy::distance::pythagoras<> point_point_strategy;
//===========================================================================
template <typename Strategy>
void test_distance_point_point(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "point/point distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<point_type, point_type> tester;
tester::apply("point(1 1)",
"point(0 0)",
sqrt(2.0), 2, strategy);
tester::apply("point(1 1)",
"point(1 1)",
0, 0, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_point_multipoint(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "point/multipoint distance tests" << std::endl;
#endif
typedef test_distance_of_geometries<point_type, multi_point_type> tester;
tester::apply("point(1 1)",
"multipoint(1 1,2 1,2 2,1 2)",
0, 0, strategy);
tester::apply("point(1 1)",
"multipoint(2 2,2 3,3 2,3 3)",
sqrt(2.0), 2, strategy);
tester::apply("point(3 0)",
"multipoint(2 2,2 4,4 2,4 4)",
sqrt(5.0), 5, strategy);
}
//===========================================================================
template <typename Strategy>
void test_distance_multipoint_multipoint(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "multipoint/multipoint distance tests" << std::endl;
#endif
typedef test_distance_of_geometries
<
multi_point_type, multi_point_type
> tester;
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
"multipoint(1 1,2 1,2 2,1 2)",
0, 0, strategy);
tester::apply("multipoint(0 0,1 0,0 1,1 1)",
"multipoint(2 2,2 3,3 2,3 3)",
sqrt(2.0), 2, strategy);
}
//===========================================================================
template <typename Point, typename Strategy>
void test_more_empty_input_pointlike_pointlike(Strategy const& strategy)
{
#ifdef GEOMETRY_TEST_DEBUG
std::cout << std::endl;
std::cout << "testing on empty inputs... " << std::flush;
#endif
bg::model::multi_point<Point> multipoint_empty;
Point point = from_wkt<Point>("point(0 0)");
// 1st geometry is empty
test_empty_input(multipoint_empty, point, strategy);
// 2nd geometry is empty
test_empty_input(point, multipoint_empty, strategy);
// both geometries are empty
test_empty_input(multipoint_empty, multipoint_empty, strategy);
#ifdef GEOMETRY_TEST_DEBUG
std::cout << "done!" << std::endl;
#endif
}
//===========================================================================
BOOST_AUTO_TEST_CASE( test_all_point_point )
{
test_distance_point_point(point_point_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_point_multipoint )
{
test_distance_point_multipoint(point_point_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_multipoint_multipoint )
{
test_distance_multipoint_multipoint(point_point_strategy());
}
BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_pointlike )
{
test_more_empty_input_pointlike_pointlike
<
point_type
>(point_point_strategy());
}

View File

@@ -1,14 +1,27 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Tests
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// 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_FROM_WKT_HPP
#define BOOST_GEOMETRY_TEST_FROM_WKT_HPP
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/multi/io/wkt/read.hpp>
template <typename Geometry>
Geometry from_wkt(std::string const& wkt)
inline Geometry from_wkt(std::string const& wkt)
{
Geometry res;
boost::geometry::read_wkt(wkt, res);
return res;
Geometry result;
boost::geometry::read_wkt(wkt, result);
return result;
}
#endif // BOOST_GEOMETRY_TEST_FROM_WKT_HPP

View File

@@ -0,0 +1,65 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// 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_TEST_MODULE
#define BOOST_TEST_MODULE test_num_points
#endif
#include <iostream>
#include <boost/test/included/unit_test.hpp>
#include <boost/geometry/algorithms/num_points.hpp>
#include <boost/geometry/multi/algorithms/num_points.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/multi/geometries/multi_geometries.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/multi/io/wkt/read.hpp>
template <typename Geometry>
inline void test_num_points(std::string const& wkt, std::size_t expected)
{
namespace bg = boost::geometry;
Geometry geometry;
boost::geometry::read_wkt(wkt, geometry);
std::size_t detected = bg::num_points(geometry);
BOOST_CHECK_EQUAL(expected, detected);
detected = bg::num_points(geometry, false);
BOOST_CHECK_EQUAL(expected, detected);
detected = bg::num_points(geometry, true);
}
BOOST_AUTO_TEST_CASE( test_num_points_closed )
{
namespace bg = boost::geometry;
typedef bg::model::point<double,2,bg::cs::cartesian> point;
typedef bg::model::linestring<point> linestring;
typedef bg::model::segment<point> segment;
typedef bg::model::box<point> box;
typedef bg::model::ring<point> ring;
typedef bg::model::polygon<point> polygon;
typedef bg::model::multi_point<point> multi_point;
typedef bg::model::multi_linestring<linestring> multi_linestring;
typedef bg::model::multi_polygon<polygon> multi_polygon;
test_num_points<point>("POINT(0 0)", 1u);
test_num_points<linestring>("LINESTRING(0 0,1 1)", 2u);
test_num_points<segment>("LINESTRING(0 0,1 1)", 2u);
test_num_points<box>("POLYGON((0 0,10 10))", 4u);
test_num_points<ring>("POLYGON((0 0,1 1,0 1,0 0))", 4u);
test_num_points<polygon>("POLYGON((0 0,10 10,0 10,0 0))", 4u);
test_num_points<polygon>("POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))", 10u);
test_num_points<multi_point>("MULTIPOINT((0 0),(1 1))", 2u);
test_num_points<multi_linestring>("MULTILINESTRING((0 0,1 1),(2 2,3 3,4 4))", 5u);
test_num_points<multi_polygon>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 10,1 10,1 9,0 10)))", 9u);
}

View File

@@ -0,0 +1,538 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#ifndef BOOST_GEOMETRY_TEST_DISTANCE_COMMON_HPP
#define BOOST_GEOMETRY_TEST_DISTANCE_COMMON_HPP
#include <iostream>
#include <string>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/multi/geometries/multi_point.hpp>
#include <boost/geometry/multi/geometries/multi_linestring.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/multi/io/wkt/write.hpp>
#include <boost/geometry/io/dsv/write.hpp>
#include <boost/geometry/multi/io/dsv/write.hpp>
#include <boost/geometry/algorithms/num_interior_rings.hpp>
#include <boost/geometry/algorithms/distance.hpp>
#include <boost/geometry/algorithms/comparable_distance.hpp>
#include "from_wkt.hpp"
#include <string_from_type.hpp>
#ifndef BOOST_GEOMETRY_TEST_DISTANCE_HPP
namespace bg = ::boost::geometry;
// function copied from BG's test_distance.hpp
template <typename Geometry1, typename Geometry2>
void test_empty_input(Geometry1 const& geometry1, Geometry2 const& geometry2)
{
try
{
bg::distance(geometry1, geometry2);
}
catch(bg::empty_input_exception const& )
{
return;
}
BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
}
#endif // BOOST_GEOMETRY_TEST_DISTANCE_HPP
//========================================================================
//========================================================================
//========================================================================
// create geometries -- START
template<typename Segment>
Segment make_segment(double x1, double y1, double x2, double y2)
{
typename bg::point_type<Segment>::type p(x1, y1), q(x2, y2);
return Segment(p, q);
}
template <typename Box>
Box make_box2d(double xmin, double ymin, double xmax, double ymax)
{
typedef typename bg::point_type<Box>::type BoxPoint;
return Box(BoxPoint(xmin, ymin), BoxPoint(xmax, ymax));
}
template <typename Box>
Box make_box3d(double xmin, double ymin, double zmin,
double xmax, double ymax, double zmax)
{
typedef typename bg::point_type<Box>::type BoxPoint;
return Box(BoxPoint(xmin, ymin, zmin), BoxPoint(xmax, ymax, zmax));
}
// create geometries -- END
//========================================================================
//========================================================================
//========================================================================
#ifdef GEOMETRY_TEST_DEBUG
// pretty print geometry -- START
template <typename Geometry, typename GeometryTag>
struct pretty_print_geometry_dispatch
{
template <typename Stream>
static inline Stream& apply(Geometry const& geometry, Stream& os)
{
os << bg::wkt(geometry);
return os;
}
};
template <typename Geometry>
struct pretty_print_geometry_dispatch<Geometry, bg::segment_tag>
{
template <typename Stream>
static inline Stream& apply(Geometry const& geometry, Stream& os)
{
os << "SEGMENT" << bg::dsv(geometry);
return os;
}
};
template <typename Geometry>
struct pretty_print_geometry_dispatch<Geometry, bg::box_tag>
{
template <typename Stream>
static inline Stream& apply(Geometry const& geometry, Stream& os)
{
os << "BOX" << bg::dsv(geometry);
return os;
}
};
template <typename Geometry>
struct pretty_print_geometry
{
template <typename Stream>
static inline Stream& apply(Geometry const& geometry, Stream& os)
{
return pretty_print_geometry_dispatch
<
Geometry, typename bg::tag<Geometry>::type
>::apply(geometry, os);
}
};
// pretty print geometry -- END
#endif // GEOMETRY_TEST_DEBUG
//========================================================================
template <typename T>
struct check_equal
{
static inline void apply(T const& value1, T const& value2)
{
BOOST_CHECK( value1 == value2 );
}
};
template <>
struct check_equal<double>
{
static inline void apply(double value1, double value2)
{
BOOST_CHECK_CLOSE( value1, value2, 0.0001 );
}
};
//========================================================================
template
<
typename Geometry1, typename Geometry2,
int id1 = bg::geometry_id<Geometry1>::value,
int id2 = bg::geometry_id<Geometry2>::value
>
struct test_distance_of_geometries
: public test_distance_of_geometries<Geometry1, Geometry2, 0, 0>
{};
template <typename Geometry1, typename Geometry2>
struct test_distance_of_geometries<Geometry1, Geometry2, 0, 0>
{
template
<
typename DistanceType,
typename ComparableDistanceType,
typename Strategy
>
static inline
void apply(std::string const& wkt1,
std::string const& wkt2,
DistanceType const& expected_distance,
ComparableDistanceType const& expected_comparable_distance,
Strategy const& strategy,
bool test_reversed = true)
{
Geometry1 geometry1 = from_wkt<Geometry1>(wkt1);
Geometry2 geometry2 = from_wkt<Geometry2>(wkt2);
apply(geometry1, geometry2,
expected_distance, expected_comparable_distance,
strategy, test_reversed);
}
template
<
typename DistanceType,
typename ComparableDistanceType,
typename Strategy
>
static inline
void apply(Geometry1 const& geometry1,
std::string const& wkt2,
DistanceType const& expected_distance,
ComparableDistanceType const& expected_comparable_distance,
Strategy const& strategy,
bool test_reversed = true)
{
Geometry2 geometry2 = from_wkt<Geometry2>(wkt2);
apply(geometry1, geometry2,
expected_distance, expected_comparable_distance,
strategy, test_reversed);
}
template
<
typename DistanceType,
typename ComparableDistanceType,
typename Strategy
>
static inline
void apply(std::string const& wkt1,
Geometry2 const& geometry2,
DistanceType const& expected_distance,
ComparableDistanceType const& expected_comparable_distance,
Strategy const& strategy,
bool test_reversed = true)
{
Geometry1 geometry1 = from_wkt<Geometry1>(wkt1);
apply(geometry1, geometry2,
expected_distance, expected_comparable_distance,
strategy, test_reversed);
}
template
<
typename DistanceType,
typename ComparableDistanceType,
typename Strategy
>
static inline
void apply(Geometry1 const& geometry1,
Geometry2 const& geometry2,
DistanceType const& expected_distance,
ComparableDistanceType const& expected_comparable_distance,
Strategy const& strategy,
bool test_reversed = true)
{
#ifdef GEOMETRY_TEST_DEBUG
typedef pretty_print_geometry<Geometry1> PPG1;
typedef pretty_print_geometry<Geometry2> PPG2;
PPG1::apply(geometry1, std::cout);
std::cout << " - ";
PPG2::apply(geometry2, std::cout);
std::cout << std::endl;
#endif
typedef typename bg::default_distance_result
<
Geometry1, Geometry2
>::type default_distance_result;
typedef typename bg::strategy::distance::services::return_type
<
Strategy, Geometry1, Geometry2
>::type distance_result_from_strategy;
static const bool same_regular = boost::is_same
<
default_distance_result,
distance_result_from_strategy
>::type::value;
BOOST_CHECK( same_regular );
typedef typename bg::default_comparable_distance_result
<
Geometry1, Geometry2
>::type default_comparable_distance_result;
typedef typename bg::strategy::distance::services::return_type
<
typename bg::strategy::distance::services::comparable_type
<
Strategy
>::type,
Geometry1,
Geometry2
>::type comparable_distance_result_from_strategy;
static const bool same_comparable = boost::is_same
<
default_comparable_distance_result,
comparable_distance_result_from_strategy
>::type::value;
BOOST_CHECK( same_comparable );
// check distance with default strategy
default_distance_result dist_def = bg::distance(geometry1, geometry2);
check_equal
<
default_distance_result
>::apply(dist_def, expected_distance);
// check distance with passed strategy
distance_result_from_strategy dist =
bg::distance(geometry1, geometry2, strategy);
check_equal
<
default_distance_result
>::apply(dist, expected_distance);
// check comparable distance with default strategy
default_comparable_distance_result cdist_def =
bg::comparable_distance(geometry1, geometry2);
check_equal
<
default_comparable_distance_result
>::apply(cdist_def, expected_comparable_distance);
// check comparable distance with passed strategy
comparable_distance_result_from_strategy cdist =
bg::comparable_distance(geometry1, geometry2, strategy);
check_equal
<
default_comparable_distance_result
>::apply(cdist, expected_comparable_distance);
#ifdef GEOMETRY_TEST_DEBUG
std::cout << string_from_type<typename bg::coordinate_type<Geometry1>::type>::name()
<< string_from_type<typename bg::coordinate_type<Geometry2>::type>::name()
<< " -> "
<< string_from_type<default_distance_result>::name()
<< string_from_type<default_comparable_distance_result>::name()
<< std::endl;
std::cout << "distance (default strategy) = " << dist_def << " ; "
<< "distance (passed strategy) = " << dist << " ; "
<< "comp. distance (default strategy) = "
<< cdist_def << " ; "
<< "comp. distance (passed strategy) = "
<< cdist << std::endl;
if ( !test_reversed )
{
std::cout << std::endl;
}
#endif
if ( test_reversed )
{
// check distance with default strategy
dist_def = bg::distance(geometry2, geometry1);
check_equal
<
default_distance_result
>::apply(dist_def, expected_distance);
// check distance with given strategy
dist = bg::distance(geometry2, geometry1, strategy);
check_equal
<
default_distance_result
>::apply(dist, expected_distance);
// check comparable distance with default strategy
cdist_def = bg::comparable_distance(geometry2, geometry1);
check_equal
<
default_comparable_distance_result
>::apply(cdist_def, expected_comparable_distance);
// check comparable distance with given strategy
cdist = bg::comparable_distance(geometry2, geometry1, strategy);
check_equal
<
default_comparable_distance_result
>::apply(cdist, expected_comparable_distance);
#ifdef GEOMETRY_TEST_DEBUG
std::cout << "distance[reversed args] (def. startegy) = "
<< dist_def << " ; "
<< "distance[reversed args] (passed startegy) = "
<< dist << " ; "
<< "comp. distance[reversed args] (def. strategy) = "
<< cdist_def << " ; "
<< "comp. distance[reversed args] (passed strategy) = "
<< cdist << std::endl;
std::cout << std::endl;
#endif
}
}
};
//========================================================================
//========================================================================
template <typename Geometry1, typename Geometry2>
struct test_distance_of_geometries
<
Geometry1, Geometry2,
92 /* segment */, 3 /* polygon */
>
: public test_distance_of_geometries<Geometry1, Geometry2, 0, 0>
{
typedef test_distance_of_geometries<Geometry1, Geometry2, 0, 0> base;
typedef typename bg::ring_type<Geometry2>::type ring_type;
template
<
typename Segment,
typename DistanceType,
typename ComparableDistanceType,
typename Strategy
>
static inline
void apply(Segment const& segment,
std::string const& wkt,
DistanceType const& expected_distance,
ComparableDistanceType const& expected_comparable_distance,
Strategy const& strategy)
{
Geometry2 geometry = from_wkt<Geometry2>(wkt);
apply(segment,
geometry,
expected_distance,
expected_comparable_distance,
strategy);
}
template
<
typename Segment,
typename DistanceType,
typename ComparableDistanceType,
typename Strategy
>
static inline
void apply(Segment const& segment,
Geometry2 const& geometry,
DistanceType const& expected_distance,
ComparableDistanceType const& expected_comparable_distance,
Strategy const& strategy)
{
base::apply(segment, geometry, expected_distance,
expected_comparable_distance, strategy);
if ( bg::num_interior_rings(geometry) == 0 ) {
#ifdef GEOMETRY_TEST_DEBUG
std::cout << "... testing also exterior ring ..." << std::endl;
#endif
test_distance_of_geometries
<
Segment, ring_type
>::apply(segment,
bg::exterior_ring(geometry),
expected_distance,
expected_comparable_distance,
strategy);
}
}
};
//========================================================================
template <typename Geometry1, typename Geometry2, typename Strategy>
void test_empty_input(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Strategy const& strategy)
{
try
{
bg::distance(geometry1, geometry2, strategy);
}
catch(bg::empty_input_exception const& )
{
return;
}
BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
try
{
bg::distance(geometry2, geometry1, strategy);
}
catch(bg::empty_input_exception const& )
{
return;
}
BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
}
#endif // BOOST_GEOMETRY_TEST_DISTANCE_COMMON_HPP

View File

@@ -92,7 +92,7 @@ struct multilinestring_equals
template <typename MultiLinestring>
struct unique<MultiLinestring, false>
{
void operator()(MultiLinestring& mls)
void operator()(MultiLinestring&)
{
}
};