// Boost.Geometry // Unit Test // Copyright (c) 2021 Oracle and/or its affiliates. // Contributed and/or modified by Vissarion Fysikopoulos, 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_algorithms_closest_points_pointlike_areal #endif #include "common.hpp" #include "empty_geometry.hpp" namespace bg = boost::geometry; //=========================================================================== template void test_closest_points_point_polygon_or_ring(Strategies const& strategies) { #ifdef BOOST_GEOMETRY_TEST_DEBUG std::cout << std::endl; std::cout << "point/polygon or ring closest_points tests" << std::endl; #endif using Segment = bg::model::segment; using Ring = bg::model::ring; using Polygon = bg::model::polygon; using tester = test_geometry; tester::apply("POINT(1 1)", "POLYGON((0 0,1 0,0 1,0 0))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); tester::apply("POINT(0.4 0.4)", "POLYGON((0 0,1 0,0 1,0 0))", "SEGMENT(0.4 0.4,0.4 0.4)", strategies); using tester2 = test_geometry; tester2::apply("POINT(1 1)", "POLYGON((0 0,1 0,0 1,0 0))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); //default strategies tester2::apply("POINT(1 1)", "POLYGON((0 0,1 0,0 1,0 0))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies, true, true); tester2::apply("POINT(1 1)", "POLYGON((0 0,1 0,0 1,0 0)(0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); tester2::apply("POINT(1 1)", "POLYGON((0 0,1 0,0 1,0 0)(0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); tester2::apply("POINT(0.01 0.01)", "POLYGON((0 0,1 0,0 1,0 0)(0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4))", "SEGMENT(0.01 0.01,0.01 0.01)", strategies); } //=========================================================================== template void test_closest_points_point_box(Strategies const& strategies) { #ifdef BOOST_GEOMETRY_TEST_DEBUG std::cout << std::endl; std::cout << "point/box closest_points tests" << std::endl; #endif using Segment = bg::model::segment; using Box = bg::model::box; using tester = test_geometry; //all 8 possible placements of point around box tester::apply("POINT(5 25)", "BOX(10 10,20 20)", "SEGMENT(5 25,10 20)", strategies); tester::apply("POINT(15 25)", "BOX(10 10,20 20)", "SEGMENT(15 25,15 20)", strategies); tester::apply("POINT(25 25)", "BOX(10 10,20 20)", "SEGMENT(25 25,20 20)", strategies); tester::apply("POINT(5 15)", "BOX(10 10,20 20)", "SEGMENT(5 15,10 15)", "SEGMENT(5 15,10 15.055045985544346)", strategies); tester::apply("POINT(25 15)", "BOX(10 10,20 20)", "SEGMENT(25 15,20 15)", "SEGMENT(25 15,20 15.055045985544346)", strategies); tester::apply("POINT(5 5)", "BOX(10 10,20 20)", "SEGMENT(5 5,10 10)", strategies); tester::apply("POINT(15 5)", "BOX(10 10,20 20)", "SEGMENT(15 5,15 10)", strategies); tester::apply("POINT(25 5)", "BOX(10 10,20 20)", "SEGMENT(25 5,20 10)", strategies); //default strategies tester::apply("POINT(25 5)", "BOX(10 10,20 20)", "SEGMENT(25 5,20 10)", strategies, true, true); //inside tester::apply("POINT(15 15)", "BOX(10 10,20 20)", "SEGMENT(15 15,15 15)", strategies); } //=========================================================================== template void test_closest_points_point_multi_polygon(Strategies const& strategies) { #ifdef BOOST_GEOMETRY_TEST_DEBUG std::cout << std::endl; std::cout << "point/multi-polygon closest_points tests" << std::endl; #endif using Segment = bg::model::segment; using Polygon = bg::model::polygon; using MultiPolygon = bg::model::multi_polygon; using tester = test_geometry; tester::apply("POINT(1 1)", "MULTIPOLYGON(((0 0,1 0,0 1,0 0)),\ ((0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4)))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); tester::apply("POINT(1 1)", "MULTIPOLYGON(((0 0,1 0,0 1,0 0)),\ ((0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4)))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies, true, true); tester::apply("POINT(0.01 0.01)", "MULTIPOLYGON(((0 0,1 0,0 1,0 0)),\ ((0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4)))", "SEGMENT(0.01 0.01,0.01 0.01)", strategies); } //=========================================================================== template void test_closest_points_multi_point_polygon_or_ring(Strategies const& strategies) { #ifdef BOOST_GEOMETRY_TEST_DEBUG std::cout << std::endl; std::cout << "multi-point/polygon or ring closest_points tests" << std::endl; #endif using Segment = bg::model::segment; using MultiPoint = bg::model::multi_point; using Ring = bg::model::ring; using Polygon = bg::model::polygon; using tester = test_geometry; tester::apply("MULTIPOINT((2 1),(1 1))", "POLYGON((0 0,1 0,0 1,0 0))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); tester::apply("MULTIPOINT((2 1),(1 1))", "POLYGON((0 0,1 0,0 1,0 0))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies, true, true); tester::apply("MULTIPOINT((1 1),(0.01 0.01))", "POLYGON((0 0,1 0,0 1,0 0))", "SEGMENT(0.01 0.01,0.01 0.01)", strategies); using tester2 = test_geometry; tester2::apply("MULTIPOINT((2 1),(1 1))", "POLYGON((0 0,1 0,0 1,0 0))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); tester2::apply("MULTIPOINT((2 1),(1 1))", "POLYGON((0 0,1 0,0 1,0 0)(0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); } //=========================================================================== template void test_closest_points_multi_point_multi_polygon(Strategies const& strategies) { #ifdef BOOST_GEOMETRY_TEST_DEBUG std::cout << std::endl; std::cout << "multi-point/multi-polygon closest_points tests" << std::endl; #endif using Segment = bg::model::segment; using MultiPoint = bg::model::multi_point; using Polygon = bg::model::polygon; using MultiPolygon = bg::model::multi_polygon; using tester = test_geometry; tester::apply("MULTIPOINT((2 1),(1 1))", "MULTIPOLYGON(((0 0,1 0,0 1,0 0)),\ ((0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4)))", "SEGMENT(1 1,0.5 0.5)", "SEGMENT(1 1,0.499962 0.500095)", "SEGMENT(1 1,0.503314 0.496737)", strategies); tester::apply("MULTIPOINT((2 1),(0.01 0.01))", "MULTIPOLYGON(((0 0,1 0,0 1,0 0)),\ ((0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4)))", "SEGMENT(0.01 0.01,0.01 0.01)", strategies); tester::apply("MULTIPOINT((2 1),(0.01 0.01))", "MULTIPOLYGON(((0 0,1 0,0 1,0 0)),\ ((0.4 0.4,0.4 0.1,0.1 0.4,0.4 0.4)))", "SEGMENT(0.01 0.01,0.01 0.01)", strategies, true, true); } //=========================================================================== template void test_closest_points_multi_point_box(Strategies const& strategies) { #ifdef BOOST_GEOMETRY_TEST_DEBUG std::cout << std::endl; std::cout << "multi-point/box closest_points tests" << std::endl; #endif using Segment = bg::model::segment; using Box = bg::model::box; using MultiPoint = bg::model::multi_point; using tester = test_geometry; tester::apply("MULTIPOINT(5 25,0 0,0 20)", "BOX(10 10,20 20)", "SEGMENT(5 25,10 20)", strategies); tester::apply("MULTIPOINT(5 25,0 0,0 20)", "BOX(10 10,20 20)", "SEGMENT(5 25,10 20)", strategies, true, true); tester::apply("MULTIPOINT(5 25,0 0,15 15)", "BOX(10 10,20 20)", "SEGMENT(15 15,15 15)", strategies); } //=========================================================================== //=========================================================================== //=========================================================================== template void test_all_pl_ar(Strategies strategies) { test_closest_points_point_polygon_or_ring(strategies); test_closest_points_point_multi_polygon(strategies); //test_closest_points_point_box(strategies); test_closest_points_multi_point_polygon_or_ring(strategies); test_closest_points_multi_point_multi_polygon(strategies); //test_closest_points_multi_point_box(strategies); test_more_empty_input_pointlike_areal(strategies); } BOOST_AUTO_TEST_CASE( test_all_pointlike_areal ) { test_all_pl_ar(cartesian()); test_all_pl_ar(spherical()); test_all_pl_ar(spherical( bg::formula::mean_radius(bg::srs::spheroid()))); test_all_pl_ar(andoyer()); test_all_pl_ar(thomas()); test_all_pl_ar(vincenty()); }