// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland. // This file was modified by Oracle on 2013, 2015, 2016. // Modifications copyright (c) 2013-2016, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include "test_intersects.hpp" #include #include #include template void test_intersects_polygon_polygon() { typedef bg::model::polygon poly_ccw_o1; typedef bg::model::polygon poly_ccw_o2; test_geometry("POLYGON((1 1, 3 3, 2 5))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true); test_geometry("POLYGON((6 6, 7 6, 7 7, 6 7))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", false); test_geometry("POLYGON((7 7, 9 7, 9 9, 7 9))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true); } template void test_intersects_linestring_segment() { typedef bg::model::linestring ls; typedef bg::model::segment seg; test_geometry("LINESTRING(1 1, 3 3, 2 5)", "SEGMENT(2 0, 2 6)", true); test_geometry("LINESTRING(1 1, 3 3)", "SEGMENT(1 0, 1 1)", true); test_geometry("LINESTRING(1 1, 3 3)", "SEGMENT(2 0, 2 2)", true); test_geometry("LINESTRING(1 1, 3 3)", "SEGMENT(3 0, 4 1)", false); } template void test_intersects_linestring_linestring() { typedef bg::model::linestring ls1; typedef bg::model::linestring ls2; test_geometry("LINESTRING(0 0,2 0,3 0)", "LINESTRING(0 0,1 1,2 2)", true); test_geometry("LINESTRING(0 0,2 0,3 0)", "LINESTRING(2 2,1 1,0 0)", true); test_geometry("LINESTRING(3 0,2 0,0 0)", "LINESTRING(0 0,1 1,2 2)", true); test_geometry("LINESTRING(3 0,2 0,0 0)", "LINESTRING(2 2,1 1,0 0)", true); test_geometry("LINESTRING(0 0,2 0,3 0)", "LINESTRING(1 0,4 0,5 0)", true); test_geometry("LINESTRING(1 0,2 0)", "LINESTRING(1 0,0 0)", true); } template void test_intersects_linestring_polygon() { typedef bg::model::linestring ls; typedef bg::model::multi_linestring mls; typedef bg::model::polygon poly_cw_c; typedef bg::model::polygon poly_ccw_c; typedef bg::model::polygon poly_ccw_o; typedef bg::model::multi_polygon mpoly_ccw_c; test_geometry("LINESTRING(1 1,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); test_geometry("LINESTRING(1 0,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); test_geometry("LINESTRING(11 0,12 12)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", false); test_geometry("LINESTRING(1 1, 3 3, 2 5)", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true); test_geometry("LINESTRING(6 6, 7 6, 7 7, 6 7)", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", false); test_geometry("LINESTRING(7 7, 9 7, 9 9, 7 9)", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true); test_geometry("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(-2 -2, 12 7)", true); test_geometry("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(5 5, 15 4)", true); test_geometry("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(7 6, 15 4)", true); test_geometry("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(6 2, 12 1)", true); // MULTI test_geometry("LINESTRING(1 1,2 2)", "MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)))", true); test_geometry("MULTILINESTRING((1 1,2 2))", "MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)))", true); } template void test_intersects_linestring_ring() { typedef bg::model::linestring ls; typedef bg::model::multi_linestring mls; typedef bg::model::ring ring_ccw_c; test_geometry("LINESTRING(1 1,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); test_geometry("LINESTRING(1 0,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); test_geometry("LINESTRING(11 0,12 12)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", false); // MULTI test_geometry("MULTILINESTRING((1 1,2 2))", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); } template void test_intersects_ring_polygon() { typedef bg::model::ring ring_ccw_o; typedef bg::model::polygon poly_ccw_o; test_geometry("POLYGON((1 1, 3 3, 2 5))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true); test_geometry("POLYGON((6 6, 7 6, 7 7, 6 7))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", false); test_geometry("POLYGON((7 7, 9 7, 9 9, 7 9))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", true); test_geometry("POLYGON((6 6,7 6,7 7,6 7))", "POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,5 8,8 8,8 5))", false); } template void test_intersects_point_linestring() { typedef bg::model::linestring ls; typedef bg::model::multi_linestring mls; test_geometry("POINT(0 0)", "LINESTRING(0 0,2 2,4 0)", true); test_geometry("POINT(1 1)", "LINESTRING(0 0,2 2,4 0)", true); test_geometry("POINT(1 0)", "LINESTRING(0 0,2 2,4 0)", false); // MULTI test_geometry("POINT(0 0)", "MULTILINESTRING((0 0,2 2,4 0))", true); } template void test_intersects_point_segment() { typedef bg::model::segment seg; test_geometry("POINT(0 0)", "LINESTRING(0 0,2 2)", true); test_geometry("POINT(1 1)", "LINESTRING(0 0,2 2)", true); test_geometry("POINT(1 0)", "LINESTRING(0 0,2 2)", false); } template void test_multi_linestring_polygon() { typedef bg::model::linestring ls; typedef bg::model::multi_linestring mls; typedef bg::model::polygon poly; test_geometry("MULTILINESTRING((11 11, 20 20),(5 7, 4 1))", "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))", true); test_geometry("MULTILINESTRING((10 0, 18 12),(2 2,2 1))", "POLYGON((5 0,0 -5,-5 0,0 5,5 0))", true); } template void test_multi_polygon_polygon() { typedef bg::model::polygon poly1; typedef bg::model::multi_polygon mpoly; typedef bg::model::polygon poly2; test_geometry("MULTIPOLYGON(((11 11,11 20,20 20,20 11,11 11)),((5 5,5 6,6 6,6 5,5 5)))", "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))", true); } template void test_point_polygon() { typedef bg::model::ring ring; typedef bg::model::polygon poly; test_geometry( "POINT(0 0)", "POLYGON((0 0,3 3,3 3,4 1))", true); test_geometry( "POINT(0 0)", "POLYGON((0 0,3 3,3 3,4 1))", true); test_geometry( "POLYGON((0 0,3 3,3 3,4 1))", "POINT(0 0)", true); test_geometry( "POLYGON((0 0,3 3,3 3,4 1))", "POINT(0 0)", true); } template void test_all() { test_intersects_point_segment(); test_intersects_point_linestring(); test_intersects_polygon_polygon(); test_intersects_linestring_polygon(); test_intersects_linestring_ring(); test_intersects_linestring_segment(); test_intersects_linestring_linestring(); test_intersects_ring_polygon(); test_multi_linestring_polygon(); test_multi_polygon_polygon(); test_point_polygon(); } template void test_all() { test_all(); } int test_main( int , char* [] ) { test_all >(); test_all, bg::model::point >(); #if ! defined(BOOST_GEOMETRY_RESCALE_TO_ROBUST) test_all > >(); #endif return 0; }