diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/geometry/test/algorithms/touches | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/geometry/test/algorithms/touches')
7 files changed, 820 insertions, 0 deletions
diff --git a/src/boost/libs/geometry/test/algorithms/touches/Jamfile.v2 b/src/boost/libs/geometry/test/algorithms/touches/Jamfile.v2 new file mode 100644 index 00000000..fcce3336 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/touches/Jamfile.v2 @@ -0,0 +1,24 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2015 Mateusz Loskot, London, UK. +# +# This file was modified by Oracle on 2014, 2015, 2016. +# Modifications copyright (c) 2014-2016, Oracle and/or its affiliates. +# +# Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle +# 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) + +test-suite boost-geometry-algorithms-touches + : + [ run touches.cpp : : : : algorithms_touches ] + [ run touches_box.cpp : : : : algorithms_touches_box ] + [ run touches_multi.cpp : : : : algorithms_touches_multi ] + [ run touches_self.cpp : : : : algorithms_touches_self ] + [ run touches_sph.cpp : : : : algorithms_touches_sph ] + ; diff --git a/src/boost/libs/geometry/test/algorithms/touches/test_touches.hpp b/src/boost/libs/geometry/test/algorithms/touches/test_touches.hpp new file mode 100644 index 00000000..fa7e39a3 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/touches/test_touches.hpp @@ -0,0 +1,142 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2013, 2015, 2016, 2017. +// Modifications copyright (c) 2013-2017 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) + +#ifndef BOOST_GEOMETRY_TEST_TOUCHES_HPP +#define BOOST_GEOMETRY_TEST_TOUCHES_HPP + + +#include <geometry_test_common.hpp> + +#include <boost/geometry/core/ring_type.hpp> +#include <boost/geometry/algorithms/touches.hpp> +#include <boost/geometry/strategies/strategies.hpp> +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +#include <boost/geometry/io/wkt/read.hpp> +#include <boost/variant/variant.hpp> + + +struct no_strategy {}; + +template <typename Geometry1, typename Geometry2, typename Strategy> +void check_touches(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& wkt1, + std::string const& wkt2, + bool expected, + Strategy const& strategy) +{ + bool detected = bg::touches(geometry1, geometry2, strategy); + + BOOST_CHECK_MESSAGE(detected == expected, + "touches: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + + detected = bg::touches(geometry2, geometry1, strategy); + + BOOST_CHECK_MESSAGE(detected == expected, + "touches: " << wkt2 + << " with " << wkt1 + << " -> Expected: " << expected + << " detected: " << detected); +} + +template <typename Geometry1, typename Geometry2> +void check_touches(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& wkt1, + std::string const& wkt2, + bool expected, + no_strategy = no_strategy()) +{ + bool detected = bg::touches(geometry1, geometry2); + + BOOST_CHECK_MESSAGE(detected == expected, + "touches: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + + detected = bg::touches(geometry2, geometry1); + + BOOST_CHECK_MESSAGE(detected == expected, + "touches: " << wkt2 + << " with " << wkt1 + << " -> Expected: " << expected + << " detected: " << detected); +} + +template <typename Geometry1, typename Geometry2> +void test_touches(std::string const& wkt1, + std::string const& wkt2, bool expected) +{ + Geometry1 geometry1; + Geometry2 geometry2; + + bg::read_wkt(wkt1, geometry1); + bg::read_wkt(wkt2, geometry2); + + boost::variant<Geometry1> v1(geometry1); + boost::variant<Geometry2> v2(geometry2); + + typedef typename bg::strategy::relate::services::default_strategy + < + Geometry1, Geometry2 + >::type strategy_type; + + check_touches(geometry1, geometry2, wkt1, wkt2, expected, no_strategy()); + check_touches(geometry1, geometry2, wkt1, wkt2, expected, strategy_type()); + check_touches(v1, geometry2, wkt1, wkt2, expected, no_strategy()); + check_touches(geometry1, v2, wkt1, wkt2, expected, no_strategy()); + check_touches(v1, v2, wkt1, wkt2, expected, no_strategy()); +} + +template <typename Geometry1, typename Geometry2> +void test_geometry(std::string const& wkt1, + std::string const& wkt2, + bool expected) +{ + test_touches<Geometry1, Geometry2>(wkt1, wkt2, expected); +} + + +template <typename Geometry> +void check_self_touches(Geometry const& geometry, + std::string const& wkt, + bool expected) +{ + bool detected = bg::touches(geometry); + + BOOST_CHECK_MESSAGE(detected == expected, + "touches: " << wkt + << " -> Expected: " << expected + << " detected: " << detected); +} + +template <typename Geometry> +void test_self_touches(std::string const& wkt, bool expected) +{ + Geometry geometry; + bg::read_wkt(wkt, geometry); + boost::variant<Geometry> v(geometry); + + check_self_touches(geometry, wkt, expected); + check_self_touches(v, wkt, expected); +} + + + +#endif diff --git a/src/boost/libs/geometry/test/algorithms/touches/touches.cpp b/src/boost/libs/geometry/test/algorithms/touches/touches.cpp new file mode 100644 index 00000000..80db2d9b --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/touches/touches.cpp @@ -0,0 +1,226 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2013, 2014. 2015. +// Modifications copyright (c) 2013-2015, 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_touches.hpp" + +template <typename P> +void test_all() +{ + typedef bg::model::multi_point<P> mpoint; + typedef bg::model::ring<P> ring; + typedef bg::model::polygon<P> polygon; + typedef bg::model::linestring<P> linestring; + typedef bg::model::multi_polygon<polygon> mpolygon; + typedef bg::model::multi_linestring<linestring> mlinestring; + + // Touching at corner + test_touches<polygon, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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, polygon> + ( + "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 + ); + + // mysql 21873343 + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 10,10 10,10 0,0 0), (0 8, 8 5, 8 8, 0 8))", + "POLYGON((0 8,-8 5,-8 8,0 8))", + true + ); + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 10,10 10,10 0,0 0), (0 6, 6 3, 6 6, 0 6))", + "POLYGON((0 6,-6 3,-6 6,0 6))", + true + ); + + // Point-Polygon + test_touches<P, ring>("POINT(40 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true); + test_touches<P, polygon>("POINT(40 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true); + test_touches<P, polygon>("POINT(60 60)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true); + test_touches<P, polygon>("POINT(50 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", false); + test_touches<P, polygon>("POINT(30 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", false); + + // Point-MultiPolygon + test_touches<P, mpolygon>("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<P, linestring>("POINT(0 0)", "LINESTRING(0 0, 2 2, 10 2)", true); + test_touches<P, linestring>("POINT(2 2)", "LINESTRING(0 0, 2 2, 10 2)", false); + test_touches<P, linestring>("POINT(1 1)", "LINESTRING(0 0, 2 2, 10 2)", false); + test_touches<P, linestring>("POINT(5 5)", "LINESTRING(0 0, 2 2, 10 2)", false); + + // Point-MultiLinestring + test_touches<P, mlinestring>("POINT(0 0)", "MULTILINESTRING((0 0, 2 2, 10 2),(5 5, 6 6))", true); + test_touches<P, mlinestring>("POINT(0 0)", "MULTILINESTRING((0 0, 2 2, 10 2),(0 0, 6 6))", false); + + // MultiPoint-Polygon + test_touches<mpoint, ring>("MULTIPOINT(40 50, 30 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", true); + test_touches<mpoint, polygon>("MULTIPOINT(40 50, 50 50)", "POLYGON((40 40,40 60,60 60,60 40,40 40))", false); + + // Linestring-Linestring + test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(0 0,0 2)", true); + test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(2 0,2 2)", true); + test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(0 2,0 0)", true); + test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(2 2,2 0)", true); + test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(0 0,0 2)", true); + test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(2 0,2 2)", true); + test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(0 2,0 0)", true); + test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(2 2,2 0)", true); + test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(1 0,1 1)", true); + test_touches<linestring, linestring>("LINESTRING(0 0,2 0)", "LINESTRING(1 1,1 0)", true); + test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(1 0,1 1)", true); + test_touches<linestring, linestring>("LINESTRING(2 0,0 0)", "LINESTRING(1 1,1 0)", true); + + test_touches<linestring, linestring>("LINESTRING(0 0,10 0)", "LINESTRING(0 0,5 5,10 0)", true); + test_touches<linestring, linestring>("LINESTRING(0 0,10 10)", "LINESTRING(0 0,0 5,10 5)", false); + + test_touches<linestring, linestring>("LINESTRING(0 5,5 6,10 5)", "LINESTRING(0 7,5 6,10 7)", false); + test_touches<linestring, linestring>("LINESTRING(0 5,5 6,10 5)", "LINESTRING(10 7,5 6,0 7)", false); + test_touches<linestring, linestring>("LINESTRING(10 5,5 6,0 5)", "LINESTRING(0 7,5 6,10 7)", false); + test_touches<linestring, linestring>("LINESTRING(10 5,5 6,0 5)", "LINESTRING(10 7,5 6,0 7)", false); + + test_touches<linestring, linestring>("LINESTRING(0 0,1 1,2 2)", "LINESTRING(2 0,2 2,1 2,1 1)", true); + test_touches<linestring, linestring>("LINESTRING(2 2,1 1,0 0)", "LINESTRING(2 0,2 2,1 2,1 1)", true); + test_touches<linestring, linestring>("LINESTRING(0 0,1 1,2 2)", "LINESTRING(1 1,1 2,2 2,2 0)", true); + test_touches<linestring, linestring>("LINESTRING(2 2,1 1,0 0)", "LINESTRING(1 1,1 2,2 2,2 0)", true); + + test_touches<linestring, linestring>("LINESTRING(0 0,1 1,0 1)", "LINESTRING(1 1,2 2,1 2,1 1)", false); + + test_touches<linestring, mlinestring>("LINESTRING(0 0,1 1,0 1)", "MULTILINESTRING((1 1,2 2),(1 2,1 1))", false); + + //Linestring-Polygon + test_touches<linestring, polygon>("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, polygon>("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, polygon>("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, ring>("LINESTRING(0 15,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_touches<linestring, polygon>("LINESTRING(0 15,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_touches<linestring, polygon>("LINESTRING(0 15,5 10,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_touches<linestring, polygon>("LINESTRING(10 15,5 10,0 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + + test_touches<linestring, polygon>("LINESTRING(0 0,3 3)", "POLYGON((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0))", true); + + test_touches<linestring, mpolygon>("LINESTRING(-1 -1,3 3)", "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)))", true); + + test_touches<mlinestring, mpolygon>("MULTILINESTRING((0 0,11 11))", "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)))", false); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<double> >(); + +#if defined(HAVE_TTMATH) + test_all<bg::model::d2::point_xy<ttmath_big> >(); +#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 +*/ diff --git a/src/boost/libs/geometry/test/algorithms/touches/touches_box.cpp b/src/boost/libs/geometry/test/algorithms/touches/touches_box.cpp new file mode 100644 index 00000000..7325bc2c --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/touches/touches_box.cpp @@ -0,0 +1,66 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2013, 2014, 2015. +// Modifications copyright (c) 2013-2015, 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_touches.hpp" + +template <typename P> +void test_all() +{ + typedef bg::model::box<P> box; + + test_touches<box, box>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((5 1,5 2,6 2,6 1,5 1))", true); + test_touches<box, box>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((4 1,4 2,5 2,5 1,4 1))", false); + test_touches<box, box>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((4 1,4 2,6 2,6 1,4 1))", false); + + // Point-size + test_touches<box, box>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((5 5,5 5,5 5,5 5,5 5))", true); + // TODO: should it be TRUE? + test_touches<box, box>("POLYGON((5 5,5 5,5 5,5 5,5 5))", "POLYGON((5 5,5 5,5 5,5 5,5 5))", true); +} + +template <typename P> +void test_box_3d() +{ + typedef bg::model::box<P> box; + + check_touches<box, box>(box(P(0,0,0),P(5,5,5)), box(P(5,1,2),P(6,6,6)), + "box(P(0,0,0),P(5,5,5))", "box(P(5,1,2),P(6,6,6))", + true); + + check_touches<box, box>(box(P(0,0,0),P(5,5,5)), box(P(5,5,5),P(6,6,6)), + "box(P(0,0,0),P(5,5,5))", "box(P(5,5,5),P(6,6,6))", + true); +} + + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<double> >(); + test_box_3d<bg::model::point<double, 3, bg::cs::cartesian> >(); + +#if defined(HAVE_TTMATH) + test_all<bg::model::d2::point_xy<ttmath_big> >(); +#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 +*/ diff --git a/src/boost/libs/geometry/test/algorithms/touches/touches_multi.cpp b/src/boost/libs/geometry/test/algorithms/touches/touches_multi.cpp new file mode 100644 index 00000000..65de6b52 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/touches/touches_multi.cpp @@ -0,0 +1,80 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2010-2015 Barend Gehrels, Amsterdam, the Netherlands. +// 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_touches.hpp" + +#include <boost/geometry/algorithms/area.hpp> +#include <boost/geometry/algorithms/num_geometries.hpp> +#include <boost/geometry/algorithms/within.hpp> + + +template <typename P> +void test_all() +{ + typedef bg::model::polygon<P> polygon; + typedef bg::model::multi_polygon<polygon> mp; + typedef bg::model::linestring<P> linestring; + typedef bg::model::multi_linestring<linestring> ml; + + test_self_touches<mp>("MULTIPOLYGON(((0 0,0 100,100 100,100 0,0 0)))", + false); + + // Exactly equal + test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 100,100 100,100 0,0 0)))", + "MULTIPOLYGON(((0 0,0 100,100 100,100 0,0 0)))", + false); + + // Spatially equal + test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 100,100 100,100 0,0 0)))", + "MULTIPOLYGON(((0 0,0 100,100 100,100 80,100 20,100 0,0 0)))", + false); + + // One exactly equal, another pair touching + test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((30 10,30 20,40 20,40 10,30 10)))", + false); + + // One spatially equal (without equal segments), another pair touching + test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 5,0 10,5 10,10 10,10 5,10 0,5 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((30 10,30 20,40 20,40 10,30 10)))", + false); + + // Alternate touches + test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTIPOLYGON(((10 10,10 20,20 20,20 10,10 10)),((30 10,30 20,40 20,40 10,30 10)))", + true); + + // Touch plus inside + test_touches<mp, mp>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTIPOLYGON(((10 10,10 20,20 20,20 10,10 10)),((22 2,28 2,28 8,22 8,22 2)))", + false); + + + test_touches<mp, ml>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTILINESTRING((10 10,10 20,20 20,20 10,10 10),(30 10,30 20,40 20,40 10,30 10))", + true); + + test_touches<mp, ml>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTILINESTRING((10 10,10 20,20 20,20 10,10 10),(22 2,28 2,28 8,22 8,22 2))", + false); + + test_touches<mp, ml>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTILINESTRING((10 10,10 20,20 20,20 10,10 10),(50 2,60 2,60 8,50 8,50 2))", + true); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<double> >(); + +#ifdef HAVE_TTMATH + test_all<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + return 0; +} diff --git a/src/boost/libs/geometry/test/algorithms/touches/touches_self.cpp b/src/boost/libs/geometry/test/algorithms/touches/touches_self.cpp new file mode 100644 index 00000000..00ea47da --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/touches/touches_self.cpp @@ -0,0 +1,43 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2013, 2014. 2015. +// Modifications copyright (c) 2013-2015, 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_touches.hpp" + +template <typename P> +void test_all() +{ + typedef bg::model::polygon<P> polygon; + + // Just a normal polygon + test_self_touches<polygon>("POLYGON((0 0,0 4,1.5 2.5,2.5 1.5,4 0,0 0))", false); + + // Self intersecting + test_self_touches<polygon>("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>("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>("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); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<double> >(); + +#if defined(HAVE_TTMATH) + test_all<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + return 0; +} diff --git a/src/boost/libs/geometry/test/algorithms/touches/touches_sph.cpp b/src/boost/libs/geometry/test/algorithms/touches/touches_sph.cpp new file mode 100644 index 00000000..352a9bff --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/touches/touches_sph.cpp @@ -0,0 +1,239 @@ +// Boost.Geometry + +// Copyright (c) 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_touches.hpp" + +#include <algorithms/overlay/overlay_cases.hpp> +#include <algorithms/overlay/multi_overlay_cases.hpp> + +#include <boost/geometry/geometries/geometries.hpp> + + +template <typename P> +void test_polygon_polygon() +{ + typedef bg::model::polygon<P> poly; + typedef bg::model::ring<P> ring; + + test_geometry<ring, ring>(case_1[0], case_1[1], + false); + test_geometry<ring, poly>(case_1[0], case_1[1], + false); + + test_geometry<poly, poly>(case_1[0], case_1[1], + false); + test_geometry<poly, poly>(case_2[0], case_2[1], + false); + test_geometry<poly, poly>(case_3_sph[0], case_3_sph[1], + false); + test_geometry<poly, poly>(case_3_2_sph[0], case_3_2_sph[1], + false); + test_geometry<poly, poly>(case_4[0], case_4[1], + false); + test_geometry<poly, poly>(case_5[0], case_5[1], + false); + test_geometry<poly, poly>(case_6_sph[0], case_6_sph[1], + false); + + test_geometry<poly, poly>(case_7[0], case_7[1], + true); + test_geometry<poly, poly>(case_8_sph[0], case_8_sph[1], + true); + test_geometry<poly, poly>(case_9_sph[0], case_9_sph[1], + true); + test_geometry<poly, poly>(case_10_sph[0], case_10_sph[1], + true); + test_geometry<poly, poly>(case_11_sph[0], case_11_sph[1], + false); + test_geometry<poly, poly>(case_12[0], case_12[1], + false); + + test_geometry<poly, poly>(case_13_sph[0], case_13_sph[1], + true); + test_geometry<poly, poly>(case_14_sph[0], case_14_sph[1], + true); + test_geometry<poly, poly>(case_15_sph[0], case_15_sph[1], + true); + test_geometry<poly, poly>(case_16_sph[0], case_16_sph[1], + true); + test_geometry<poly, poly>(case_17_sph[0], case_17_sph[1], + false); + test_geometry<poly, poly>(case_18_sph[0], case_18_sph[1], + false); +} + +template <typename P> +void test_polygon_multi_polygon() +{ + typedef bg::model::polygon<P> poly; + typedef bg::model::ring<P> ring; + typedef bg::model::multi_polygon<poly> mpoly; + + test_geometry<ring, mpoly>(case_1[0], case_multi_2[0], + false); + test_geometry<poly, mpoly>(case_2[0], case_multi_2[0], + false); +} + +template <typename P> +void test_multi_polygon_multi_polygon() +{ + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + test_geometry<mpoly, mpoly>(case_multi_2[0], case_multi_2[1], + false); +} + +template <typename P> +void test_linestring_polygon() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::polygon<P> poly; + typedef bg::model::polygon<P> ring; + + test_geometry<ls, poly>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_geometry<ls, ring>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_geometry<ls, poly>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_geometry<ls, poly>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_geometry<ls, poly>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + + test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))", + false); + + test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9,1 9,1 1,9 1)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))", + false); + + test_geometry<ls, poly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + true); +} + +template <typename P> +void test_linestring_multi_polygon() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,10 9)", + "MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)))", + true); +} + +template <typename P> +void test_multi_linestring_polygon() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::polygon<P> poly; + typedef bg::model::ring<P> ring; + typedef bg::model::multi_linestring<ls> mls; + + test_geometry<mls, poly>("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))", + false); + + test_geometry<mls, ring>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))", + "POLYGON((5 5,5 15,15 15,15 5,5 5))", + false); + + test_geometry<mls, poly>("MULTILINESTRING((3 10.031432746397092, 1 5, 1 10.013467818052765, 3 4, 7 8, 6 10.035925377760330, 10 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + false); +} + +template <typename P> +void test_multi_linestring_multi_polygon() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::multi_polygon<poly> mpoly; + + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10,0 10,0 0),(2 2,5 5,2 8,2 2))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2)))", + true); + + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10),(10 10,0 10,0 0),(20 20,50 50,20 80,20 20))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + true); + + test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(5 -2,6 -2,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + false); +} + +template <typename P> +void test_linestring_linestring() +{ + typedef bg::model::linestring<P> ls; + + test_geometry<ls, ls>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", false); + + test_geometry<ls, ls>("LINESTRING(1 0,2 2,2 3)", "LINESTRING(0 0, 2 2, 3 2)", false); +} + +template <typename P> +void test_linestring_multi_linestring() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + + test_geometry<ls, mls>("LINESTRING(0 0,10 0)", + "MULTILINESTRING((1 0,2 0),(1 1,2 1))", + false); + + test_geometry<ls, mls>("LINESTRING(0 0,5 0,5 5,0 5,0 0)", + "MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5))", + false); +} + +template <typename P> +void test_multi_linestring_multi_linestring() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + + test_geometry<mls, mls>("MULTILINESTRING((0 0,0 0,18 0,18 0,19 0,19 0,19 0,30 0,30 0))", + "MULTILINESTRING((0 10,5 0,20 0,20 0,30 0))", + false); +} + + +template <typename P> +void test_all() +{ + test_polygon_polygon<P>(); + test_polygon_multi_polygon<P>(); + test_multi_polygon_multi_polygon<P>(); + + test_linestring_polygon<P>(); + test_linestring_multi_polygon<P>(); + test_multi_linestring_polygon<P>(); + test_multi_linestring_multi_polygon<P>(); + + test_linestring_linestring<P>(); + test_linestring_multi_linestring<P>(); + test_multi_linestring_multi_linestring<P>(); +} + + +int test_main( int , char* [] ) +{ + test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >(); + +#if defined(HAVE_TTMATH) + test_cs<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >(); +#endif + + return 0; +} |