diff options
Diffstat (limited to 'src/boost/libs/geometry/test/algorithms/overlaps')
6 files changed, 472 insertions, 0 deletions
diff --git a/src/boost/libs/geometry/test/algorithms/overlaps/Jamfile.v2 b/src/boost/libs/geometry/test/algorithms/overlaps/Jamfile.v2 new file mode 100644 index 00000000..ec744c76 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/overlaps/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-overlaps + : + [ run overlaps.cpp : : : : algorithms_overlaps ] + [ run overlaps_areal.cpp : : : : algorithms_overlaps_areal ] + [ run overlaps_box.cpp : : : : algorithms_overlaps_box ] + [ run overlaps_sph.cpp : : : : algorithms_overlaps_sph ] + ; + diff --git a/src/boost/libs/geometry/test/algorithms/overlaps/overlaps.cpp b/src/boost/libs/geometry/test/algorithms/overlaps/overlaps.cpp new file mode 100644 index 00000000..b305edb5 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/overlaps/overlaps.cpp @@ -0,0 +1,63 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014, 2015, 2017. +// Modifications copyright (c) 2014-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) + +#include "test_overlaps.hpp" + +template <typename P> +void test_pp() +{ + typedef bg::model::multi_point<P> mpt; + + test_geometry<P, P>("POINT(0 0)", "POINT(0 0)", false); + test_geometry<P, P>("POINT(0 0)", "POINT(1 1)", false); + + test_geometry<P, mpt>("POINT(0 0)", "MULTIPOINT(0 0, 1 1)", false); + + test_geometry<mpt, P>("MULTIPOINT(0 0, 1 1)", "POINT(0 0)", false); + + test_geometry<mpt, mpt>("MULTIPOINT(0 0,1 1,2 2)", "MULTIPOINT(1 1,3 3,4 4)", true); + test_geometry<mpt, mpt>("MULTIPOINT(0 0,1 1,2 2)", "MULTIPOINT(1 1,2 2)", false); +} + +template <typename P> +void test_ll() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 1)", "LINESTRING(1 1,2 2,4 4)", true); + test_geometry<ls, ls>("LINESTRING(0 0,2 2,4 0)", "LINESTRING(0 1,2 1,3 2)", false); + + test_geometry<ls, mls>("LINESTRING(0 0,2 2,3 1)", "MULTILINESTRING((1 1,2 2),(2 2,4 4))", true); + test_geometry<ls, mls>("LINESTRING(0 0,2 2,3 1)", "MULTILINESTRING((1 1,2 2),(3 3,4 4))", true); + test_geometry<ls, mls>("LINESTRING(0 0,3 3,3 1)", "MULTILINESTRING((3 3,2 2),(0 0,1 1))", false); +} + +template <typename P> +void test_2d() +{ + test_pp<P>(); + test_ll<P>(); +} + +int test_main( int , char* [] ) +{ + test_2d<bg::model::d2::point_xy<int> >(); + test_2d<bg::model::d2::point_xy<double> >(); + +#if defined(HAVE_TTMATH) + test_2d<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + return 0; +} diff --git a/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_areal.cpp b/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_areal.cpp new file mode 100644 index 00000000..c7361f20 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_areal.cpp @@ -0,0 +1,73 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014, 2015. +// Modifications copyright (c) 2014-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_overlaps.hpp" + +template <typename P> +void test_aa() +{ + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + test_geometry<poly, poly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((3 3,3 9,9 9,9 3,3 3))", true); + test_geometry<poly, poly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((5 5,5 9,9 9,9 5,5 5))", false); + test_geometry<poly, poly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((3 3,3 5,5 5,5 3,3 3))", false); + + test_geometry<poly, mpoly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", + "MULTIPOLYGON(((3 3,3 5,5 5,5 3,3 3)),((5 5,5 6,6 6,6 5,5 5)))", + true); + test_geometry<mpoly, mpoly>("MULTIPOLYGON(((3 3,3 5,5 5,5 3,3 3)),((0 0,0 3,3 3,3 0,0,0)))", + "MULTIPOLYGON(((3 3,3 5,5 5,5 3,3 3)),((5 5,5 6,6 6,6 5,5 5)))", + true); + + // related to https://svn.boost.org/trac/boost/ticket/10912 + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))", + "POLYGON((3 3,3 9,9 9,9 3,3 3))", + true); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2),(6 6,8 6,8 8,6 8,6 6))", + "POLYGON((0 0,0 5,5 5,5 0,0 0))", + true); + + test_geometry<mpoly, poly>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "POLYGON((0 0,0 5,5 5,5 0,0 0))", + false); + test_geometry<mpoly, poly>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + false); + + // mysql 21872795 + test_geometry<poly, poly>("POLYGON((2 2,2 8,8 8,8 2,2 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(8 8,4 6,4 4,8 8))", + true); + test_geometry<poly, poly>("POLYGON((2 2,2 8,8 8,8 2,2 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 4,4 6,2 2))", + true); +} + +template <typename P> +void test_2d() +{ + test_aa<P>(); +} + +int test_main( int , char* [] ) +{ + test_2d<bg::model::d2::point_xy<int> >(); + test_2d<bg::model::d2::point_xy<double> >(); + +#if defined(HAVE_TTMATH) + test_2d<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + return 0; +} diff --git a/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_box.cpp b/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_box.cpp new file mode 100644 index 00000000..b58cfa96 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_box.cpp @@ -0,0 +1,65 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014, 2015. +// Modifications copyright (c) 2014-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_overlaps.hpp" + +template <typename P> +void test_box_box_2d() +{ +#if defined(BOOST_GEOMETRY_COMPILE_FAIL) + test_geometry<P, P>("POINT(1 1)", "POINT(1 1)", true); +#endif + + test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1, 3 3)", "BOX(0 0,2 2)", true); + + // touch -> false + test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1, 3 3)", "BOX(3 3,5 5)", false); + + // disjoint -> false + test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1, 3 3)", "BOX(4 4,6 6)", false); + + // within -> false + test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1, 5 5)", "BOX(2 2,3 3)", false); + + // within+touch -> false + test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1, 5 5)", "BOX(2 2,5 5)", false); +} + +template <typename P> +void test_3d() +{ + test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1 1, 3 3 3)", "BOX(0 0 0,2 2 2)", true); + test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1 1, 3 3 3)", "BOX(3 3 3,5 5 5)", false); + test_geometry<bg::model::box<P>, bg::model::box<P> >("BOX(1 1 1, 3 3 3)", "BOX(4 4 4,6 6 6)", false); +} + + +template <typename P> +void test_2d() +{ + test_box_box_2d<P>(); +} + +int test_main( int , char* [] ) +{ + test_2d<bg::model::d2::point_xy<int> >(); + test_2d<bg::model::d2::point_xy<double> >(); + +#if defined(HAVE_TTMATH) + test_2d<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + //test_3d<bg::model::point<double, 3, bg::cs::cartesian> >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_sph.cpp b/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_sph.cpp new file mode 100644 index 00000000..79478ad3 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/overlaps/overlaps_sph.cpp @@ -0,0 +1,153 @@ +// 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_overlaps.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], + true); + test_geometry<ring, poly>(case_1[0], case_1[1], + true); + + test_geometry<poly, poly>(case_1[0], case_1[1], + true); + test_geometry<poly, poly>(case_2[0], case_2[1], + true); + 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], + true); + test_geometry<poly, poly>(case_5[0], case_5[1], + true); + test_geometry<poly, poly>(case_6_sph[0], case_6_sph[1], + false); + + test_geometry<poly, poly>(case_7[0], case_7[1], + false); + test_geometry<poly, poly>(case_8_sph[0], case_8_sph[1], + false); + test_geometry<poly, poly>(case_9_sph[0], case_9_sph[1], + false); + test_geometry<poly, poly>(case_10_sph[0], case_10_sph[1], + false); + test_geometry<poly, poly>(case_11_sph[0], case_11_sph[1], + false); + test_geometry<poly, poly>(case_12[0], case_12[1], + true); + + test_geometry<poly, poly>(case_13_sph[0], case_13_sph[1], + false); + test_geometry<poly, poly>(case_14_sph[0], case_14_sph[1], + false); + test_geometry<poly, poly>(case_15_sph[0], case_15_sph[1], + false); + test_geometry<poly, poly>(case_16_sph[0], case_16_sph[1], + false); + 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], + true); + test_geometry<poly, mpoly>(case_2[0], case_multi_2[0], + true); +} + +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], + true); +} + +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))", + true); + + 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))", + true); +} + + +template <typename P> +void test_all() +{ + test_polygon_polygon<P>(); + test_polygon_multi_polygon<P>(); + test_multi_polygon_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; +} diff --git a/src/boost/libs/geometry/test/algorithms/overlaps/test_overlaps.hpp b/src/boost/libs/geometry/test/algorithms/overlaps/test_overlaps.hpp new file mode 100644 index 00000000..7d668698 --- /dev/null +++ b/src/boost/libs/geometry/test/algorithms/overlaps/test_overlaps.hpp @@ -0,0 +1,94 @@ +// Generic Geometry2 Library +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2015, 2017. +// Modifications copyright (c) 2015-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_OVERLAPS_HPP +#define BOOST_GEOMETRY_TEST_OVERLAPS_HPP + + +#include <geometry_test_common.hpp> + +#include <boost/geometry/core/ring_type.hpp> +#include <boost/geometry/algorithms/overlaps.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> + + +struct no_strategy {}; + +template <typename Geometry1, typename Geometry2, typename Strategy> +bool call_overlaps(Geometry1 const& geometry1, + Geometry2 const& geometry2, + Strategy const& strategy) +{ + return bg::overlaps(geometry1, geometry2, strategy); +} + +template <typename Geometry1, typename Geometry2> +bool call_overlaps(Geometry1 const& geometry1, + Geometry2 const& geometry2, + no_strategy) +{ + return bg::overlaps(geometry1, geometry2); +} + +template <typename Geometry1, typename Geometry2, typename Strategy> +void test_geometry(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& wkt1, + std::string const& wkt2, + bool expected, + Strategy const& strategy) +{ + bool detected = call_overlaps(geometry1, geometry2, strategy); + + BOOST_CHECK_MESSAGE(detected == expected, + "overlaps: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + + detected = call_overlaps(geometry2, geometry1, strategy); + + BOOST_CHECK_MESSAGE(detected == expected, + "overlaps: " << wkt2 + << " with " << wkt1 + << " -> Expected: " << expected + << " detected: " << detected); +} + +template <typename Geometry1, typename Geometry2> +void test_geometry(std::string const& wkt1, + std::string const& wkt2, + bool expected) +{ + Geometry1 geometry1; + Geometry2 geometry2; + + bg::read_wkt(wkt1, geometry1); + bg::read_wkt(wkt2, geometry2); + + test_geometry(geometry1, geometry2, wkt1, wkt2, expected, no_strategy()); + + typedef typename bg::strategy::relate::services::default_strategy + < + Geometry1, Geometry2 + >::type strategy_type; + + test_geometry(geometry1, geometry2, wkt1, wkt2, expected, strategy_type()); +} + + +#endif |