From 302c25280dc140cd6bd90dde54abeafd2fe0ca82 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Thu, 8 May 2014 13:45:10 +0300 Subject: [PATCH] [distance] add unit tests for all geometry combinations --- test/algorithms/distance_all.cpp | 20 + test/algorithms/distance_areal_areal.cpp | 266 ++++++ test/algorithms/distance_linear_areal.cpp | 774 ++++++++++++++++++ test/algorithms/distance_linear_linear.cpp | 268 ++++++ test/algorithms/distance_pointlike_areal.cpp | 547 +++++++++++++ test/algorithms/distance_pointlike_linear.cpp | 250 ++++++ .../distance_pointlike_pointlike.cpp | 138 ++++ 7 files changed, 2263 insertions(+) create mode 100644 test/algorithms/distance_all.cpp create mode 100644 test/algorithms/distance_areal_areal.cpp create mode 100644 test/algorithms/distance_linear_areal.cpp create mode 100644 test/algorithms/distance_linear_linear.cpp create mode 100644 test/algorithms/distance_pointlike_areal.cpp create mode 100644 test/algorithms/distance_pointlike_linear.cpp create mode 100644 test/algorithms/distance_pointlike_pointlike.cpp diff --git a/test/algorithms/distance_all.cpp b/test/algorithms/distance_all.cpp new file mode 100644 index 000000000..74a46fffb --- /dev/null +++ b/test/algorithms/distance_all.cpp @@ -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" diff --git a/test/algorithms/distance_areal_areal.cpp b/test/algorithms/distance_areal_areal.cpp new file mode 100644 index 000000000..10e261513 --- /dev/null +++ b/test/algorithms/distance_areal_areal.cpp @@ -0,0 +1,266 @@ +// 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 + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_distance_areal_areal +#endif + +#include + +#include "test_distance_common.hpp" + + +typedef bg::model::point point_type; +typedef bg::model::polygon polygon_type; +typedef bg::model::multi_polygon multi_polygon_type; +typedef bg::model::box box_type; + +namespace services = bg::strategy::distance::services; +typedef bg::default_distance_result::type return_type; + +typedef bg::strategy::distance::projected_point<> point_segment_strategy; +typedef bg::strategy::distance::pythagoras_box_box<> box_box_strategy; + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("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("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("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("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 +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 + test_distance_of_geometries tester; + + tester("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("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 +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 + test_distance_of_geometries tester; + + tester("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("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 +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 + test_distance_of_geometries tester; + + tester(make_box2d(5, 5, 10, 10), + make_box2d(0, 0, 1, 1), + sqrt(32.0), 32, strategy); + + tester(make_box2d(3, 8, 13, 18), + make_box2d(0, 0, 5, 5), + 3, 9, strategy); + + tester(make_box2d(5, 5, 10, 10), + make_box2d(0, 0, 5, 5), + 0, 0, strategy); + + tester(make_box2d(5, 5, 10, 10), + make_box2d(0, 0, 6, 6), + 0, 0, strategy); + + tester(make_box2d(3, 5, 13, 15), + make_box2d(0, 0, 5, 5), + 0, 0, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("polygon((10 10,10 5,5 5,5 10,10 10))", + make_box2d(0, 0, 1, 1), + sqrt(32.0), 32, strategy); + + tester("polygon((10 10,10 5,5 5,5 10,10 10))", + make_box2d(0, 0, 5, 5), + 0, 0, strategy); + + tester("polygon((10 10,10 5,5 5,5 10,10 10))", + make_box2d(0, 0, 6, 6), + 0, 0, strategy); + + tester("polygon((10 10,15 5,10 0,5 5,10 10))", + make_box2d(5, 0, 7.5, 2.5), + 0, 0, strategy); + + tester("polygon((10 10,15 5,10 0,5 5,10 10))", + make_box2d(5, 0, 6, 1), + sqrt(4.5), 4.5, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("multipolygon(((-10 -10,-10 -9,-9 -9,-9 -10,-10 -10)),\ + ((2 2,2 3,3 3,3 2,2 2)))", + make_box2d(0, 0, 1, 1), + sqrt(2.0), 2, strategy); + + tester("multipolygon(((-10 -10,-10 -9,-9 -9,-9 -10,-10 -10)),\ + ((2 2,2 3,3 3,3 2,2 2)))", + make_box2d(0, 0, 2, 2), + 0, 0, strategy); + + tester("multipolygon(((-10 -10,-10 -9,-9 -9,-9 -10,-10 -10)),\ + ((2 2,2 3,3 3,3 2,2 2)))", + make_box2d(0, 0, 2.5, 2), + 0, 0, strategy); +} + +//=========================================================================== + +template +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 polygon_empty; + bg::model::multi_polygon > multipolygon_empty; + + bg::model::polygon polygon = + from_wkt >("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_segment_strategy()); +} diff --git a/test/algorithms/distance_linear_areal.cpp b/test/algorithms/distance_linear_areal.cpp new file mode 100644 index 000000000..c5d4d1409 --- /dev/null +++ b/test/algorithms/distance_linear_areal.cpp @@ -0,0 +1,774 @@ +// 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 + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_distance_linear_areal +#endif + +#include + +#include "test_distance_common.hpp" + + +typedef bg::model::point point_type; +typedef bg::model::point int_point_type; +typedef bg::model::segment segment_type; +typedef bg::model::segment int_segment_type; +typedef bg::model::linestring linestring_type; +typedef bg::model::multi_linestring multi_linestring_type; +typedef bg::model::polygon polygon_type; +typedef bg::model::multi_polygon multi_polygon_type; +typedef bg::model::box box_type; +typedef bg::model::box int_box_type; + +namespace services = bg::strategy::distance::services; +typedef bg::default_distance_result::type return_type; + +typedef bg::strategy::distance::pythagoras<> point_point_strategy; +typedef bg::strategy::distance::projected_point<> point_segment_strategy; + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester(make_segment(-1, 20, 1, 20), + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 10, 100, strategy); + + tester(make_segment(1, 20, 2, 40), + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 10, 100, strategy); + + tester(make_segment(-1, 20, -1, 5), + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 0, 0, strategy); + + tester(make_segment(-1, 20, -1, -20), + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 0, 0, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("linestring(-1 20,1 20,1 30)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 10, 100, strategy, true); + + tester("linestring(-1 20,1 20,1 5)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 0, 0, strategy, true); + + tester("linestring(-1 20,1 20,1 -20)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 0, 0, strategy, true); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("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("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("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 +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 + test_distance_of_geometries tester; + + tester(make_segment(-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(make_segment(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(make_segment(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(make_segment(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 +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 + test_distance_of_geometries tester; + + tester("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("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("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("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 +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 + test_distance_of_geometries + < + multi_linestring_type, multi_polygon_type + > tester; + + tester("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("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 +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; + + test_distance_of_geometries tester; + test_distance_of_geometries itester; + + // segments that intersect the box + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 0.5, 0.5, 0.75), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 0.5, 1.5, 0.75), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, -1, 0.5, 2), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 1, 1.5, 0.75), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(2, 0, 0, 2), + 0, 0, strategy); + + // segment that has closest point on box boundary + tester(make_box2d(0, 0, 1, 1), + make_segment(4, 0.5, 5, 0.75), + 3, 9, strategy); + + // segment that has closest point on box corner + tester(make_box2d(0, 0, 1, 1), + make_segment(4, 0, 0, 4), + sqrt(2), 2, strategy); + itester(make_box2d(0, 0, 1, 1), + make_segment(-4, 0, 0, -4), + sqrt(8), 8, strategy); + itester(make_box2d(0, 0, 1, 1), + make_segment(-8, 4, 4, -8), + sqrt(8), 8, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-4, 0, 0, 4), + 1.5 * sqrt(2), 4.5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-4, 0, 1, 5), + 1.5 * sqrt(2), 4.5, strategy); + itester(make_box2d(0, 0, 1, 1), + make_segment(0, -2, 3, 1), + 0.5 * sqrt(2), 0.5, strategy); + itester(make_box2d(0, 0, 1, 1), + make_segment(0, -2, 2, 2), + 0, 0, strategy); + + // horizontal segments + itester(make_box2d(0, 0, 1, 1), + make_segment(-2, -1, -1, -1), + sqrt(2), 2, strategy); + itester(make_box2d(0, 0, 1, 1), + make_segment(-1, -1, 0, -1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-0.5, -1, 0.5, -1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, -1, 0.75, -1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, -1, 1.25, -1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, -1, 2, -1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(2, -1, 3, -1), + sqrt(2), 2, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -1, 2, -1), + 1, 1, strategy); + + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 0, -1, 0), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 0, 0, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-0.5, 0, 0.5, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 0, 0.75, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 0, 1.25, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 0, 2, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(2, 0, 3, 0), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 0, 2, 0), + 0, 0, strategy); + + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 0.5, -1, 0.5), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 0.5, 0, 0.5), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-0.5, 0.5, 0.5, 0.5), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 0.5, 0.75, 0.5), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 0.5, 1.25, 0.5), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 0.5, 2, 0.5), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(2, 0.5, 3, 0.5), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 0.5, 2, 0.5), + 0, 0, strategy); + + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 1, -1, 1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 1, 0, 1), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-0.5, 1, 0.5, 1), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 1, 0.75, 1), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 1, 1.25, 1), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 1, 2, 1), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(2, 1, 3, 1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 1, 2, 1), + 0, 0, strategy); + + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 3, -1, 3), + sqrt(5), 5, strategy); + itester(make_box2d(0, 0, 1, 1), + make_segment(-1, 3, 0, 3), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-0.5, 3, 0.5, 3), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 3, 0.75, 3), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 3, 1.25, 3), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 3, 2, 3), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(2, 3, 3, 3), + sqrt(5), 5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 3, 2, 3), + 2, 4, strategy); + + // vertical segments + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, -2, -1, -1), + sqrt(2), 2, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, -1, -1, 0), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, -0.5, -1, 0.5), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 0.5, -1, 0.75), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 0.5, -1, 1.25), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 1, -1, 2), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 2, -1, 3), + sqrt(2), 2, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, -2, -1, 2), + 1, 1, strategy); + + tester(make_box2d(0, 0, 1, 1), + make_segment(0, -2, 0, -1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, -1, 0, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, -0.5, 0, 0.5), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, 0.5, 0, 0.75), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, 0.5, 0, 1.25), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, 1, 0, 2), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, 2, 0, 3), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, -2, 0, 2), + 0, 0, strategy); + + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, -2, 0.5, -1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, -1, 0.5, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, -0.5, 0.5, 0.5), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 0.5, 0.5, 0.75), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 0.5, 0.5, 1.25), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 1, 0.5, 2), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 2, 0.5, 3), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, -2, 0.5, 2), + 0, 0, strategy); + + tester(make_box2d(0, 0, 1, 1), + make_segment(1, -2, 1, -1), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, -1, 1, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, -0.5, 1, 0.5), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 0.5, 1, 0.75), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 0.5, 1, 1.25), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 1, 1, 2), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 2, 1, 3), + 1, 1, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, -2, 1, 2), + 0, 0, strategy); + + tester(make_box2d(0, 0, 1, 1), + make_segment(3, -2, 3, -1), + sqrt(5), 5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(3, -1, 3, 0), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(3, -0.5, 3, 0.5), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(3, 0.5, 3, 0.75), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(3, 0.5, 3, 1.25), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(3, 1, 3, 2), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(3, 2, 3, 3), + sqrt(5), 5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(3, -2, 3, 2), + 2, 4, strategy); + + // positive slope + itester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, -1, -1), + sqrt(2), 2, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 0, -0.5), + 0.5, 0.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 0.5, -0.5), + 0.5, 0.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 1, -0.5), + 0.5, 0.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 2, 0), + sqrt(0.2), 0.2, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 4, 1), + sqrt(0.2), 0.2, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, -1.5, 0), + 1.5, 2.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, -1.5, 0.5), + 1.5, 2.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, -1.5, 1), + 1.5, 2.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 0, 2), + sqrt(0.2), 0.2, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 1, 4), + sqrt(0.2), 0.2, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 4, 2), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 2, 4), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 4, 3), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 3, 4), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, 3, 3), + 0, 0, strategy); + + // negative slope + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, -2, -1, -3), + sqrt(8), 8, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-3, -1, 0, -4), + sqrt(8), 8, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 0.75, -1.5, 0.5), + 1.5, 2.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 1.5, -1.5, 0.5), + 1.5, 2.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 2, 0.75, 1.5), + 0.5, 0.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 2, 0.75, 1.5), + 0.5, 0.25, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, 2, 2, 0), + 0, 0, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0, 3, 3, 0), + sqrt(0.5), 0.5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 4, 4, -1), + sqrt(0.5), 0.5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, 4, 0, 3), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-2, 5, -1, 4), + sqrt(10), 10, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(3, -1, 4, -4), + sqrt(5), 5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(1, 2, 2, 1), + sqrt(0.5), 0.5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, -2, 2, -3), + 2, 4, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, -2, 0, -3), + sqrt(5), 5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, -2, 0.5, -3.5), + sqrt(5), 5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(-1, -2, 0.5, -3.5), + sqrt(5), 5, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 3, 2.5, 2), + sqrt(2.45), 2.45, strategy); + tester(make_box2d(0, 0, 1, 1), + make_segment(0.5, 1.5, 1.5, -1.5), + 0, 0, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + // linestrings that intersect the box + tester("linestring(-1 0.5,0.5 0.75)", + make_box2d(0, 0, 1, 1), + 0, 0, strategy); + tester("linestring(-1 0.5,1.5 0.75)", + make_box2d(0, 0, 1, 1), + 0, 0, strategy); + + // linestring that has closest point on box boundary + tester("linestring(4 0.5,5 0.75)", + make_box2d(0, 0, 1, 1), + 3, 9, strategy); + + // linestring that has closest point on box corner + tester("linestring(4 0,0 4)", + make_box2d(0, 0, 1, 1), + sqrt(2), 2, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + // multilinestring that intersects the box + tester("multilinestring((-1 0.5,0.5 0.75),(4 0.5,5 0.75))", + make_box2d(0, 0, 1, 1), + 0, 0, strategy); + + // multilinestring that has closest point on box boundary + tester("multilinestring((4 0.5,5 0.75))", + make_box2d(0, 0, 1, 1), + 3, 9, strategy); + + // multilinestring that has closest point on box corner + tester("multilinestring((5 0,0 5),(4 0,0 4))", + make_box2d(0, 0, 1, 1), + sqrt(2), 2, strategy); +} + +//=========================================================================== + +template +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 line_empty; + bg::model::polygon polygon_empty; + bg::model::multi_linestring > multiline_empty; + bg::model::multi_polygon > multipolygon_empty; + + bg::model::linestring line = + from_wkt >("linestring(0 0,1 1)"); + + bg::model::polygon polygon = + from_wkt >("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_point_strategy()); + 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_segment_strategy()); +} diff --git a/test/algorithms/distance_linear_linear.cpp b/test/algorithms/distance_linear_linear.cpp new file mode 100644 index 000000000..17ac8874f --- /dev/null +++ b/test/algorithms/distance_linear_linear.cpp @@ -0,0 +1,268 @@ +// 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 + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_distance_linear_linear +#endif + +#include + +#include "test_distance_common.hpp" + + +typedef bg::model::point point_type; +typedef bg::model::segment segment_type; +typedef bg::model::linestring linestring_type; +typedef bg::model::multi_linestring multi_linestring_type; + +namespace services = bg::strategy::distance::services; +typedef bg::default_distance_result::type return_type; + +typedef bg::strategy::distance::projected_point<> point_segment_strategy; + +//=========================================================================== + +#ifdef BOOST_GEOMETRY_SUPPORT_SEGMENT_SEGMENT_DISTANCE +template +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 + test_distance_of_geometries tester; + + tester(make_segment(0, 0, 10, 0), + make_segment(4, 2, 4, 0.5), + return_type(0.5), return_type(0.25), strategy); + + tester(make_segment(0, 0, 10, 0), + make_segment(4, 2, 4, -0.5), + return_type(0), return_type(0), strategy); + + tester(make_segment(0, 0, 10, 0), + make_segment(4, 2, 0, 0), + return_type(0), return_type(0), strategy); + + tester(make_segment(0, 0, 10, 0), + make_segment(-2, 3, 1, 2), + return_type(2), return_type(4), strategy); +} +#endif // BOOST_GEOMETRY_SUPPORT_SEGMENT_SEGMENT_DISTANCE + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester(make_segment(-1, -1, -2, -2), + "linestring(2 1,1 2,4 0)", + sqrt(12.5), 12.5, strategy); + + tester(make_segment(1, 1, 2, 2), + "linestring(2 1,1 2,4 0)", + 0, 0, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + // It is not obvious that linestrings with only one point are valid + tester("linestring(1 1)", "linestring(2 1)", 1, 1, strategy); + + tester("linestring(1 1,3 1)", "linestring(2 1)", 0, 0, strategy); + + tester("linestring(1 1)", "linestring(0 0,-2 0,2 -2,2 0)", + sqrt(2.0), 2, strategy); + + tester("linestring(1 1,1 1)", "linestring(2 1,2 1)", 1, 1, strategy); + + tester("linestring(1 1,1 1,1 1)", "linestring(2 1,2 1,2 1,2 1)", + 1, 1, strategy); + + tester("linestring(1 1,3 1)", "linestring(2 1,2 1)", 0, 0, strategy); + + tester("linestring(1 1,1 1)", "linestring(0 0,-2 0,2 -2,2 0)", + sqrt(2.0), 2, strategy); + + tester("linestring(1 1,3 1)", "linestring(2 1, 4 1)", 0, 0, strategy); + + tester("linestring(1 1,2 2,3 3)", "linestring(2 1,1 2,4 0)", + 0, 0, strategy); + + tester("linestring(1 1,2 2,3 3)", "linestring(1 0,2 -1,4 0)", + 1, 1, strategy); + + tester("linestring(1 1,2 2,3 3)", "linestring(1 -10,2 0,2.1 -10,4 0)", + sqrt(2.0), 2, strategy); + + tester("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("linestring(1 1,1 2)", "linestring(0 0,-2 0,2 -2,2 0)", + sqrt(2.0), 2, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester(make_segment(-1, -1, -2, -2), + "multilinestring((2 1,1 2),(4 0,4 10))", + sqrt(12.5), 12.5, strategy); + + tester(make_segment(1, 1, 2, 2), + "multilinestring((2 1,1 2),(4 0,4 10))", + 0, 0, strategy); +} + +//=========================================================================== + +template +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 + + test_distance_of_geometries tester; + + tester("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("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 +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 + + test_distance_of_geometries + < + multi_linestring_type, multi_linestring_type + > tester; + + tester("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("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("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 +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 line_empty; + bg::model::multi_linestring > multiline_empty; + + bg::model::linestring line = + from_wkt >("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 +} + +//=========================================================================== + +#ifdef BOOST_GEOMETRY_SUPPORT_SEGMENT_SEGMENT_DISTANCE +BOOST_AUTO_TEST_CASE( test_all_segment_segment ) +{ + test_distance_segment_segment(point_segment_strategy()); +} +#endif // BOOST_GEOMETRY_SUPPORT_SEGMENT_SEGMENT_DISTANCE + +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_segment_strategy()); +} diff --git a/test/algorithms/distance_pointlike_areal.cpp b/test/algorithms/distance_pointlike_areal.cpp new file mode 100644 index 000000000..78e42a4f9 --- /dev/null +++ b/test/algorithms/distance_pointlike_areal.cpp @@ -0,0 +1,547 @@ +// 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 + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_distance_pointlike_areal +#endif + +#include + +#include "test_distance_common.hpp" + + +typedef bg::model::point point_type; +typedef bg::model::multi_point multi_point_type; +typedef bg::model::point point_type_3d; +typedef bg::model::multi_point multi_point_type_3d; +typedef bg::model::polygon polygon_type; +typedef bg::model::multi_polygon multi_polygon_type; +typedef bg::model::box box_type; +typedef bg::model::box box_type_3d; + +namespace services = bg::strategy::distance::services; +typedef bg::default_distance_result::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 +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 + test_distance_of_geometries tester; + + tester("point(0 -20)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 10, 100, strategy); + + tester("point(12 0)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 2, 4, strategy); + + tester("point(0 0)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 0, 0, strategy); + + tester("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 +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 + test_distance_of_geometries tester; + + tester("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("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("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("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 +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 + test_distance_of_geometries tester; + + tester("multipoint(0 -20,0 -15)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 5, 25, strategy); + + tester("multipoint(16 0,12 0)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 2, 4, strategy); + + tester("multipoint(0 0,5 5,4 4)", + "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))", + 0, 0, strategy); + + tester("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 +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 + test_distance_of_geometries tester; + + tester("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("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("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("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 +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 + test_distance_of_geometries tester; + + // point inside box + tester(make_box2d(-1, -1, 1, 1), + "point(0 0)", 0, 0, strategy); + + // points on box corners + tester(make_box2d(-1, -1, 1, 1), + "point(-1 -1)", 0, 0, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(-1 1)", 0, 0, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(1 -1)", 0, 0, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(1 1)", 0, 0, strategy); + + // points on box boundary edges + tester(make_box2d(-1, -1, 1, 1), + "point(0 -1)", 0, 0, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(-1 0)", 0, 0, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(1 0)", 0, 0, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(0 1)", 0, 0, strategy); + + // points outside box + tester(make_box2d(-1, -1, 1, 1), + "point(0 4)", 3, 9, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(0.5 4)", 3, 9, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(-0.5 5)", 4, 16, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(3 0.25)", 2, 4, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(-3 -0.25)", 2, 4, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(3 5)", sqrt(20), 20, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(-5 -4)", 5, 25, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(2 -2)", sqrt(2), 2, strategy); + tester(make_box2d(-1, -1, 1, 1), + "point(-3 4)", sqrt(13), 13, strategy); +} + +//=========================================================================== + +template +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_point; + typedef bg::model::box int_box; + + test_distance_of_geometries() + ("point(0 0)", + make_box2d(1, 1, 2, 2), + sqrt(2), 2, strategy); + + test_distance_of_geometries() + ("point(0.5 0)", + make_box2d(1, -1, 2, 1), + 0.5, 0.25, strategy); + + test_distance_of_geometries() + ("point(1.5 0)", + make_box2d(1, -1, 2, 1), + 0, 0, strategy); + + test_distance_of_geometries() + ("point(1.5 0)", + make_box2d(1, -1, 2, 1), + 0, 0, strategy); + + test_distance_of_geometries() + ("point(1 0)", + make_box2d(0.5, -1, 1.5, 1), + 0, 0, strategy); + + test_distance_of_geometries() + ("point(0 0)", + make_box2d(0.5, -1, 1.5, 1), + 0.5, 0.25, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + // point inside box + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 0 0)", 0, 0, strategy); + + // points on box corners + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 -1 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 -1 1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 1 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 1 1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 -1 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 -1 1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 1 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 1 1)", 0, 0, strategy); + + // points on box boundary edges + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 -1 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 -1 1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 1 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 1 1)", 0, 0, strategy); + + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 0 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 0 1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 0 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 0 1)", 0, 0, strategy); + + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 -1 0)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 1 0)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 -1 0)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 1 0)", 0, 0, strategy); + + // point on box faces + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 0 -1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 0 1)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 -1 0)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 1 0)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-1 0 0)", 0, 0, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(1 0 0)", 0, 0, strategy); + + // points outside box -- closer to box corners + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-2 -3 -4)", sqrt(14), 14, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-2 -3 3)", 3, 9, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-2 5 -2)", sqrt(18), 18, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-2 5 3)", sqrt(21), 21, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(4 -6 -3)", sqrt(38), 38, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(4 -6 4)", sqrt(43), 43, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(4 7 -2)", sqrt(46), 46, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(4 7 8)", sqrt(94), 94, strategy); + + + // points closer to box facets + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 0 10)", 9, 81, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 0 -5)", 4, 16, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 7 0)", 6, 36, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 -6 0)", 5, 25, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(4 0 0)", 3, 9, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-3 0 0)", 2, 4, strategy); + + // points closer to box edges + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 -4 -5)", 5, 25, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 -3 6)", sqrt(29), 29, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 2 -7)", sqrt(37), 37, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(0 8 7)", sqrt(85), 85, strategy); + + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-4 0 -4)", sqrt(18), 18, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-3 0 5)", sqrt(20), 20, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(2 0 -6)", sqrt(26), 26, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(8 0 6)", sqrt(74), 74, strategy); + + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-5 -5 0)", sqrt(32), 32, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(-4 6 0)", sqrt(34), 34, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(3 -7 0)", sqrt(40), 40, strategy); + tester(make_box3d(-1, -1, -1, 1, 1, 1), + "point(9 7 0)", 10, 100, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + // at least one point inside the box + tester(make_box2d(0, 0, 10, 10), + "multipoint(0 0,-1 -1,20 20)", 0, 0, strategy); + + tester(make_box2d(0, 0, 10, 10), + "multipoint(1 1,-1 -1,20 20)", 0, 0, strategy); + + tester(make_box2d(0, 0, 10, 10), + "multipoint(1 1,2 2,3 3)", 0, 0, strategy); + + // all points outside the box + tester(make_box2d(0, 0, 10, 10), + "multipoint(-1 -1,20 20)", sqrt(2), 2, strategy); + + tester(make_box2d(0, 0, 10, 10), + "multipoint(5 13, 50 50)", 3, 9, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + // at least one point inside the box + tester(make_box3d(0, 0, 0, 10, 10, 10), + "multipoint(0 0 0,-1 -1 -1,20 20 20)", 0, 0, strategy); + + tester(make_box3d(0, 0, 0, 10, 10, 10), + "multipoint(1 1 1,-1 -1 -1,20 20 20)", 0, 0, strategy); + + tester(make_box3d(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(make_box3d(0, 0, 0, 10, 10, 10), + "multipoint(-1 -1 -1,20 20 20)", sqrt(3), 3, strategy); + + tester(make_box3d(0, 0, 0, 10, 10, 10), + "multipoint(5 5 13,50 50 50)", 3, 9, strategy); +} + +//=========================================================================== + +template +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 multipoint_empty; + bg::model::polygon polygon_empty; + bg::model::multi_polygon > multipolygon_empty; + + Point point = from_wkt("point(0 0)"); + bg::model::polygon polygon = + from_wkt >("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()); +} diff --git a/test/algorithms/distance_pointlike_linear.cpp b/test/algorithms/distance_pointlike_linear.cpp new file mode 100644 index 000000000..9fe7f84c7 --- /dev/null +++ b/test/algorithms/distance_pointlike_linear.cpp @@ -0,0 +1,250 @@ +// 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 + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_distance_pointlike_linear +#endif + +#include + +#include "test_distance_common.hpp" + + +typedef bg::model::point point_type; +typedef bg::model::multi_point multi_point_type; +typedef bg::model::segment segment_type; +typedef bg::model::linestring linestring_type; +typedef bg::model::multi_linestring multi_linestring_type; + +namespace services = bg::strategy::distance::services; +typedef bg::default_distance_result::type return_type; + +typedef bg::strategy::distance::pythagoras<> point_point_strategy; +typedef bg::strategy::distance::projected_point<> point_segment_strategy; + + +//=========================================================================== + + +template +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 + test_distance_of_geometries tester; + + tester("point(0 0)", "segment(2 0,3 0)", 2, 4, strategy); + tester("point(2.5 3)", "segment(2 0,3 0)", 3, 9, strategy); + tester("point(2 0)", "segment(2 0,3 0)", 0, 0, strategy); + tester("point(3 0)", "segment(2 0,3 0)", 0, 0, strategy); + tester("point(2.5 0)", "segment(2 0,3 0)", 0, 0, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("point(0 0)", "linestring(2 0)", 2, 4, strategy); + tester("point(0 0)", "linestring(2 0,3 0)", 2, 4, strategy); + tester("point(2.5 3)", "linestring(2 0,3 0)", 3, 9, strategy); + tester("point(2 0)", "linestring(2 0,3 0)", 0, 0, strategy); + tester("point(3 0)", "linestring(2 0,3 0)", 0, 0, strategy); + tester("point(2.5 0)", "linestring(2 0,3 0)", 0, 0, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("point(0 0)", "multilinestring((-5 0,-3 0),(2 0,3 0))", + 2, 4, strategy); + tester("point(2.5 3)", "multilinestring((-5 0,-3 0),(2 0,3 0))", + 3, 9, strategy); + tester("point(2 0)", "multilinestring((-5 0,-3 0),(2 0,3 0))", + 0, 0, strategy); + tester("point(3 0)", "multilinestring((-5 0,-3 0),(2 0,3 0))", + 0, 0, strategy); + tester("point(2.5 0)", "multilinestring((-5 0,-3 0),(2 0,3 0))", + 0, 0, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("linestring(2 0,0 2,100 100)", + "multipoint(0 0,1 0,0 1,1 1)", + 0, 0, strategy); + tester("linestring(4 0,0 4,100 100)", + "multipoint(0 0,1 0,0 1,1 1)", + sqrt(2.0), 2, strategy); + tester("linestring(1 1,2 2,100 100)", + "multipoint(0 0,1 0,0 1,1 1)", + 0, 0, strategy); + tester("linestring(3 3,4 4,100 100)", + "multipoint(0 0,1 0,0 1,1 1)", + sqrt(8.0), 8, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("multipoint(0 0,1 0,0 1,1 1)", + "multilinestring((2 0,0 2),(2 2,3 3))", + 0, 0, strategy); + tester("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("multipoint(0 0,1 0,0 1,1 1)", + "multilinestring((4 4,5 5),(1 1,2 2))", + 0, 0, strategy); + tester("multipoint(0 0,1 0,0 1,1 1)", + "multilinestring((3 3,4 4),(4 4,5 5))", + sqrt(8.0), 8, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("multipoint(0 0,1 0,0 1,1 1)", + make_segment(2, 0, 0, 2), + 0, 0, strategy); + tester("multipoint(0 0,1 0,0 1,1 1)", + make_segment(4, 0, 0, 4), + sqrt(2.0), 2, strategy); + tester("multipoint(0 0,1 0,0 1,1 1)", + make_segment(1, 1, 2, 2), + 0, 0, strategy); + tester("multipoint(0 0,1 0,0 1,1 1)", + make_segment(3, 3, 4, 4), + sqrt(8.0), 8, strategy); +} + +//=========================================================================== + +template +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 line_empty; + bg::model::multi_point multipoint_empty; + bg::model::multi_linestring > multiline_empty; + + Point point = from_wkt("point(0 0)"); + bg::model::linestring line = + from_wkt >("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()); +} diff --git a/test/algorithms/distance_pointlike_pointlike.cpp b/test/algorithms/distance_pointlike_pointlike.cpp new file mode 100644 index 000000000..149a2dc3e --- /dev/null +++ b/test/algorithms/distance_pointlike_pointlike.cpp @@ -0,0 +1,138 @@ +// 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 + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_distance_pointlike_pointlike +#endif + +#include + +#include "test_distance_common.hpp" + + +typedef bg::model::point point_type; +typedef bg::model::multi_point multi_point_type; + +namespace services = bg::strategy::distance::services; +typedef bg::default_distance_result::type return_type; + +typedef bg::strategy::distance::pythagoras<> point_point_strategy; + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("point(1 1)", "point(0 0)", + sqrt(2.0), 2, strategy); + tester("point(1 1)", "point(1 1)", + 0, 0, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("point(1 1)", + "multipoint(1 1,2 1,2 2,1 2)", + 0, 0, strategy); + tester("point(1 1)", + "multipoint(2 2,2 3,3 2,3 3)", + sqrt(2.0), 2, strategy); + tester("point(3 0)", + "multipoint(2 2,2 4,4 2,4 4)", + sqrt(5.0), 5, strategy); +} + +//=========================================================================== + +template +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 + test_distance_of_geometries tester; + + tester("multipoint(0 0,1 0,0 1,1 1)", + "multipoint(1 1,2 1,2 2,1 2)", + 0, 0, strategy); + tester("multipoint(0 0,1 0,0 1,1 1)", + "multipoint(2 2,2 3,3 2,3 3)", + sqrt(2.0), 2, strategy); +} + +//=========================================================================== + +template +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 multipoint_empty; + + Point point = from_wkt("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()); +}