// Boost.Geometry (aka GGL, Generic Geometry Library) // // Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands. // This file was modified by Oracle on 2013. // Modifications copyright (c) 2013, Oracle and/or its affiliates. // 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 #include #include template void test_all() { typedef bg::model::polygon

polygon; typedef bg::model::linestring

linestring; typedef bg::model::multi_polygon mpolygon; typedef bg::model::multi_linestring mlinestring; // Just a normal polygon test_self_touches("POLYGON((0 0,0 4,1.5 2.5,2.5 1.5,4 0,0 0))", false); // Self intersecting test_self_touches("POLYGON((1 2,1 1,2 1,2 2.25,3 2.25,3 0,0 0,0 3,3 3,2.75 2,1 2))", false); // Self touching at a point test_self_touches("POLYGON((0 0,0 3,2 3,2 2,1 2,1 1,2 1,2 2,3 2,3 0,0 0))", true); // Self touching at a segment test_self_touches("POLYGON((0 0,0 3,2 3,2 2,1 2,1 1,2 1,2 2.5,3 2.5,3 0,0 0))", true); // Touching at corner test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((100 100,100 200,200 200, 200 100,100 100))", true ); // Intersecting at corner test_touches ( "POLYGON((0 0,0 100,101 101,100 0,0 0))", "POLYGON((100 100,100 200,200 200, 200 100,100 100))", false ); // Touching at side (interior of a segment) test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((200 0,100 50,200 100,200 0))", true ); // Touching at side (partly collinear) test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((200 20,100 20,100 80,200 80,200 20))", true ); // Completely equal test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((0 0,0 100,100 100,100 0,0 0))", false ); // Spatially equal test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((0 0,0 100,100 100,100 80,100 20,100 0,0 0))", false ); // Spatially equal (without equal segments) test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((0 0,0 50,0 100,50 100,100 100,100 50,100 0,50 0,0 0))", false ); // Touching at side (opposite equal) test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((200 0,100 0,100 100,200 100,200 0))", true ); // Touching at side (opposite equal - but with real "equal" turning point) test_touches ( "POLYGON((0 0,0 100,100 100,100 80,100 20,100 0,0 0))", "POLYGON((200 0,100 0,100 20,100 80,100 100,200 100,200 0))", true ); // First partly collinear to side, than overlapping test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((200 20,100 20,100 50,50 50,50 80,100 80,200 80,200 20))", false ); // Touching interior (= no touch) test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0))", "POLYGON((20 20,20 80,100 50,20 20))", false ); // Fitting in hole test_touches ( "POLYGON((0 0,0 100,100 100,100 0,0 0),(40 40,60 40,60 60,40 60,40 40))", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true ); // Point-Polygon test_touches("POINT(40 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true); test_touches("POINT(60 60)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true); test_touches("POINT(50 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", false); test_touches("POINT(30 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", false); // Point-MultiPolygon test_touches("POINT(40 50)", "MULTIPOLYGON(((40 40,40 60,60 60,60 40,40 40)),((0 0,0 10,10 10,10 0)))", true); // Point-Linestring test_touches("POINT(0 0)", "LINESTRING(0 0, 2 2, 10 2)", true); test_touches("POINT(2 2)", "LINESTRING(0 0, 2 2, 10 2)", false); test_touches("POINT(1 1)", "LINESTRING(0 0, 2 2, 10 2)", false); test_touches("POINT(5 5)", "LINESTRING(0 0, 2 2, 10 2)", false); // Point-MultiLinestring test_touches("POINT(0 0)", "MULTILINESTRING((0 0, 2 2, 10 2),(5 5, 6 6))", true); test_touches("POINT(0 0)", "MULTILINESTRING((0 0, 2 2, 10 2),(0 0, 6 6))", false); // Linestring-Linestring test_touches("LINESTRING(0 0,2 0)", "LINESTRING(0 0,0 2)", true); test_touches("LINESTRING(0 0,2 0)", "LINESTRING(2 0,2 2)", true); test_touches("LINESTRING(0 0,2 0)", "LINESTRING(0 2,0 0)", true); test_touches("LINESTRING(0 0,2 0)", "LINESTRING(2 2,2 0)", true); test_touches("LINESTRING(2 0,0 0)", "LINESTRING(0 0,0 2)", true); test_touches("LINESTRING(2 0,0 0)", "LINESTRING(2 0,2 2)", true); test_touches("LINESTRING(2 0,0 0)", "LINESTRING(0 2,0 0)", true); test_touches("LINESTRING(2 0,0 0)", "LINESTRING(2 2,2 0)", true); test_touches("LINESTRING(0 0,2 0)", "LINESTRING(1 0,1 1)", true); test_touches("LINESTRING(0 0,2 0)", "LINESTRING(1 1,1 0)", true); test_touches("LINESTRING(2 0,0 0)", "LINESTRING(1 0,1 1)", true); test_touches("LINESTRING(2 0,0 0)", "LINESTRING(1 1,1 0)", true); test_touches("LINESTRING(0 0,10 0)", "LINESTRING(0 0,5 5,10 0)", true); test_touches("LINESTRING(0 0,10 10)", "LINESTRING(0 0,0 5,10 5)", false); test_touches("LINESTRING(0 5,5 6,10 5)", "LINESTRING(0 7,5 6,10 7)", false); test_touches("LINESTRING(0 5,5 6,10 5)", "LINESTRING(10 7,5 6,0 7)", false); test_touches("LINESTRING(10 5,5 6,0 5)", "LINESTRING(0 7,5 6,10 7)", false); test_touches("LINESTRING(10 5,5 6,0 5)", "LINESTRING(10 7,5 6,0 7)", false); test_touches("LINESTRING(0 0,1 1,2 2)", "LINESTRING(2 0,2 2,1 2,1 1)", true); test_touches("LINESTRING(2 2,1 1,0 0)", "LINESTRING(2 0,2 2,1 2,1 1)", true); test_touches("LINESTRING(0 0,1 1,2 2)", "LINESTRING(1 1,1 2,2 2,2 0)", true); test_touches("LINESTRING(2 2,1 1,0 0)", "LINESTRING(1 1,1 2,2 2,2 0)", true); //Linestring-Polygon test_touches("LINESTRING(10 0,15 5,10 10,5 15,5 10,0 10,5 15,5 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true); test_touches("LINESTRING(5 10,5 15,0 10,5 10,5 15,10 10,15 5,10 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", true); test_touches("LINESTRING(5 10,5 15,0 10,5 10,5 15,10 10,5 5,10 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); test_touches("LINESTRING(0 15,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); test_touches("LINESTRING(0 15,5 10,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); test_touches("LINESTRING(10 15,5 10,0 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); } int test_main( int , char* [] ) { test_all >(); #if defined(HAVE_TTMATH) test_all >(); #endif return 0; } /* with viewy as ( select geometry::STGeomFromText('POLYGON((0 0,0 100,100 100,100 0,0 0))',0) as p , geometry::STGeomFromText('POLYGON((200 0,100 50,200 100,200 0))',0) as q ) -- select p from viewy union all select q from viewy select p.STTouches(q) from viewy */