diff options
Diffstat (limited to 'libs/geometry/test/algorithms/relational_operations')
36 files changed, 6877 insertions, 0 deletions
diff --git a/libs/geometry/test/algorithms/relational_operations/Jamfile.v2 b/libs/geometry/test/algorithms/relational_operations/Jamfile.v2 new file mode 100644 index 000000000..2c0c34c9e --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/Jamfile.v2 @@ -0,0 +1,33 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +# +# This file was modified by Oracle on 2014. +# Modifications copyright (c) 2014, 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-relational + : + [ run covered_by.cpp ] + [ run crosses.cpp ] + [ run equals.cpp ] + [ run intersects.cpp ] + [ run multi_covered_by.cpp ] + [ run multi_equals.cpp ] + [ run multi_intersects.cpp ] + [ run multi_touches.cpp ] + [ run overlaps.cpp ] + [ run touches.cpp ] + ; + +build-project disjoint ; +build-project relate ; +build-project within ; diff --git a/libs/geometry/test/algorithms/relational_operations/covered_by.cpp b/libs/geometry/test/algorithms/relational_operations/covered_by.cpp new file mode 100644 index 000000000..15031487a --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/covered_by.cpp @@ -0,0 +1,152 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// 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_covered_by.hpp" + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + + +template <typename P> +void test_all() +{ + /* + // trivial case + test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true, false); + + // on border/corner + test_ring<P>("POINT(0 0)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true); + test_ring<P>("POINT(0 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true); + + // aligned to segment/vertex + test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", true, false); + test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", true, false); + + // same polygon, but point on border + test_ring<P>("POINT(3 3)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", false, true); + test_ring<P>("POINT(3 3)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", false, true); + + // holes + test_geometry<P, bg::model::polygon<P> >("POINT(2 2)", + "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1))", false); + + */ + + typedef bg::model::segment<P> seg; + test_geometry<P, seg>("POINT(1 1)", "LINESTRING(0 0, 2 2)", true); + test_geometry<P, seg>("POINT(0 0)", "LINESTRING(0 0, 1 1)", true); + test_geometry<P, seg>("POINT(1 0)", "LINESTRING(0 0, 1 1)", false); + + // linestrings + typedef bg::model::linestring<P> ls; + test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0,1 1,2 2)", true); + test_geometry<P, ls>("POINT(3 3)", "LINESTRING(0 0,1 1,2 2)", false); + test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0,2 2,3 3)", true); + + // multi_linestrings + typedef bg::model::multi_linestring<ls> mls; + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1))", true); + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1),(0 0,1 0))", true); + + typedef bg::model::box<P> box_type; + + test_geometry<P, box_type>("POINT(1 1)", "BOX(0 0,2 2)", true); + test_geometry<P, box_type>("POINT(0 0)", "BOX(0 0,2 2)", true); + test_geometry<P, box_type>("POINT(2 2)", "BOX(0 0,2 2)", true); + test_geometry<P, box_type>("POINT(0 1)", "BOX(0 0,2 2)", true); + test_geometry<P, box_type>("POINT(1 0)", "BOX(0 0,2 2)", true); + test_geometry<P, box_type>("POINT(3 3)", "BOX(0 0,2 2)", false); + + test_geometry<box_type, box_type>("BOX(1 1,2 2)", "BOX(0 0,3 3)", true); + test_geometry<box_type, box_type>("BOX(0 0,3 3)", "BOX(1 1,2 2)", false); + test_geometry<box_type, box_type>("BOX(0 0,2 2)", "BOX(0 0,3 3)", true); + test_geometry<box_type, box_type>("BOX(1 1,3 3)", "BOX(0 0,3 3)", true); + test_geometry<box_type, box_type>("BOX(1 2,3 3)", "BOX(0 0,3 3)", true); + test_geometry<box_type, box_type>("BOX(1 1,4 3)", "BOX(0 0,3 3)", false); +} + + +void test_3d() +{ + typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> point_type; + typedef boost::geometry::model::box<point_type> box_type; + box_type box(point_type(0, 0, 0), point_type(4, 4, 4)); + BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 2), box), true); + BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 4, 2), box), true); + BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 4), box), true); + BOOST_CHECK_EQUAL(bg::covered_by(point_type(2, 2, 5), box), false); +} + +template <typename P1, typename P2> +void test_mixed_of() +{ + typedef boost::geometry::model::polygon<P1> polygon_type1; + typedef boost::geometry::model::polygon<P2> polygon_type2; + typedef boost::geometry::model::box<P1> box_type1; + typedef boost::geometry::model::box<P2> box_type2; + + polygon_type1 poly1; + polygon_type2 poly2; + boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly1); + boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly2); + + box_type1 box1(P1(1, 1), P1(4, 4)); + box_type2 box2(P2(0, 0), P2(5, 5)); + P1 p1(3, 3); + P2 p2(3, 3); + + BOOST_CHECK_EQUAL(bg::covered_by(p1, poly2), true); + BOOST_CHECK_EQUAL(bg::covered_by(p2, poly1), true); + BOOST_CHECK_EQUAL(bg::covered_by(p2, box1), true); + BOOST_CHECK_EQUAL(bg::covered_by(p1, box2), true); + BOOST_CHECK_EQUAL(bg::covered_by(box1, box2), true); + BOOST_CHECK_EQUAL(bg::covered_by(box2, box1), false); +} + + +void test_mixed() +{ + // Mixing point types and coordinate types + test_mixed_of + < + boost::geometry::model::d2::point_xy<double>, + boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> + >(); + test_mixed_of + < + boost::geometry::model::d2::point_xy<float>, + boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> + >(); + test_mixed_of + < + boost::geometry::model::d2::point_xy<int>, + boost::geometry::model::d2::point_xy<double> + >(); +} + + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + test_all<bg::model::d2::point_xy<double> >(); + + //test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >(); + + test_mixed(); + test_3d(); + + +#if defined(HAVE_TTMATH) + test_all<bg::model::d2::point_xy<ttmath_big> >(); + //test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >(); +#endif + + return 0; +} diff --git a/libs/geometry/test/algorithms/relational_operations/crosses.cpp b/libs/geometry/test/algorithms/relational_operations/crosses.cpp new file mode 100644 index 000000000..ef9cafb90 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/crosses.cpp @@ -0,0 +1,100 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#include "test_crosses.hpp" + +template <typename P> +void test_pl() +{ + /*typedef bg::model::multi_point<P> mpt; + typedef bg::model::linestring<P> ls; + + // not implemented yet + test_geometry<mpt, ls>("MULTIPOINT(0 0,1 1)", "LINESTRING(0 0,1 0,3 3)", true); + test_geometry<mpt, ls>("MULTIPOINT(0 0,1 1)", "LINESTRING(0 0,1 1,3 3)", false);*/ +} + +template <typename P> +void test_pa() +{ + /*typedef bg::model::multi_point<P> mpt; + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + // not implemented yet + test_geometry<mpt, poly>("MULTIPOINT(0 0,6 6)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry<mpt, poly>("MULTIPOINT(0 0,1 1)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", 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,4 4)", "LINESTRING(0 1,2 1,3 1)", true); + test_geometry<ls, ls>("LINESTRING(0 0,2 2)", "LINESTRING(0 1,2 1)", true); + test_geometry<ls, ls>("LINESTRING(0 0,2 2,4 4)", "LINESTRING(0 1,1 1,2 2,3 2)", false); + + test_geometry<ls, mls>("LINESTRING(0 0,2 2,4 4)", "MULTILINESTRING((0 1,4 1),(0 2,4 2))", true); + test_geometry<mls, ls>("MULTILINESTRING((0 1,4 1),(0 2,4 2))", "LINESTRING(0 0,2 2,4 4)", true); + + test_geometry<mls, mls>("MULTILINESTRING((0 0,2 2,4 4),(3 0,3 4))", "MULTILINESTRING((0 1,4 1),(0 2,4 2))", true); + + // spike - boundary and interior on the same point + test_geometry<ls, ls>("LINESTRING(3 7, 8 8, 2 6)", "LINESTRING(5 7, 10 7, 0 7)", true); +} + +template <typename P> +void test_la() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::ring<P> ring; + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + test_geometry<ls, ring>("LINESTRING(0 0, 10 10)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry<ls, poly>("LINESTRING(0 0, 10 10)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry<ls, mpoly>("LINESTRING(0 0, 10 10)", "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)))", true); + + test_geometry<ls, poly>("LINESTRING(0 0, 10 0)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + test_geometry<ls, poly>("LINESTRING(1 1, 5 5)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + + test_geometry<mls, ring>("MULTILINESTRING((1 1, 5 5),(6 6,7 7))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry<mls, poly>("MULTILINESTRING((1 1, 5 5),(6 6,7 7))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry<mls, mpoly>("MULTILINESTRING((1 1, 5 5),(6 6,7 7))", "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)))", true); +} + +template <typename P> +void test_2d() +{ + test_pl<P>(); + test_pa<P>(); + test_ll<P>(); + test_la<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/libs/geometry/test/algorithms/relational_operations/disjoint/Jamfile.v2 b/libs/geometry/test/algorithms/relational_operations/disjoint/Jamfile.v2 new file mode 100644 index 000000000..8586e9a2c --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/disjoint/Jamfile.v2 @@ -0,0 +1,22 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +# +# This file was modified by Oracle on 2014. +# Modifications copyright (c) 2014, 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-disjoint + : + [ run disjoint.cpp ] + [ run disjoint_coverage.cpp ] + [ run multi_disjoint.cpp ] + ; diff --git a/libs/geometry/test/algorithms/relational_operations/disjoint/disjoint.cpp b/libs/geometry/test/algorithms/relational_operations/disjoint/disjoint.cpp new file mode 100644 index 000000000..7299af406 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/disjoint/disjoint.cpp @@ -0,0 +1,230 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, 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_disjoint.hpp" + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/strategies/strategies.hpp> + +#include <test_common/test_point.hpp> + +#include <algorithms/overlay/overlay_cases.hpp> + +#include <algorithms/predef_relop.hpp> + + +template <typename P> +void test_all() +{ + typedef bg::model::box<P> box; + + test_disjoint<P, P>("pp1", "point(1 1)", "point(1 1)", false); + test_disjoint<P, P>("pp2", "point(1 1)", "point(1.001 1)", true); + + // left-right + test_disjoint<box, box>("bb1", "box(1 1, 2 2)", "box(3 1, 4 2)", true); + test_disjoint<box, box>("bb2", "box(1 1, 2 2)", "box(2 1, 3 2)", false); + test_disjoint<box, box>("bb3", "box(1 1, 2 2)", "box(2 2, 3 3)", false); + test_disjoint<box, box>("bb4", "box(1 1, 2 2)", "box(2.001 2, 3 3)", true); + + // up-down + test_disjoint<box, box>("bb5", "box(1 1, 2 2)", "box(1 3, 2 4)", true); + test_disjoint<box, box>("bb6", "box(1 1, 2 2)", "box(1 2, 2 3)", false); + // right-left + test_disjoint<box, box>("bb7", "box(1 1, 2 2)", "box(0 1, 1 2)", false); + test_disjoint<box, box>("bb8", "box(1 1, 2 2)", "box(0 1, 1 2)", false); + + // point-box + test_disjoint<P, box>("pb1", "point(1 1)", "box(0 0, 2 2)", false); + test_disjoint<P, box>("pb2", "point(2 2)", "box(0 0, 2 2)", false); + test_disjoint<P, box>("pb3", "point(2.0001 2)", "box(1 1, 2 2)", true); + test_disjoint<P, box>("pb4", "point(0.9999 2)", "box(1 1, 2 2)", true); + + // box-point (to test reverse compiling) + test_disjoint<box, P>("bp1", "box(1 1, 2 2)", "point(2 2)", false); + + // Test triangles for polygons/rings, boxes + // Note that intersections are tested elsewhere, they don't need + // thorough test at this place + typedef bg::model::polygon<P> polygon; + typedef bg::model::ring<P> ring; + + // Four times same test with other types + test_disjoint<polygon, polygon>("disjoint_simplex_pp", disjoint_simplex[0], disjoint_simplex[1], true); + test_disjoint<ring, polygon>("disjoint_simplex_rp", disjoint_simplex[0], disjoint_simplex[1], true); + test_disjoint<ring, ring>("disjoint_simplex_rr", disjoint_simplex[0], disjoint_simplex[1], true); + test_disjoint<polygon, ring>("disjoint_simplex_pr", disjoint_simplex[0], disjoint_simplex[1], true); + + test_disjoint<polygon, polygon>("ticket_8310a", ticket_8310a[0], ticket_8310a[1], false); + test_disjoint<polygon, polygon>("ticket_8310b", ticket_8310b[0], ticket_8310b[1], false); + test_disjoint<polygon, polygon>("ticket_8310c", ticket_8310c[0], ticket_8310c[1], false); + + // Testing touch + test_disjoint<polygon, polygon>("touch_simplex_pp", touch_simplex[0], touch_simplex[1], false); + + // Testing overlap (and test compiling with box) + test_disjoint<polygon, polygon>("overlaps_box_pp", overlaps_box[0], overlaps_box[1], false); + test_disjoint<box, polygon>("overlaps_box_bp", overlaps_box[0], overlaps_box[1], false); + test_disjoint<box, ring>("overlaps_box_br", overlaps_box[0], overlaps_box[1], false); + test_disjoint<polygon, box>("overlaps_box_pb", overlaps_box[1], overlaps_box[0], false); + test_disjoint<ring, box>("overlaps_box_rb", overlaps_box[1], overlaps_box[0], false); + + // Test if within(a,b) returns false for disjoint + test_disjoint<ring, ring>("within_simplex_rr1", within_simplex[0], within_simplex[1], false); + test_disjoint<ring, ring>("within_simplex_rr2", within_simplex[1], within_simplex[0], false); + + test_disjoint<P, ring>("point_ring1", "POINT(0 0)", "POLYGON((0 0,3 3,6 0,0 0))", false); + test_disjoint<P, ring>("point_ring2", "POINT(3 1)", "POLYGON((0 0,3 3,6 0,0 0))", false); + test_disjoint<P, ring>("point_ring3", "POINT(0 3)", "POLYGON((0 0,3 3,6 0,0 0))", true); + test_disjoint<P, polygon>("point_polygon1", "POINT(0 0)", "POLYGON((0 0,3 3,6 0,0 0))", false); + test_disjoint<P, polygon>("point_polygon2", "POINT(3 1)", "POLYGON((0 0,3 3,6 0,0 0))", false); + test_disjoint<P, polygon>("point_polygon3", "POINT(0 3)", "POLYGON((0 0,3 3,6 0,0 0))", true); + + test_disjoint<ring, P>("point_ring2", "POLYGON((0 0,3 3,6 0,0 0))", "POINT(0 0)", false); + test_disjoint<polygon, P>("point_polygon2", "POLYGON((0 0,3 3,6 0,0 0))", "POINT(0 0)", false); + + // Linear + typedef bg::model::linestring<P> ls; + typedef bg::model::segment<P> segment; + test_disjoint<ls, ls>("ls/ls 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false); + test_disjoint<ls, ls>("ls/ls 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true); + test_disjoint<segment, segment>("s/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false); + test_disjoint<segment, segment>("s/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true); + + // Test degenerate segments (patched by Karsten Ahnert on 2012-07-25) + test_disjoint<segment, segment>("s/s 3", "linestring(0 0,0 0)", "linestring(1 0,0 1)", true); + test_disjoint<segment, segment>("s/s 4", "linestring(0 0,0 0)", "linestring(0 0,0 0)", false); + test_disjoint<segment, segment>("s/s 5", "linestring(0 0,0 0)", "linestring(1 0,1 0)", true); + test_disjoint<segment, segment>("s/s 6", "linestring(0 0,0 0)", "linestring(0 1,0 1)", true); + + // Collinear opposite + test_disjoint<ls, ls>("ls/ls co", "linestring(0 0,2 2)", "linestring(1 1,0 0)", false); + // Collinear opposite and equal + test_disjoint<ls, ls>("ls/ls co-e", "linestring(0 0,1 1)", "linestring(1 1,0 0)", false); + + + // Problem described by Volker/Albert 2012-06-01 + test_disjoint<polygon, box>("volker_albert_1", + "POLYGON((1992 3240,1992 1440,3792 1800,3792 3240,1992 3240))", + "BOX(1941 2066, 2055 2166)", false); + + test_disjoint<polygon, box>("volker_albert_2", + "POLYGON((1941 2066,2055 2066,2055 2166,1941 2166))", + "BOX(1941 2066, 2055 2166)", false); + + // Degenerate linestrings + { + // Submitted by Zachary on the Boost.Geometry Mailing List, on 2012-01-29 + std::string const a = "linestring(100 10, 0 10)"; + std::string const b = "linestring(50 10, 50 10)"; // one point only, with same y-coordinate + std::string const c = "linestring(100 10, 100 10)"; // idem, at left side + test_disjoint<ls, ls>("dls/dls 1", a, b, false); + test_disjoint<ls, ls>("dls/dls 2", b, a, false); + test_disjoint<segment, segment>("ds/ds 1", a, b, false); + test_disjoint<segment, segment>("ds/ds 2", b, a, false); + test_disjoint<ls, ls>("dls/dls 1", a, c, false); + } + + // Linestrings making angles normally ignored + { + // These (non-disjoint) cases + // correspond to the test "segment_intersection_collinear" + + // Collinear ('a') + // a1---------->a2 + // b1--->b2 + test_disjoint<ls, ls>("n1", "linestring(2 0,0 6)", "linestring(0 0,2 0)", false); + + // a1---------->a2 + // b1--->b2 + test_disjoint<ls, ls>("n7", "linestring(2 0,6 0)", "linestring(6 0,8 0)", false); + + // Collinear - opposite ('f') + // a1---------->a2 + // b2<---b1 + test_disjoint<ls, ls>("o1", "linestring(2 0,6 0)", "linestring(2 0,0 0)", false); + } + + { + // Starting in the middle ('s') + // b2 + // ^ + // | + // | + // a1--------b1----->a2 + test_disjoint<ls, ls>("case_s", "linestring(0 0,4 0)", "linestring(2 0,2 2)", false); + + // Collinear, but disjoint + test_disjoint<ls, ls>("c-d", "linestring(2 0,6 0)", "linestring(7 0,8 0)", true); + + // Parallel, disjoint + test_disjoint<ls, ls>("c-d", "linestring(2 0,6 0)", "linestring(2 1,6 1)", true); + + // Error still there until 1.48 (reported "error", was reported to disjoint, so that's why it did no harm) + test_disjoint<ls, ls>("case_recursive_boxes_1", + "linestring(10 7,10 6)", "linestring(10 10,10 9)", true); + + } + + // TODO test_disjoint<segment, ls>("s/ls 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false); + // TODO test_disjoint<segment, ls>("s/ls 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true); + // TODO test_disjoint<ls, segment>("ls/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false); + // TODO test_disjoint<ls, segment>("ls/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true); + + // 22.01.2015 + test_disjoint<ls, ls>("col-op", "LINESTRING(5 5,10 10)", "LINESTRING(6 6,3 3)", false); + test_disjoint<ls, ls>("col-op", "LINESTRING(5 5,2 8)", "LINESTRING(4 6,7 3)", false); + + test_disjoint<ls, polygon>("col-op", "LINESTRING(10 10,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + test_disjoint<ls, polygon>("col-op", "LINESTRING(9 10,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + + // assertion failure in 1.57 + test_disjoint<ls, ls>("point_ll_assert_1_57", + "LINESTRING(-2305843009213693956 4611686018427387906, -33 -92, 78 83)", + "LINESTRING(31 -97, -46 57, -20 -4)", + false); +} + + +template <typename P> +void test_3d() +{ + typedef bg::model::box<P> box; + + test_disjoint<P, P>("pp 3d 1", "point(1 1 1)", "point(1 1 1)", false); + test_disjoint<P, P>("pp 3d 2", "point(1 1 1)", "point(1.001 1 1)", true); + + test_disjoint<box, box>("bb1", "box(1 1 1, 2 2 2)", "box(3 1 1, 4 2 1)", true); + test_disjoint<box, box>("bb2", "box(1 1 1, 2 2 2)", "box(2 1 1, 3 2 1)", false); + test_disjoint<box, box>("bb3", "box(1 1 1, 2 2 2)", "box(2 2 1, 3 3 1)", false); + test_disjoint<box, box>("bb4", "box(1 1 1, 2 2 2)", "box(2.001 2 1, 3 3 1)", true); + +} + +int test_main(int, char* []) +{ + test_all<bg::model::d2::point_xy<float> >(); + test_all<bg::model::d2::point_xy<double> >(); + +#ifdef HAVE_TTMATH + test_all<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + test_3d<bg::model::point<double, 3, bg::cs::cartesian> >(); + + + return 0; +} diff --git a/libs/geometry/test/algorithms/relational_operations/disjoint/disjoint_coverage.cpp b/libs/geometry/test/algorithms/relational_operations/disjoint/disjoint_coverage.cpp new file mode 100644 index 000000000..4708fd6db --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/disjoint/disjoint_coverage.cpp @@ -0,0 +1,1723 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2014, Oracle and/or its affiliates. + +// Licensed under the Boost Software License version 1.0. +// http://www.boost.org/users/license.html + +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_disjoint_coverage +#endif + +// unit test to test disjoint for all geometry combinations + +#include <iostream> + +#include <boost/test/included/unit_test.hpp> + +#include <boost/geometry/core/tag.hpp> +#include <boost/geometry/core/tags.hpp> +#include <boost/geometry/multi/core/tags.hpp> + +#include <boost/geometry/strategies/strategies.hpp> + +#include <boost/geometry/io/wkt/read.hpp> +#include <boost/geometry/io/wkt/write.hpp> +#include <boost/geometry/multi/io/wkt/read.hpp> +#include <boost/geometry/multi/io/wkt/write.hpp> +#include <boost/geometry/io/dsv/write.hpp> + +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/segment.hpp> +#include <boost/geometry/geometries/linestring.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/multi/geometries/multi_point.hpp> +#include <boost/geometry/multi/geometries/multi_linestring.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +#include <boost/geometry/algorithms/disjoint.hpp> + +#include <from_wkt.hpp> + + +#ifdef HAVE_TTMATH +#include <boost/geometry/extensions/contrib/ttmath_stub.hpp> +#endif + +namespace bg = ::boost::geometry; + +//============================================================================ + +struct test_disjoint +{ + template <typename Geometry1, typename Geometry2> + static inline void apply(std::string const& case_id, + Geometry1 const& geometry1, + Geometry2 const& geometry2, + bool expected_result) + { + bool result = bg::disjoint(geometry1, geometry2); + BOOST_CHECK_MESSAGE(result == expected_result, + "case ID: " << case_id << ", G1: " << bg::wkt(geometry1) + << ", G2: " << bg::wkt(geometry2) << " -> Expected: " + << expected_result << ", detected: " << result); + + result = bg::disjoint(geometry2, geometry1); + BOOST_CHECK_MESSAGE(result == expected_result, + "case ID: " << case_id << ", G1: " << bg::wkt(geometry2) + << ", G2: " << bg::wkt(geometry1) << " -> Expected: " + << expected_result << ", detected: " << result); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "case ID: " << case_id << "; G1 - G2: "; + std::cout << bg::wkt(geometry1) << " - "; + std::cout << bg::wkt(geometry2) << std::endl; + std::cout << std::boolalpha; + std::cout << "expected/computed result: " + << expected_result << " / " << result << std::endl; + std::cout << std::endl; + std::cout << std::noboolalpha; +#endif + } +}; + +//============================================================================ + +// pointlike-pointlike geometries +template <typename P> +inline void test_point_point() +{ + typedef test_disjoint tester; + + tester::apply("p-p-01", + from_wkt<P>("POINT(0 0)"), + from_wkt<P>("POINT(0 0)"), + false); + + tester::apply("p-p-02", + from_wkt<P>("POINT(0 0)"), + from_wkt<P>("POINT(1 1)"), + true); +} + +template <typename P> +inline void test_point_multipoint() +{ + typedef bg::model::multi_point<P> MP; + + typedef test_disjoint tester; + + tester::apply("p-mp-01", + from_wkt<P>("POINT(0 0)"), + from_wkt<MP>("MULTIPOINT(0 0,1 1)"), + false); + + tester::apply("p-mp-02", + from_wkt<P>("POINT(0 0)"), + from_wkt<MP>("MULTIPOINT(1 1,2 2)"), + true); + + tester::apply("p-mp-03", + from_wkt<P>("POINT(0 0)"), + from_wkt<MP>("MULTIPOINT()"), + true); +} + +template <typename P> +inline void test_multipoint_multipoint() +{ + typedef bg::model::multi_point<P> MP; + + typedef test_disjoint tester; + + tester::apply("mp-mp-01", + from_wkt<MP>("MULTIPOINT(0 0,1 0)"), + from_wkt<MP>("MULTIPOINT(0 0,1 1)"), + false); + + tester::apply("mp-mp-02", + from_wkt<MP>("MULTIPOINT(0 0,1 0)"), + from_wkt<MP>("MULTIPOINT(1 1,2 2)"), + true); + + tester::apply("mp-mp-03", + from_wkt<MP>("MULTIPOINT()"), + from_wkt<MP>("MULTIPOINT(1 1,2 2)"), + true); + + tester::apply("mp-mp-04", + from_wkt<MP>("MULTIPOINT(0 0,1 0)"), + from_wkt<MP>("MULTIPOINT()"), + true); +} + +//============================================================================ + +// pointlike-linear geometries +template <typename P> +inline void test_point_segment() +{ + typedef test_disjoint tester; + typedef bg::model::segment<P> S; + + tester::apply("p-s-01", + from_wkt<P>("POINT(0 0)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + false); + + tester::apply("p-s-02", + from_wkt<P>("POINT(1 0)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + false); + + tester::apply("p-s-03", + from_wkt<P>("POINT(1 1)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + true); + + tester::apply("p-s-04", + from_wkt<P>("POINT(3 0)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + true); + + tester::apply("p-s-05", + from_wkt<P>("POINT(-1 0)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + true); +} + +template <typename P> +inline void test_point_linestring() +{ + typedef bg::model::linestring<P> L; + + typedef test_disjoint tester; + + tester::apply("p-l-01", + from_wkt<P>("POINT(0 0)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply("p-l-02", + from_wkt<P>("POINT(1 1)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply("p-l-03", + from_wkt<P>("POINT(3 3)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply("p-l-04", + from_wkt<P>("POINT(1 0)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + true); + + tester::apply("p-l-05", + from_wkt<P>("POINT(5 5)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + true); + + tester::apply("p-l-06", + from_wkt<P>("POINT(5 5)"), + from_wkt<L>("LINESTRING(0 0,2 2)"), + true); +} + +template <typename P> +inline void test_point_multilinestring() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + + typedef test_disjoint tester; + + tester::apply("p-ml-01", + from_wkt<P>("POINT(0 1)"), + from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + true); + + tester::apply("p-ml-02", + from_wkt<P>("POINT(0 0)"), + from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply("p-ml-03", + from_wkt<P>("POINT(1 1)"), + from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply("p-ml-04", + from_wkt<P>("POINT(1 0)"), + from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply("p-ml-05", + from_wkt<P>("POINT(0 0)"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(3 0,4 0))"), + true); + + tester::apply("p-ml-06", + from_wkt<P>("POINT(0 0)"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(0 0,4 0))"), + false); + + tester::apply("p-ml-07", + from_wkt<P>("POINT(0 0)"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(-1 0,4 0))"), + false); +} + +template <typename P> +inline void test_multipoint_segment() +{ + typedef test_disjoint tester; + typedef bg::model::multi_point<P> MP; + typedef bg::model::segment<P> S; + + tester::apply("mp-s-01", + from_wkt<MP>("MULTIPOINT(0 0,1 1)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + false); + + tester::apply("mp-s-02", + from_wkt<MP>("MULTIPOINT(1 0,1 1)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + false); + + tester::apply("mp-s-03", + from_wkt<MP>("MULTIPOINT(1 1,2 2)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + true); + + tester::apply("mp-s-04", + from_wkt<MP>("MULTIPOINT()"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + true); + + tester::apply("mp-s-05", + from_wkt<MP>("MULTIPOINT(3 0,4 0)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + true); + + tester::apply("mp-s-06", + from_wkt<MP>("MULTIPOINT(1 0,4 0)"), + from_wkt<S>("SEGMENT(0 0,2 0)"), + false); + + // segments that degenerate to a point + tester::apply("mp-s-07", + from_wkt<MP>("MULTIPOINT(1 1,2 2)"), + from_wkt<S>("SEGMENT(0 0,0 0)"), + true); + + tester::apply("mp-s-08", + from_wkt<MP>("MULTIPOINT(1 1,2 2)"), + from_wkt<S>("SEGMENT(1 1,1 1)"), + false); +} + +template <typename P> +inline void test_multipoint_linestring() +{ + typedef bg::model::multi_point<P> MP; + typedef bg::model::linestring<P> L; + + typedef test_disjoint tester; + + tester::apply("mp-l-01", + from_wkt<MP>("MULTIPOINT(0 0,1 0)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply("mp-l-02", + from_wkt<MP>("MULTIPOINT(1 0,1 1)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply("mp-l-03", + from_wkt<MP>("MULTIPOINT(1 0,3 3)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply("mp-l-04", + from_wkt<MP>("MULTIPOINT(1 0,2 0)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + true); + + tester::apply("mp-l-05", + from_wkt<MP>("MULTIPOINT(-1 -1,2 0)"), + from_wkt<L>("LINESTRING(0 0,2 2,4 4)"), + true); + + tester::apply("mp-l-06", + from_wkt<MP>("MULTIPOINT(-1 -1,2 0)"), + from_wkt<L>("LINESTRING(1 0,3 0)"), + false); + + tester::apply("mp-l-07", + from_wkt<MP>("MULTIPOINT(-1 -1,2 0)"), + from_wkt<L>("LINESTRING(1 0,3 0)"), + false); +} + +template <typename P> +inline void test_multipoint_multilinestring() +{ + typedef bg::model::multi_point<P> MP; + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + + typedef test_disjoint tester; + + tester::apply("mp-ml-01", + from_wkt<MP>("MULTIPOINT(0 1,0 2)"), + from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + true); + + tester::apply("mp-ml-02", + from_wkt<MP>("MULTIPOINT(0 0,1 0)"), + from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply("mp-ml-03", + from_wkt<MP>("MULTIPOINT(0 1,1 1)"), + from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply("mp-ml-04", + from_wkt<MP>("MULTIPOINT(0 1,1 0)"), + from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); +} + +//============================================================================ + +// pointlike-areal geometries +template <typename P> +inline void test_point_box() +{ + typedef test_disjoint tester; + typedef bg::model::box<P> B; + + tester::apply("p-b-01", + from_wkt<P>("POINT(0 0)"), + from_wkt<B>("BOX(0 0,1 1)"), + false); + + tester::apply("p-b-02", + from_wkt<P>("POINT(2 2)"), + from_wkt<B>("BOX(0 0,1 0)"), + true); +} + +template <typename P> +inline void test_point_ring() +{ + typedef bg::model::ring<P, false, false> R; // ccw, open + + typedef test_disjoint tester; + + tester::apply("p-r-01", + from_wkt<P>("POINT(0 0)"), + from_wkt<R>("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply("p-r-02", + from_wkt<P>("POINT(1 1)"), + from_wkt<R>("POLYGON((0 0,1 0,0 1))"), + true); +} + +template <typename P> +inline void test_point_polygon() +{ + typedef bg::model::polygon<P, false, false> PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply("p-pg-01", + from_wkt<P>("POINT(0 0)"), + from_wkt<PL>("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply("p-pg-02", + from_wkt<P>("POINT(1 1)"), + from_wkt<PL>("POLYGON((0 0,1 0,0 1))"), + true); +} + +template <typename P> +inline void test_point_multipolygon() +{ + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("p-mpg-01", + from_wkt<P>("POINT(0 0)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"), + false); + + tester::apply("p-mpg-02", + from_wkt<P>("POINT(1 1)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"), + true); +} + +template <typename P> +inline void test_multipoint_box() +{ + typedef test_disjoint tester; + typedef bg::model::multi_point<P> MP; + typedef bg::model::box<P> B; + + tester::apply("mp-b-01", + from_wkt<MP>("MULTIPOINT(0 0,1 1)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("mp-b-02", + from_wkt<MP>("MULTIPOINT(1 1,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("mp-b-03", + from_wkt<MP>("MULTIPOINT(3 3,4 4)"), + from_wkt<B>("BOX(0 0,2 2)"), + true); + + tester::apply("mp-b-04", + from_wkt<MP>("MULTIPOINT()"), + from_wkt<B>("BOX(0 0,2 2)"), + true); +} + +template <typename P> +inline void test_multipoint_ring() +{ + typedef bg::model::multi_point<P> MP; + typedef bg::model::ring<P, false, false> R; // ccw, open + + typedef test_disjoint tester; + + tester::apply("mp-r-01", + from_wkt<MP>("MULTIPOINT(0 0,1 0)"), + from_wkt<R>("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply("mp-r-02", + from_wkt<MP>("MULTIPOINT(1 0,1 1)"), + from_wkt<R>("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply("mp-r-03", + from_wkt<MP>("MULTIPOINT(1 1,2 2)"), + from_wkt<R>("POLYGON((0 0,1 0,0 1))"), + true); +} + +template <typename P> +inline void test_multipoint_polygon() +{ + typedef bg::model::multi_point<P> MP; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply("mp-pg-01", + from_wkt<MP>("MULTIPOINT(0 0,1 0)"), + from_wkt<PL>("POLYGON(((0 0,1 0,0 1)))"), + false); + + tester::apply("mp-pg-02", + from_wkt<MP>("MULTIPOINT(0 0,2 0)"), + from_wkt<PL>("POLYGON(((0 0,1 0,0 1)))"), + false); + + tester::apply("mp-pg-03", + from_wkt<MP>("MULTIPOINT(1 1,2 0)"), + from_wkt<PL>("POLYGON(((0 0,1 0,0 1)))"), + true); + + tester::apply("mp-pg-04", + from_wkt<MP>("MULTIPOINT(1 1,2 3)"), + from_wkt<PL>("POLYGON(((0 0,1 0,0 1)))"), + true); +} + +template <typename P> +inline void test_multipoint_multipolygon() +{ + typedef bg::model::multi_point<P> MP; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("mp-mp-01", + from_wkt<MP>("MULTIPOINT(0 0,2 0)"), + from_wkt<MPL>("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply("mp-mp-02", + from_wkt<MP>("MULTIPOINT(0 0,1 0)"), + from_wkt<MPL>("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply("mp-mp-03", + from_wkt<MP>("MULTIPOINT(1 1,2 0)"), + from_wkt<MPL>("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply("mp-mp-04", + from_wkt<MP>("MULTIPOINT(1 1,2 3)"), + from_wkt<MPL>("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + true); +} + +//============================================================================ + +// linear-linear geometries +template <typename P> +inline void test_segment_segment() +{ + typedef bg::model::segment<P> S; + + typedef test_disjoint tester; + + tester::apply("s-s-01", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<S>("SEGMENT(0 0,0 2)"), + false); + + tester::apply("s-s-02", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<S>("SEGMENT(2 0,3 0)"), + false); + + tester::apply("s-s-03", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<S>("SEGMENT(1 0,3 0)"), + false); + + tester::apply("s-s-04", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<S>("SEGMENT(1 0,1 1)"), + false); + + tester::apply("s-s-05", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<S>("SEGMENT(1 1,2 2)"), + true); + + tester::apply("s-s-06", + from_wkt<S>("SEGMENT(0 0,1 1)"), + from_wkt<S>("SEGMENT(1 1,1 1)"), + false); + + tester::apply("s-s-07", + from_wkt<S>("SEGMENT(0 0,1 1)"), + from_wkt<S>("SEGMENT(2 2,2 2)"), + true); + + tester::apply("s-s-08", + from_wkt<S>("SEGMENT(0 0,1 1)"), + from_wkt<S>("SEGMENT(2 2,3 3)"), + true); +} + +template <typename P> +inline void test_linestring_segment() +{ + typedef bg::model::segment<P> S; + typedef bg::model::linestring<P> L; + + typedef test_disjoint tester; + + tester::apply("l-s-01", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(0 0,0 2)"), + false); + + tester::apply("l-s-02", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(2 0,3 0)"), + false); + + tester::apply("l-s-03", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 0,3 0)"), + false); + + tester::apply("l-s-04", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 0,1 1)"), + false); + + tester::apply("l-s-05", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 1,2 2)"), + true); + + tester::apply("l-s-06", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 1,1 1,2 2)"), + true); + + tester::apply("l-s-07", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 0,1 0,1 1,2 2)"), + false); + + tester::apply("l-s-08", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 0,1 0,3 0)"), + false); + + tester::apply("l-s-09", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(3 0,3 0,4 0)"), + true); + + tester::apply("l-s-10", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(3 0,3 0)"), + true); + + tester::apply("l-s-11", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(-1 0,-1 0)"), + true); + + tester::apply("l-s-12", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 0,1 0)"), + false); + + tester::apply("l-s-13", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 1,1 1)"), + true); +} + +template <typename P> +inline void test_multilinestring_segment() +{ + typedef bg::model::segment<P> S; + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + + typedef test_disjoint tester; + + tester::apply("s-ml-01", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply("s-ml-02", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply("s-ml-03", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply("s-ml-04", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply("s-ml-05", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2))"), + true); + + tester::apply("s-ml-06", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2),(3 3,3 3))"), + true); + + tester::apply("s-ml-07", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2),(1 0,1 0))"), + false); + + tester::apply("s-ml-08", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2),(3 0,3 0))"), + true); +} + +template <typename P> +inline void test_linestring_linestring() +{ + typedef bg::model::linestring<P> L; + + typedef test_disjoint tester; + + tester::apply("l-l-01", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<L>("LINESTRING(0 0,0 2)"), + false); + + tester::apply("l-l-02", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<L>("LINESTRING(2 0,3 0)"), + false); + + tester::apply("l-l-03", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 0,3 0)"), + false); + + tester::apply("l-l-04", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 0,1 1)"), + false); + + tester::apply("l-l-05", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<L>("LINESTRING(1 1,2 2)"), + true); +} + +template <typename P> +inline void test_linestring_multilinestring() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + + typedef test_disjoint tester; + + tester::apply("l-ml-01", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply("l-ml-02", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply("l-ml-03", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply("l-ml-04", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply("l-ml-05", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2))"), + true); +} + +template <typename P> +inline void test_multilinestring_multilinestring() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + + typedef test_disjoint tester; + + tester::apply("ml-ml-01", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<ML>("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply("ml-ml-02", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<ML>("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply("ml-ml-03", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<ML>("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply("ml-ml-04", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<ML>("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply("ml-ml-05", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<ML>("MULTILINESTRING((1 1,2 2))"), + true); +} + +//============================================================================ + +// linear-areal geometries +template <typename P> +inline void test_segment_box() +{ + typedef bg::model::segment<P> S; + typedef bg::model::box<P> B; + + typedef test_disjoint tester; + + tester::apply("s-b-01", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("s-b-02", + from_wkt<S>("SEGMENT(1 1,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("s-b-03", + from_wkt<S>("SEGMENT(2 2,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("s-b-04", + from_wkt<S>("SEGMENT(4 4,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + true); + + tester::apply("s-b-05", + from_wkt<S>("SEGMENT(0 4,4 4)"), + from_wkt<B>("BOX(0 0,2 2)"), + true); + + tester::apply("s-b-06", + from_wkt<S>("SEGMENT(4 0,4 4)"), + from_wkt<B>("BOX(0 0,2 2)"), + true); + + tester::apply("s-b-07", + from_wkt<S>("SEGMENT(0 -2,0 -1)"), + from_wkt<B>("BOX(0 0,1 1)"), + true); + + tester::apply("s-b-08", + from_wkt<S>("SEGMENT(-2 -2,-2 -1)"), + from_wkt<B>("BOX(0 0,1 1)"), + true); + + tester::apply("s-b-09", + from_wkt<S>("SEGMENT(-2 -2,-2 -2)"), + from_wkt<B>("BOX(0 0,1 1)"), + true); + + tester::apply("s-b-10", + from_wkt<S>("SEGMENT(-2 0,-2 0)"), + from_wkt<B>("BOX(0 0,1 1)"), + true); + + tester::apply("s-b-11", + from_wkt<S>("SEGMENT(0 -2,0 -2)"), + from_wkt<B>("BOX(0 0,1 1)"), + true); + + tester::apply("s-b-12", + from_wkt<S>("SEGMENT(-2 0,-1 0)"), + from_wkt<B>("BOX(0 0,1 1)"), + true); + + // segment degenerates to a point + tester::apply("s-b-13", + from_wkt<S>("SEGMENT(0 0,0 0)"), + from_wkt<B>("BOX(0 0,1 1)"), + false); + + tester::apply("s-b-14", + from_wkt<S>("SEGMENT(1 1,1 1)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("s-b-15", + from_wkt<S>("SEGMENT(2 2,2 2)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("s-b-16", + from_wkt<S>("SEGMENT(2 0,2 0)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("s-b-17", + from_wkt<S>("SEGMENT(0 2,0 2)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("s-b-18", + from_wkt<S>("SEGMENT(2 2,2 2)"), + from_wkt<B>("BOX(0 0,1 1)"), + true); +} + +template <typename P> +inline void test_segment_ring() +{ + typedef bg::model::segment<P> S; + typedef bg::model::ring<P, false, false> R; // ccw, open + + typedef test_disjoint tester; + + tester::apply("s-r-01", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("s-r-02", + from_wkt<S>("SEGMENT(1 0,3 3)"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("s-r-03", + from_wkt<S>("SEGMENT(1 1,3 3)"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("s-r-04", + from_wkt<S>("SEGMENT(2 2,3 3)"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + true); +} + +template <typename P> +inline void test_segment_polygon() +{ + typedef bg::model::segment<P> S; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply("s-pg-01", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("s-pg-02", + from_wkt<S>("SEGMENT(1 0,3 3)"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("s-pg-03", + from_wkt<S>("SEGMENT(1 1,3 3)"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("s-pg-04", + from_wkt<S>("SEGMENT(2 2,3 3)"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + true); +} + +template <typename P> +inline void test_segment_multipolygon() +{ + typedef bg::model::segment<P> S; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("s-mpg-01", + from_wkt<S>("SEGMENT(0 0,2 0)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("s-mpg-02", + from_wkt<S>("SEGMENT(1 0,3 3)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("s-mpg-03", + from_wkt<S>("SEGMENT(1 1,3 3)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("s-mpg-04", + from_wkt<S>("SEGMENT(2 2,3 3)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +template <typename P> +inline void test_linestring_box() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::box<P> B; + + typedef test_disjoint tester; + + tester::apply("l-b-01", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("l-b-02", + from_wkt<L>("LINESTRING(1 1,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("l-b-03", + from_wkt<L>("LINESTRING(2 2,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("l-b-04", + from_wkt<L>("LINESTRING(4 4,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + true); +} + +template <typename P> +inline void test_linestring_ring() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::ring<P, false, false> R; // ccw, open + + typedef test_disjoint tester; + + tester::apply("l-r-01", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("l-r-02", + from_wkt<L>("LINESTRING(1 0,3 3)"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("l-r-03", + from_wkt<L>("LINESTRING(1 1,3 3)"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("l-r-04", + from_wkt<L>("LINESTRING(2 2,3 3)"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + true); +} + +template <typename P> +inline void test_linestring_polygon() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply("l-pg-01", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("l-pg-02", + from_wkt<L>("LINESTRING(1 0,3 3)"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("l-pg-03", + from_wkt<L>("LINESTRING(1 1,3 3)"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("l-pg-04", + from_wkt<L>("LINESTRING(2 2,3 3)"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + true); +} + +template <typename P> +inline void test_linestring_multipolygon() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("l-mpg-01", + from_wkt<L>("LINESTRING(0 0,2 0)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("l-mpg-02", + from_wkt<L>("LINESTRING(1 0,3 3)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("l-mpg-03", + from_wkt<L>("LINESTRING(1 1,3 3)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("l-mpg-04", + from_wkt<L>("LINESTRING(2 2,3 3)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +template <typename P> +inline void test_multilinestring_box() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + typedef bg::model::box<P> B; + + typedef test_disjoint tester; + + tester::apply("ml-b-01", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("ml-b-02", + from_wkt<ML>("MULTILINESTRING((1 1,3 3))"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("ml-b-03", + from_wkt<ML>("MULTILINESTRING((2 2,3 3))"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("ml-b-04", + from_wkt<ML>("MULTILINESTRING((4 4,3 3))"), + from_wkt<B>("BOX(0 0,2 2)"), + true); +} + +template <typename P> +inline void test_multilinestring_ring() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + typedef bg::model::ring<P, false, false> R; // ccw, open + + typedef test_disjoint tester; + + tester::apply("ml-r-01", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("ml-r-02", + from_wkt<ML>("MULTILINESTRING((1 0,3 3))"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("ml-r-03", + from_wkt<ML>("MULTILINESTRING((1 1,3 3))"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("ml-r-04", + from_wkt<ML>("MULTILINESTRING((2 2,3 3))"), + from_wkt<R>("POLYGON((0 0,2 0,0 2))"), + true); +} + +template <typename P> +inline void test_multilinestring_polygon() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply("ml-pg-01", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("ml-pg-02", + from_wkt<ML>("MULTILINESTRING((1 0,3 3))"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("ml-pg-03", + from_wkt<ML>("MULTILINESTRING((1 1,3 3))"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply("ml-pg-04", + from_wkt<ML>("MULTILINESTRING((2 2,3 3))"), + from_wkt<PL>("POLYGON((0 0,2 0,0 2))"), + true); +} + +template <typename P> +inline void test_multilinestring_multipolygon() +{ + typedef bg::model::linestring<P> L; + typedef bg::model::multi_linestring<L> ML; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("ml-mpg-01", + from_wkt<ML>("MULTILINESTRING((0 0,2 0))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("ml-mpg-02", + from_wkt<ML>("MULTILINESTRING((1 0,3 3))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("ml-mpg-03", + from_wkt<ML>("MULTILINESTRING((1 1,3 3))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply("ml-mpg-04", + from_wkt<ML>("MULTILINESTRING((2 2,3 3))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +//============================================================================ + +// areal-areal geometries +template <typename P> +inline void test_box_box() +{ + typedef bg::model::box<P> B; + + typedef test_disjoint tester; + + tester::apply("b-b-01", + from_wkt<B>("BOX(2 2,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("b-b-02", + from_wkt<B>("BOX(1 1,3 3)"), + from_wkt<B>("BOX(0 0,2 2)"), + false); + + tester::apply("b-b-03", + from_wkt<B>("BOX(3 3,4 4)"), + from_wkt<B>("BOX(0 0,2 2)"), + true); +} + +template <typename P> +inline void test_ring_box() +{ + typedef bg::model::box<P> B; + typedef bg::model::ring<P, false, false> R; // ccw, open + + typedef test_disjoint tester; + + tester::apply("r-b-01", + from_wkt<B>("BOX(2 2,3 3)"), + from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("r-b-02", + from_wkt<B>("BOX(1 1,3 3)"), + from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("r-b-03", + from_wkt<B>("BOX(3 3,4 4)"), + from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template <typename P> +inline void test_polygon_box() +{ + typedef bg::model::box<P> B; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply("pg-b-01", + from_wkt<B>("BOX(2 2,3 3)"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("pg-b-02", + from_wkt<B>("BOX(1 1,3 3)"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("pg-b-03", + from_wkt<B>("BOX(3 3,4 4)"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template <typename P> +inline void test_multipolygon_box() +{ + typedef bg::model::box<P> B; + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("mpg-b-01", + from_wkt<B>("BOX(2 2,3 3)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply("mpg-b-02", + from_wkt<B>("BOX(1 1,3 3)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply("mpg-b-03", + from_wkt<B>("BOX(3 3,4 4)"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template <typename P> +inline void test_ring_ring() +{ + typedef bg::model::ring<P, false, false> R; // ccw, open + + typedef test_disjoint tester; + + tester::apply("r-r-01", + from_wkt<R>("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("r-r-02", + from_wkt<R>("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("r-r-03", + from_wkt<R>("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt<R>("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template <typename P> +inline void test_polygon_ring() +{ + typedef bg::model::ring<P, false, false> R; // ccw, open + typedef bg::model::polygon<P, false, false> PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply("pg-r-01", + from_wkt<R>("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("pg-r-02", + from_wkt<R>("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("pg-r-03", + from_wkt<R>("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template <typename P> +inline void test_multipolygon_ring() +{ + typedef bg::model::ring<P, false, false> R; // ccw, open + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("mpg-r-01", + from_wkt<R>("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply("mpg-r-02", + from_wkt<R>("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply("mpg-r-03", + from_wkt<R>("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template <typename P> +inline void test_polygon_polygon() +{ + typedef bg::model::polygon<P, false, false> PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply("pg-pg-01", + from_wkt<PL>("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("pg-pg-02", + from_wkt<PL>("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply("pg-pg-03", + from_wkt<PL>("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt<PL>("POLYGON((0 0,2 0,2 2,0 2))"), + true); + + tester::apply("pg-pg-04", + from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9))"), + from_wkt<PL>("POLYGON((3 3,6 3,6 6,3 6))"), + false); + // polygon with a hole which entirely contains the other polygon + tester::apply("pg-pg-05", + from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9),(2 2,2 7,7 7,7 2))"), + from_wkt<PL>("POLYGON((3 3,6 3,6 6,3 6))"), + true); + // polygon with a hole, but the inner ring intersects the other polygon + tester::apply("pg-pg-06", + from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9),(3 2,3 7,7 7,7 2))"), + from_wkt<PL>("POLYGON((2 3,6 3,6 6,2 6))"), + false); + // polygon with a hole, but the other polygon is entirely contained + // between the inner and outer rings. + tester::apply("pg-pg-07", + from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9),(6 2,6 7,7 7,7 2))"), + from_wkt<PL>("POLYGON((3 3,5 3,5 6,3 6))"), + false); + // polygon with a hole and the outer ring of the other polygon lies + // between the inner and outer, but without touching either. + tester::apply("pg-pg-08", + from_wkt<PL>("POLYGON((0 0,9 0,9 9,0 9),(3 3,3 6,6 6,6 3))"), + from_wkt<PL>("POLYGON((2 2,7 2,7 7,2 7))"), + false); + + { + typedef bg::model::polygon<P> PL; // cw, closed + + // https://svn.boost.org/trac/boost/ticket/10647 + tester::apply("ticket-10647", + from_wkt<PL>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0)(1 1, 4 1, 4 4, 1 4, 1 1))"), + from_wkt<PL>("POLYGON((2 2, 2 3, 3 3, 3 2, 2 2))"), + true); + } +} + +template <typename P> +inline void test_polygon_multipolygon() +{ + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("pg-mpg-01", + from_wkt<PL>("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply("pg-mpg-02", + from_wkt<PL>("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply("pg-mpg-03", + from_wkt<PL>("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template <typename P> +inline void test_multipolygon_multipolygon() +{ + typedef bg::model::polygon<P, false, false> PL; // ccw, open + typedef bg::model::multi_polygon<PL> MPL; + + typedef test_disjoint tester; + + tester::apply("mpg-mpg-01", + from_wkt<MPL>("MULTIPOLYGON(((2 2,2 3,3 3,3 2)))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply("mpg-mpg-02", + from_wkt<MPL>("MULTIPOLYGON(((1 1,1 3,3 3,3 1)))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply("mpg-mpg-03", + from_wkt<MPL>("MULTIPOLYGON(((3 3,3 4,4 4,4 3)))"), + from_wkt<MPL>("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +//============================================================================ + +template <typename CoordinateType> +inline void test_pointlike_pointlike() +{ + typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; + + test_point_point<point_type>(); + test_point_multipoint<point_type>(); + + test_multipoint_multipoint<point_type>(); +} + +template <typename CoordinateType> +inline void test_pointlike_linear() +{ + typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; + + test_point_linestring<point_type>(); + test_point_multilinestring<point_type>(); + test_point_segment<point_type>(); + + // not implemented yet + // test_multipoint_linestring<point_type>(); + // test_multipoint_multilinestring<point_type>(); + test_multipoint_segment<point_type>(); +} + +template <typename CoordinateType> +inline void test_pointlike_areal() +{ + typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; + + test_point_polygon<point_type>(); + test_point_multipolygon<point_type>(); + test_point_ring<point_type>(); + test_point_box<point_type>(); + + // not implemented yet + // test_multipoint_polygon<point_type>(); + // test_multipoint_multipolygon<point_type>(); + // test_multipoint_ring<point_type>(); + test_multipoint_box<point_type>(); +} + +template <typename CoordinateType> +inline void test_linear_linear() +{ + typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; + + test_linestring_linestring<point_type>(); + test_linestring_multilinestring<point_type>(); + test_linestring_segment<point_type>(); + + test_multilinestring_multilinestring<point_type>(); + test_multilinestring_segment<point_type>(); + + test_segment_segment<point_type>(); +} + +template <typename CoordinateType> +inline void test_linear_areal() +{ + typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; + + test_segment_polygon<point_type>(); + test_segment_multipolygon<point_type>(); + test_segment_ring<point_type>(); + test_segment_box<point_type>(); + + test_linestring_polygon<point_type>(); + test_linestring_multipolygon<point_type>(); + test_linestring_ring<point_type>(); + test_linestring_box<point_type>(); + + test_multilinestring_polygon<point_type>(); + test_multilinestring_multipolygon<point_type>(); + test_multilinestring_ring<point_type>(); + test_multilinestring_box<point_type>(); +} + +template <typename CoordinateType> +inline void test_areal_areal() +{ + typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; + + test_polygon_polygon<point_type>(); + test_polygon_multipolygon<point_type>(); + test_polygon_ring<point_type>(); + test_polygon_box<point_type>(); + + test_multipolygon_multipolygon<point_type>(); + test_multipolygon_ring<point_type>(); + test_multipolygon_box<point_type>(); + + test_ring_ring<point_type>(); + test_ring_box<point_type>(); + + test_box_box<point_type>(); +} + +//============================================================================ + +BOOST_AUTO_TEST_CASE( test_pointlike_pointlike_all ) +{ + test_pointlike_pointlike<double>(); + test_pointlike_pointlike<int>(); +#ifdef HAVE_TTMATH + test_pointlike_pointlike<ttmath_big>(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_pointlike_linear_all ) +{ + test_pointlike_linear<double>(); + test_pointlike_linear<int>(); +#ifdef HAVE_TTMATH + test_pointlike_linear<ttmath_big>(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_pointlike_areal_all ) +{ + test_pointlike_areal<double>(); + test_pointlike_areal<int>(); +#ifdef HAVE_TTMATH + test_pointlike_areal<ttmath_big>(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_linear_linear_all ) +{ + test_linear_linear<double>(); + test_linear_linear<int>(); +#ifdef HAVE_TTMATH + test_linear_linear<ttmath_big>(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_linear_areal_all ) +{ + test_linear_areal<double>(); + test_linear_areal<int>(); +#ifdef HAVE_TTMATH + test_linear_areal<ttmath_big>(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_areal_areal_all ) +{ + test_areal_areal<double>(); + test_areal_areal<int>(); +#ifdef HAVE_TTMATH + test_areal_areal<ttmath_big>(); +#endif +} diff --git a/libs/geometry/test/algorithms/relational_operations/disjoint/multi_disjoint.cpp b/libs/geometry/test/algorithms/relational_operations/disjoint/multi_disjoint.cpp new file mode 100644 index 000000000..330a66e52 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/disjoint/multi_disjoint.cpp @@ -0,0 +1,140 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2012 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_disjoint.hpp" + +#include <boost/geometry/strategies/strategies.hpp> + +#include <boost/geometry/multi/algorithms/detail/sections/range_by_section.hpp> +#include <boost/geometry/multi/algorithms/detail/sections/sectionalize.hpp> +#include <boost/geometry/multi/algorithms/detail/point_on_border.hpp> +#include <boost/geometry/multi/algorithms/detail/for_each_range.hpp> +#include <boost/geometry/multi/algorithms/within.hpp> +#include <boost/geometry/multi/core/closure.hpp> +#include <boost/geometry/multi/core/geometry_id.hpp> +#include <boost/geometry/multi/core/ring_type.hpp> +#include <boost/geometry/multi/views/detail/range_type.hpp> + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +#include <test_common/test_point.hpp> + +#include <algorithms/predef_relop.hpp> + + +template <typename P> +void test_all() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::polygon<P> polygon; + typedef bg::model::multi_polygon<polygon> mp; + + test_disjoint<mp, mp>("", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + false); + + // True disjoint + test_disjoint<mp, mp>("", + "MULTIPOLYGON(((0 0,0 4,4 4,4 0,0 0)))", + "MULTIPOLYGON(((6 6,6 10,10 10,10 6,6 6)))", + true); + + // Touch -> not disjoint + test_disjoint<mp, mp>("", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)))", + "MULTIPOLYGON(((5 5,5 10,10 10,10 5,5 5)))", + false); + + // Not disjoint but no IP's + test_disjoint<mp, mp>("no_ips", + "MULTIPOLYGON(((2 2,2 8,8 8,8 2,2 2)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((22 2,28 2,28 8,22 8,22 2)))", + false); + + // Not disjoint and not inside each other (in first ring) but wrapped (in second rings) + test_disjoint<mp, mp>("no_ips2", + "MULTIPOLYGON(((2 2,2 8,8 8,8 2,2 2)),((20 0,20 10,30 10,30 0,20 0)))", + "MULTIPOLYGON(((2 12,2 18,8 18,8 12,2 12)),((22 2,28 2,28 8,22 8,22 2)))", + false); + + test_disjoint<mp, mp>("no_ips2_rev", + "MULTIPOLYGON(((2 12,2 18,8 18,8 12,2 12)),((22 2,28 2,28 8,22 8,22 2)))", + "MULTIPOLYGON(((2 2,2 8,8 8,8 2,2 2)),((20 0,20 10,30 10,30 0,20 0)))", + false); + + + test_disjoint<P, mp>("point_mp1", + "POINT(0 0)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + false); + + test_disjoint<P, mp>("point_mp2", + "POINT(5 5)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + false); + + test_disjoint<P, mp>("point_mp1", + "POINT(11 11)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + true); + + std::string polygon_inside_hole("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0), (2 2,8 2,8 8,2 8,2 2)),((4 4,4 6,6 6,6 4,4 4)))"); + test_disjoint<P, mp>("point_mp_pih1", + "POINT(5 5)", + polygon_inside_hole, + false); + + test_disjoint<P, mp>("point_mp_pih2", + "POINT(3 3)", + polygon_inside_hole, + true); + + test_disjoint<mp, P>("point_mp1rev", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + "POINT(0 0)", + false); + + // assertion failure in 1.57 + test_disjoint<ls, mls>("point_l_ml_assert_1_57", + "LINESTRING(-2305843009213693956 4611686018427387906, -33 -92, 78 83)", + "MULTILINESTRING((20 100, 31 -97, -46 57, -20 -4))", + false); + test_disjoint<ls, mls>("point_l_ml_assert_1_57", + "LINESTRING(-2305843009213693956 4611686018427387906, -33 -92, 78 83)", + "MULTILINESTRING((20 100, 31 -97, -46 57, -20 -4),(-71 -4))", + false); +} + +int test_main(int, char* []) +{ + //test_all<bg::model::d2::point_xy<float> >(); + test_all<bg::model::d2::point_xy<double> >(); + +#ifdef HAVE_TTMATH + test_all<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + return 0; +} + + +/* +with viewy as +( +select geometry::STGeomFromText('MULTIPOLYGON(((2 2,2 8,8 8,8 2,2 2)),((20 0,20 10,30 10,30 0,20 0)))',0) as p + , geometry::STGeomFromText('MULTIPOLYGON(((2 12,2 18,8 18,8 12,2 12)),((22 2,28 2,28 8,22 8,22 2)))',0) as q +) + select p from viewy union all select q from viewy +-- select p.STDisjoint(q) from viewy +*/ diff --git a/libs/geometry/test/algorithms/relational_operations/disjoint/test_disjoint.hpp b/libs/geometry/test/algorithms/relational_operations/disjoint/test_disjoint.hpp new file mode 100644 index 000000000..55a22e9bd --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/disjoint/test_disjoint.hpp @@ -0,0 +1,63 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, 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) + +#ifndef BOOST_GEOMETRY_TEST_DISJOINT_HPP +#define BOOST_GEOMETRY_TEST_DISJOINT_HPP + +#include <iostream> +#include <string> +#include <boost/variant/variant.hpp> + +#include <geometry_test_common.hpp> + +#include <boost/geometry/algorithms/disjoint.hpp> +#include <boost/geometry/multi/algorithms/disjoint.hpp> +#include <boost/geometry/multi/io/wkt/read.hpp> + + +template <typename G1, typename G2> +void check_disjoint(std::string const& id, + G1 const& g1, + G2 const& g2, + bool expected) +{ + bool detected = bg::disjoint(g1, g2); + BOOST_CHECK_MESSAGE(detected == expected, + "disjoint: " << id + << " -> Expected: " << expected + << " detected: " << detected); +} + +template <typename G1, typename G2> +void test_disjoint(std::string const& id, + std::string const& wkt1, + std::string const& wkt2, bool expected) +{ + G1 g1; + bg::read_wkt(wkt1, g1); + + G2 g2; + bg::read_wkt(wkt2, g2); + + boost::variant<G1> v1(g1); + boost::variant<G2> v2(g2); + + check_disjoint(id, g1, g2, expected); + check_disjoint(id, v1, g2, expected); + check_disjoint(id, g1, v2, expected); + check_disjoint(id, v1, v2, expected); +} + + +#endif // BOOST_GEOMETRY_TEST_DISJOINT_HPP diff --git a/libs/geometry/test/algorithms/relational_operations/equals.cpp b/libs/geometry/test/algorithms/relational_operations/equals.cpp new file mode 100644 index 000000000..3fc067646 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/equals.cpp @@ -0,0 +1,259 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2013, 2014. +// Modifications copyright (c) 2013-2014 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_equals.hpp" + +#include <boost/type_traits/is_floating_point.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + + +namespace bgm = bg::model; + +template <typename P> +void test_segment_segment() +{ + typedef bgm::segment<P> seg; + + test_geometry<seg, seg>("seg2d_1", "LINESTRING(0 0, 3 3)", "LINESTRING(0 0, 3 3)", true); + test_geometry<seg, seg>("seg2d_1", "LINESTRING(0 0, 3 3)", "LINESTRING(3 3, 0 0)", true); + + test_geometry<seg, seg>("seg2d_1", "LINESTRING(0 0, 3 3)", "LINESTRING(0 0, 1 1)", false); + test_geometry<seg, seg>("seg2d_1", "LINESTRING(0 0, 3 3)", "LINESTRING(3 3, 2 2)", false); + + test_geometry<seg, seg>("seg2d_1", "LINESTRING(0 0, 3 3)", "LINESTRING(1 1, 4 4)", false); + test_geometry<seg, seg>("seg2d_1", "LINESTRING(0 0, 3 3)", "LINESTRING(1 0, 2 0)", false); +} + +template <typename P> +void test_linestring_linestring() +{ + typedef bgm::linestring<P> ls; + + test_geometry<ls, ls>("ls2d_1", "LINESTRING(1 1, 3 3)", "LINESTRING(3 3, 1 1)", true); + test_geometry<ls, ls>("ls2d_2", "LINESTRING(1 1, 3 3, 2 5)", "LINESTRING(1 1, 2 2, 3 3, 2 5)", true); + test_geometry<ls, ls>("ls2d_3", "LINESTRING(1 0, 3 3, 2 5)", "LINESTRING(1 1, 2 2, 3 3, 2 5)", false); + test_geometry<ls, ls>("ls2d_4", "LINESTRING(1 0, 3 3, 2 5)", "LINESTRING(1 1, 3 3, 2 5)", false); + test_geometry<ls, ls>("ls2d_5", "LINESTRING(0 5,5 5,10 5,10 0,5 0,5 5,5 10,10 10,15 10,15 5,10 5,10 10,10 15)", + "LINESTRING(0 5,15 5,15 10,5 10,5 0,10 0,10 15)", true); + test_geometry<ls, ls>("ls2d_6", "LINESTRING(0 5,5 5,10 5,10 10,5 10,5 5,5 0)", "LINESTRING(0 5,5 5,5 10,10 10,10 5,5 5,5 0)", true); + test_geometry<ls, ls>("ls2d_7", "LINESTRING(0 5,10 5,10 10,5 10,5 0)", "LINESTRING(0 5,5 5,5 10,10 10,10 5,5 5,5 0)", true); + test_geometry<ls, ls>("ls2d_8", "LINESTRING(0 0,5 0,5 0,6 0)", "LINESTRING(0 0,6 0)", true); + + test_geometry<ls, ls>("ls2d_seg", "LINESTRING(1 1,2 2)", "LINESTRING(1 1,2 2)", true); + test_geometry<ls, ls>("ls2d_rev", "LINESTRING(1 1,2 2)", "LINESTRING(2 2,1 1)", true); + + test_geometry<ls, ls>("ls2d_spike", "LINESTRING(0 0,5 0,3 0,6 0)", "LINESTRING(0 0,6 0)", true); + + test_geometry<ls, ls>("ls2d_ring1", "LINESTRING(0 0,5 0,5 5,0 5,0 0)", "LINESTRING(5 5,0 5,0 0,5 0,5 5)", true); + test_geometry<ls, ls>("ls2d_ring2", "LINESTRING(0 0,5 0,5 5,0 5,0 0)", "LINESTRING(5 5,5 0,0 0,0 5,5 5)", true); + test_geometry<ls, ls>("ls2d_overl_ring1", "LINESTRING(0 0,5 0,5 5,0 5,0 0)", "LINESTRING(5 5,0 5,0 0,5 0,5 5,0 5)", true); + test_geometry<ls, ls>("ls2d_overl_ring2", "LINESTRING(0 0,5 0,5 5,0 5,0 0)", "LINESTRING(5 5,5 0,0 0,0 5,5 5,5 0)", true); + + // https://svn.boost.org/trac/boost/ticket/10904 + if ( BOOST_GEOMETRY_CONDITION( + boost::is_floating_point<typename bg::coordinate_type<ls>::type>::value ) ) + { + test_geometry<ls, ls>("ls2d_small1", + "LINESTRING(5.6956521739130430148634331999347 -0.60869565217391330413931882503675,5.5 -0.50000000000000066613381477509392)", + "LINESTRING(5.5 -0.50000000000000066613381477509392,5.5 -0.5)", + false); + + test_geometry<ls, ls>("ls2d_small2", + "LINESTRING(-3.2333333333333333925452279800083 5.5999999999999978683717927196994,-3.2333333333333333925452279800083 5.5999999999999996447286321199499)", + "LINESTRING(-3.2333333333333325043668082798831 5.5999999999999996447286321199499,-3.2333333333333333925452279800083 5.5999999999999996447286321199499)", + false); + } +} + +template <typename P> +void test_linestring_multilinestring() +{ + typedef bgm::linestring<P> ls; + typedef bgm::multi_linestring<ls> mls; + + test_geometry<ls, mls>("ls_mls_1", "LINESTRING(0 0,1 0,2 0)", "MULTILINESTRING((0 0,2 0))", true); + test_geometry<ls, mls>("ls_mls_1", "LINESTRING(0 0,1 0,2 0)", "MULTILINESTRING((0 0,1 0),(1 0,2 0))", true); + test_geometry<ls, mls>("ls_mls_1", "LINESTRING(0 0,2 0,4 0)", "MULTILINESTRING((0 0,2 0),(2 0,3 0),(3 0,4 0))", true); + test_geometry<ls, mls>("ls_mls_1", "LINESTRING(0 0,2 0,4 0)", "MULTILINESTRING((0 0,2 0),(2 0,3 0),(2 0,3 0),(3 0,4 0))", true); + test_geometry<ls, mls>("ls_mls_1", "LINESTRING(0 0,2 0,4 0)", "MULTILINESTRING((0 0,2 0),(3 0,4 0))", false); + + test_geometry<ls, mls>("ls_mls_spike", "LINESTRING(0 0,2 0,2 2,2 0,4 0)", "MULTILINESTRING((0 0,4 0),(2 2,2 0))", true); + test_geometry<ls, mls>("ls_mls_spike", "LINESTRING(0 0,2 0,2 2,2 0,4 0)", "MULTILINESTRING((0 0,4 0),(2 2,2 -1))", false); + + test_geometry<ls, mls>("ls_mls_ring1", "LINESTRING(0 0,5 0,5 5,0 5,0 0)", "MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5))", true); + test_geometry<ls, mls>("ls_mls_ring2", "LINESTRING(0 0,5 0,5 5,0 5,0 0)", "MULTILINESTRING((5 5,5 0,0 0),(0 0,0 5,5 5))", true); + test_geometry<ls, mls>("ls_mls_overl_ring1", "LINESTRING(0 0,5 0,5 5,0 5,0 0)", "MULTILINESTRING((5 5,0 5,0 0),(0 0,5 0,5 5,0 5))", true); + test_geometry<ls, mls>("ls_mls_overl_ring2", "LINESTRING(0 0,5 0,5 5,0 5,0 0)", "MULTILINESTRING((5 5,5 0,0 0),(0 0,0 5,5 5,5 0))", true); +} + +template <typename P> +void test_multilinestring_multilinestring() +{ + typedef bgm::linestring<P> ls; + typedef bgm::multi_linestring<ls> mls; + + test_geometry<mls, mls>("ls_mls_mls", + "MULTILINESTRING((0 5,10 5,10 10,5 10),(5 10,5 0,5 2),(5 2,5 5,0 5))", + "MULTILINESTRING((5 5,0 5),(5 5,5 0),(10 10,10 5,5 5,5 10,10 10))", + true); +} + +template <typename P> +void test_all() +{ + typedef bg::model::box<P> box; + typedef bg::model::ring<P> ring; + typedef bg::model::polygon<P> polygon; + //typedef bg::model::linestring<P> linestring; + + std::string case_p1 = "POLYGON((0 0,0 2,2 2,0 0))"; + + test_geometry<P, P>("p1", "POINT(1 1)", "POINT(1 1)", true); + test_geometry<P, P>("p2", "POINT(1 1)", "POINT(1 2)", false); + test_geometry<box, box>("b1", "BOX(1 1,2 2)", "BOX(1 2,2 2)", false); + test_geometry<box, box>("b1", "BOX(1 2,3 4)", "BOX(1 2,3 4)", true); + + // Completely equal + test_geometry<ring, ring>("poly_eq", case_p1, case_p1, true); + + // Shifted + test_geometry<ring, ring>("poly_sh", "POLYGON((2 2,0 0,0 2,2 2))", case_p1, true); + test_geometry<polygon, polygon>("poly_sh2", case_p1, "POLYGON((0 2,2 2,0 0,0 2))", true); + + // Extra coordinate + test_geometry<ring, ring>("poly_extra", case_p1, "POLYGON((0 0,0 2,2 2,1 1,0 0))", true); + + // Shifted + extra (redundant) coordinate + test_geometry<ring, ring>("poly_shifted_extra1", "POLYGON((2 2,1 1,0 0,0 2,2 2))", case_p1, true); + + // Shifted + extra (redundant) coordinate being first/last point + test_geometry<ring, ring>("poly_shifted_extra2", "POLYGON((1 1,0 0,0 2,2 2,1 1))", case_p1, true); + + // Degenerate (duplicate) points + test_geometry<ring, ring>("poly_degenerate", "POLYGON((0 0,0 2,2 2,2 2,0 0))", "POLYGON((0 0,0 2,0 2,2 2,0 0))", true); + + // Two different bends, same area, unequal + test_geometry<ring, ring>("poly_bends", + "POLYGON((4 0,5 3,8 4,7 7,4 8,0 4,4 0))", + "POLYGON((4 0,7 1,8 4,5 5,4 8,0 4,4 0))", false); + + // Unequal (but same area) + test_geometry<ring, ring>("poly_uneq", case_p1, "POLYGON((1 1,1 3,3 3,1 1))", false); + + // One having hole + test_geometry<polygon, polygon>("poly_hole", "POLYGON((0 0,0 4,4 4,0 0))", "POLYGON((0 0,0 4,4 4,0 0),(1 1,2 1,2 2,1 2,1 1))", false); + + // Both having holes + test_geometry<polygon, polygon>("poly_holes", + "POLYGON((0 0,0 4,4 4,0 0),(1 1,2 1,2 2,1 2,1 1))", + "POLYGON((0 0,0 4,4 4,0 0),(1 1,2 1,2 2,1 2,1 1))", true); + + // Both having holes, outer equal, inner not equal + test_geometry<polygon, polygon>("poly_uneq_holes", + "POLYGON((0 0,0 4,4 4,0 0),(1 1,2 1,2 2,1 2,1 1))", + "POLYGON((0 0,0 4,4 4,0 0),(2 2,3 2,3 3,2 3,2 2))", false); + + // Both having 2 holes, equal but in different order + test_geometry<polygon, polygon>("poly_holes_diff_order", + "POLYGON((0 0,0 4,4 4,0 0),(1 1,2 1,2 2,1 2,1 1),(2 2,3 2,3 3,2 3,2 2))", + "POLYGON((0 0,0 4,4 4,0 0),(2 2,3 2,3 3,2 3,2 2),(1 1,2 1,2 2,1 2,1 1))", true); + + // Both having 3 holes, equal but in different order + test_geometry<polygon, polygon>("poly_holes_diff_order_3", + "POLYGON((0 0,0 10,10 10,0 0),(1 1,2 1,2 2,1 2,1 1),(4 1,5 1,5 2,4 2,4 1),(2 2,3 2,3 3,2 3,2 2))", + "POLYGON((0 0,0 10,10 10,0 0),(4 1,5 1,5 2,4 2,4 1),(2 2,3 2,3 3,2 3,2 2),(1 1,2 1,2 2,1 2,1 1))", true); + + // polygon/ring vv + test_geometry<polygon, ring>("poly_sh2_pr", case_p1, case_p1, true); + test_geometry<ring, polygon>("poly_sh2_rp", case_p1, case_p1, true); + + // box/ring/poly + test_geometry<box, ring>("boxring1", "BOX(1 1,2 2)", "POLYGON((1 1,1 2,2 2,2 1,1 1))", true); + test_geometry<ring, box>("boxring2", "POLYGON((1 1,1 2,2 2,2 1,1 1))", "BOX(1 1,2 2)", true); + test_geometry<box, polygon>("boxpoly1", "BOX(1 1,2 2)", "POLYGON((1 1,1 2,2 2,2 1,1 1))", true); + test_geometry<polygon, box>("boxpoly2", "POLYGON((1 1,1 2,2 2,2 1,1 1))", "BOX(1 1,2 2)", true); + + test_geometry<polygon, box>("boxpoly2", "POLYGON((1 1,1 2,2 2,2 1,1 1))", "BOX(1 1,2 3)", false); + + test_geometry<polygon, polygon>("poly_holes_shifted_points", + "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))", + "POLYGON((0 0,0 3,3 3,3 0,0 0),(2 2,1 2,1 1,2 1,2 2))", true); + + test_segment_segment<P>(); + test_linestring_linestring<P>(); + test_linestring_multilinestring<P>(); + test_multilinestring_multilinestring<P>(); +} + + +template <typename T> +void verify() +{ + T dxn1, dyn1, dxn2, dyn2; + + { + T x1 = "0", y1 = "0", x2 = "3", y2 = "3"; + T dx = x2 - x1, dy = y2 - y1; + T mag = sqrt(dx * dx + dy * dy); + dxn1 = dx / mag; + dyn1 = dy / mag; + } + + { + T x1 = "0", y1 = "0", x2 = "1", y2 = "1"; + T dx = x2 - x1, dy = y2 - y1; + T mag = sqrt(dx * dx + dy * dy); + dxn2 = dx / mag; + dyn2 = dy / mag; + } + + if (dxn1 == dxn2 && dyn1 == dyn2) + { + //std::cout << "vectors are equal, using ==" << std::endl; + } + if (boost::geometry::math::equals(dxn1, dxn2) + && boost::geometry::math::equals(dyn1, dyn2)) + { + //std::cout << "vectors are equal, using bg::math::equals" << std::endl; + } + + bool equals = boost::geometry::math::equals_with_epsilon(dxn1, dxn2) + && boost::geometry::math::equals_with_epsilon(dyn1, dyn2); + + if (equals) + { + //std::cout << "vectors are equal, using bg::math::equals_with_epsilon" << std::endl; + } + + BOOST_CHECK_EQUAL(equals, true); +} + + +int test_main( int , char* [] ) +{ + //verify<double>(); +#if defined(HAVE_TTMATH) + verify<ttmath_big>(); +#endif + + test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/intersects.cpp b/libs/geometry/test/algorithms/relational_operations/intersects.cpp new file mode 100644 index 000000000..8a2f9cf14 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/intersects.cpp @@ -0,0 +1,357 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// 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 "test_intersects.hpp" + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +#include <boost/geometry/util/rational.hpp> + +template <typename P> +void test_intersects_polygon_polygon() +{ + typedef bg::model::polygon<P, false, false> poly_ccw_o; + test_geometry<poly_ccw_o, poly_ccw_o>("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<poly_ccw_o, poly_ccw_o>("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<poly_ccw_o, poly_ccw_o>("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 <typename P> +void test_intersects_linestring_segment() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::segment<P> seg; + + test_geometry<ls, seg>("LINESTRING(1 1, 3 3, 2 5)", "SEGMENT(2 0, 2 6)", true); + test_geometry<ls, seg>("LINESTRING(1 1, 3 3)", "SEGMENT(1 0, 1 1)", true); + test_geometry<ls, seg>("LINESTRING(1 1, 3 3)", "SEGMENT(2 0, 2 2)", true); + test_geometry<ls, seg>("LINESTRING(1 1, 3 3)", "SEGMENT(3 0, 4 1)", false); +} + +template <typename P> +void test_intersects_linestring_linestring() +{ + typedef bg::model::linestring<P> ls; + + test_geometry<ls, ls>("LINESTRING(0 0,2 0,3 0)", "LINESTRING(0 0,1 1,2 2)", true); + test_geometry<ls, ls>("LINESTRING(0 0,2 0,3 0)", "LINESTRING(2 2,1 1,0 0)", true); + test_geometry<ls, ls>("LINESTRING(3 0,2 0,0 0)", "LINESTRING(0 0,1 1,2 2)", true); + test_geometry<ls, ls>("LINESTRING(3 0,2 0,0 0)", "LINESTRING(2 2,1 1,0 0)", true); + + test_geometry<ls, ls>("LINESTRING(0 0,2 0,3 0)", "LINESTRING(1 0,4 0,5 0)", true); + test_geometry<ls, ls>("LINESTRING(1 0,2 0)", "LINESTRING(1 0,0 0)", true); +} + +template <typename P> +void test_intersects_linestring_polygon() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::polygon<P> poly_cw_c; + typedef bg::model::polygon<P, false> poly_ccw_c; + typedef bg::model::polygon<P, false, false> poly_ccw_o; + typedef bg::model::multi_polygon<poly_ccw_c> mpoly_ccw_c; + + test_geometry<ls, poly_ccw_c>("LINESTRING(1 1,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); + test_geometry<ls, poly_ccw_c>("LINESTRING(1 0,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); + test_geometry<ls, poly_ccw_c>("LINESTRING(11 0,12 12)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", false); + + test_geometry<ls, poly_ccw_o>("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<ls, poly_ccw_o>("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<ls, poly_ccw_o>("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<poly_cw_c, ls>("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(-2 -2, 12 7)", true); + test_geometry<poly_cw_c, ls>("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(5 5, 15 4)", true); + test_geometry<poly_cw_c, ls>("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(7 6, 15 4)", true); + test_geometry<poly_cw_c, ls>("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", "LINESTRING(6 2, 12 1)", true); + + // MULTI + test_geometry<ls, mpoly_ccw_c>("LINESTRING(1 1,2 2)", "MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)))", true); + test_geometry<mls, mpoly_ccw_c>("MULTILINESTRING((1 1,2 2))", "MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)))", true); +} + +template <typename P> +void test_intersects_linestring_ring() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::ring<P, false> ring_ccw_c; + + test_geometry<ls, ring_ccw_c>("LINESTRING(1 1,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); + test_geometry<ls, ring_ccw_c>("LINESTRING(1 0,2 2)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); + test_geometry<ls, ring_ccw_c>("LINESTRING(11 0,12 12)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", false); + + // MULTI + test_geometry<mls, ring_ccw_c>("MULTILINESTRING((1 1,2 2))", "POLYGON((0 0,10 0,10 10,0 10,0 0))", true); +} + +template <typename P> +void test_intersects_ring_polygon() +{ + typedef bg::model::ring<P, false, false> ring_ccw_o; + typedef bg::model::polygon<P, false, false> poly_ccw_o; + + test_geometry<ring_ccw_o, poly_ccw_o>("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<ring_ccw_o, poly_ccw_o>("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<ring_ccw_o, poly_ccw_o>("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<ring_ccw_o, poly_ccw_o>("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 <typename P> +void test_intersects_point_linestring() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + + test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0,2 2,4 0)", true); + test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0,2 2,4 0)", true); + test_geometry<P, ls>("POINT(1 0)", "LINESTRING(0 0,2 2,4 0)", false); + + // MULTI + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,2 2,4 0))", true); +} + +template <typename P> +void test_intersects_point_segment() +{ + typedef bg::model::segment<P> seg; + + test_geometry<P, seg>("POINT(0 0)", "LINESTRING(0 0,2 2)", true); + test_geometry<P, seg>("POINT(1 1)", "LINESTRING(0 0,2 2)", true); + test_geometry<P, seg>("POINT(1 0)", "LINESTRING(0 0,2 2)", false); +} + +template <typename P> +void test_multi_linestring_polygon() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::polygon<P> poly; + + 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))", + true); + test_geometry<mls, poly>("MULTILINESTRING((10 0, 18 12),(2 2,2 1))", + "POLYGON((5 0,0 -5,-5 0,0 5,5 0))", + true); +} + +template <typename P> +void test_multi_polygon_polygon() +{ + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + test_geometry<mpoly, poly>("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 <typename P> +void test_all() +{ + typedef bg::model::polygon<P> polygon; + typedef bg::model::ring<P> ring; + + // intersect <=> ! disjoint (in most cases) + // so most tests are done in disjoint test. + // We only test compilation of a few cases. + test_geometry<P, bg::model::box<P> >("POINT(1 1)", "BOX(0 0,2 2)", true); + + test_geometry<polygon, bg::model::box<P> >( + "POLYGON((1992 3240,1992 1440,3792 1800,3792 3240,1992 3240))", + "BOX(1941 2066, 2055 2166)", true); + + test_geometry<ring, bg::model::box<P> >( + "POLYGON((1992 3240,1992 1440,3792 1800,3792 3240,1992 3240))", + "BOX(1941 2066, 2055 2166)", true); + + test_geometry<polygon, bg::model::box<P> >( + "POLYGON((1941 2066,2055 2066,2055 2166,1941 2166))", + "BOX(1941 2066, 2055 2166)", true); + + test_intersects_point_segment<P>(); + test_intersects_point_linestring<P>(); + test_intersects_polygon_polygon<P>(); + test_intersects_linestring_polygon<P>(); + test_intersects_linestring_ring<P>(); + test_intersects_linestring_segment<P>(); + test_intersects_linestring_linestring<P>(); + test_intersects_ring_polygon<P>(); + test_multi_linestring_polygon<P>(); + test_multi_polygon_polygon<P>(); + + // self-intersecting is not tested in disjoint, so that is done here. + + // Just a normal polygon + test_self_intersects<polygon>("POLYGON((0 0,0 4,1.5 2.5,2.5 1.5,4 0,0 0))", false); + + // Self intersecting + test_self_intersects<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))", true); + + // Self intersecting in last segment + test_self_intersects<polygon>("POLYGON((0 2,2 4,2 0,4 2,0 2))", true); + + // Self tangent + test_self_intersects<polygon>("POLYGON((0 0,0 4,4 4,4 0,2 4,0 0))", true); + + // Self tangent in corner + test_self_intersects<polygon>("POLYGON((0 0,0 4,4 4,4 0,0 4,2 0,0 0))", true); + + // With spike + test_self_intersects<polygon>("POLYGON((0 0,0 4,4 4,4 2,6 2,4 2,4 0,0 0))", true); + + // Non intersection, but with duplicate + test_self_intersects<polygon>("POLYGON((0 0,0 4,4 0,4 0,0 0))", false); + + // With many duplicates + test_self_intersects<polygon>( + "POLYGON((0 0,0 1,0 1,0 1,0 2,0 2,0 3,0 3,0 3,0 3,0 4,2 4,2 4,4 4,4 0,4 0,3 0,3 0,3 0,3 0,3 0,0 0))", + false); + + // Hole: interior tangent to exterior + test_self_intersects<polygon>("POLYGON((0 0,0 4,4 4,4 0,0 0),(1 2,2 4,3 2,1 2))", true); + + // Hole: interior intersecting exterior + test_self_intersects<polygon>("POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,1 3,5 4,1 1))", true); + + // Hole: two intersecting holes + test_self_intersects<polygon>( + "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,1 3,3 3,3 1,1 1),(2 2,2 3.5,3.5 3.5,3.5 2,2 2))", true); + + // Mail Akira T on [Boost-users] at 27-7-2011 3:17 + test_self_intersects<bg::model::linestring<P> >( + "LINESTRING(0 0,0 4,4 4,2 2,2 5)", true); + + test_self_intersects<bg::model::linestring<P> >( + "LINESTRING(0 4,4 4,2 2,2 5)", true); + + // Test self-intersections at last segment in close/open rings: + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,3 3,4 1,0 0))", false); + + test_self_intersects<bg::model::ring<P, true, false> >( + "POLYGON((0 0,3 3,4 1))", false); + + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,3 3,4 1,0 1,0 0))", true); + + test_self_intersects<bg::model::ring<P, true, false> >( + "POLYGON((0 0,3 3,4 1,0 1))", true); + + // Duplicates in first or last + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,3 3,4 1,0 1,0 1,0 0))", true); + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,3 3,4 1,0 1,0 0,0 0))", true); + test_self_intersects<bg::model::ring<P, true, false> >( + "POLYGON((0 0,3 3,4 1,0 1,0 1))", true); + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,0 0,3 3,4 1,0 1,0 1,0 0))", true); + test_self_intersects<bg::model::ring<P, true, false> >( + "POLYGON((0 0,0 0,3 3,4 1,0 1,0 1))", true); + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,3 3,3 3,4 1,0 1,0 1,0 0))", true); + test_self_intersects<bg::model::ring<P, true, false> >( + "POLYGON((0 0,3 3,3 3,4 1,0 1,0 1))", true); + + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,3 3,4 1,0 0,0 0))", false); + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,3 3,4 1,4 1,0 0))", false); + test_self_intersects<bg::model::ring<P, true, false> >( + "POLYGON((0 0,3 3,4 1,4 1))", false); + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,0 0,3 3,4 1,0 0))", false); + test_self_intersects<bg::model::ring<P, true, false> >( + "POLYGON((0 0,0 0,3 3,4 1))", false); + test_self_intersects<bg::model::ring<P> >( + "POLYGON((0 0,3 3,3 3,4 1,0 0))", false); + test_self_intersects<bg::model::ring<P, true, false> >( + "POLYGON((0 0,3 3,3 3,4 1))", false); + + test_geometry<P, bg::model::box<P> >( + "POINT(0 0)", + "BOX(0 0,4 4)", + true); + test_geometry<P, bg::model::ring<P> >( + "POINT(0 0)", + "POLYGON((0 0,3 3,3 3,4 1))", + true); + test_geometry<P, bg::model::polygon<P> >( + "POINT(0 0)", + "POLYGON((0 0,3 3,3 3,4 1))", + true); + + test_geometry<bg::model::ring<P>, P>( + "POLYGON((0 0,3 3,3 3,4 1))", + "POINT(0 0)", + true); + test_geometry<bg::model::polygon<P>, P>( + "POLYGON((0 0,3 3,3 3,4 1))", + "POINT(0 0)", + true); +} + +// Those tests won't pass for rational<> because numeric_limits<> isn't specialized for this type +template <typename P> +void test_additional() +{ + test_geometry<bg::model::segment<P>, bg::model::box<P> >( + "SEGMENT(0 0,3 3)", + "BOX(1 2,3 5)", + true); + test_geometry<bg::model::segment<P>, bg::model::box<P> >( + "SEGMENT(1 1,2 3)", + "BOX(0 0,4 4)", + true); + test_geometry<bg::model::segment<P>, bg::model::box<P> >( + "SEGMENT(1 1,1 1)", + "BOX(1 0,3 5)", + true); + test_geometry<bg::model::segment<P>, bg::model::box<P> >( + "SEGMENT(0 1,0 1)", + "BOX(1 0,3 5)", + false); + test_geometry<bg::model::segment<P>, bg::model::box<P> >( + "SEGMENT(2 1,2 1)", + "BOX(1 0,3 5)", + true); + test_geometry<bg::model::linestring<P>, bg::model::box<P> >( + "LINESTRING(0 0,1 0,10 10)", + "BOX(1 2,3 5)", + true); + test_geometry<bg::model::linestring<P>, bg::model::box<P> >( + "LINESTRING(1 2)", + "BOX(0 0,3 5)", + true); +} + + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<double> >(); + test_additional<bg::model::d2::point_xy<double> >(); + +#if ! defined(BOOST_GEOMETRY_RESCALE_TO_ROBUST) + test_all<bg::model::d2::point_xy<boost::rational<int> > >(); +#endif + +#if defined(HAVE_TTMATH) + test_all<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + return 0; +} diff --git a/libs/geometry/test/algorithms/relational_operations/multi_covered_by.cpp b/libs/geometry/test/algorithms/relational_operations/multi_covered_by.cpp new file mode 100644 index 000000000..7489435b4 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/multi_covered_by.cpp @@ -0,0 +1,59 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2007-2012 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 <geometry_test_common.hpp> + +#include <boost/geometry/algorithms/correct.hpp> +#include <boost/geometry/algorithms/covered_by.hpp> + +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/multi/core/point_order.hpp> +#include <boost/geometry/multi/algorithms/covered_by.hpp> + +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> +#include <boost/geometry/multi/io/wkt/wkt.hpp> + +#include "test_covered_by.hpp" + + +template <typename P> +void test_all() +{ + typedef bg::model::multi_polygon<bg::model::polygon<P> > mp; + + // test multi-with-one-polygon (trivial case) + test_geometry<P, mp>("POINT(1 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", true); + test_geometry<P, mp>("POINT(3 3)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + test_geometry<P, mp>("POINT(0 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", true); + test_geometry<P, mp>("POINT(4 4)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + + // test if it is in one of them + std::string multi("MULTIPOLYGON(" + "((0 0,0 2,2 2,2 0,0 0))" + "((3 3,3 6,6 6,6 3,3 3))" + ")"); + test_geometry<P, mp>("POINT(4 4)", multi, true); + test_geometry<P, mp>("POINT(1 1)", multi, true); + test_geometry<P, mp>("POINT(0 1)", multi, true); +} + +int test_main( int , char* [] ) +{ + //test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/multi_equals.cpp b/libs/geometry/test/algorithms/relational_operations/multi_equals.cpp new file mode 100644 index 000000000..d1239d38f --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/multi_equals.cpp @@ -0,0 +1,57 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2010-2012 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_equals.hpp" + +#include <boost/geometry/multi/algorithms/area.hpp> +#include <boost/geometry/multi/algorithms/equals.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +#include <boost/geometry/multi/io/wkt/read.hpp> + + + +template <typename P> +void test_all() +{ + std::string case1 = "MULTIPOLYGON(((0 0,0 7,4 2,2 0,0 0)))"; + std::string case1_p = "POLYGON((0 0,0 7,4 2,2 0,0 0))"; + + typedef bg::model::polygon<P> polygon; + typedef bg::model::multi_polygon<polygon> mp; + test_geometry<mp, mp>("c1", case1, case1, true); + + test_geometry<mp, mp>("c2", + "MULTIPOLYGON(((0 0,0 7.01,4 2,2 0,0 0)))", + case1, false); + + // Different order == equal + test_geometry<mp, mp>("c3", + "MULTIPOLYGON(((0 0,0 7,4 2,2 0,0 0)),((10 10,10 12,12 10,10 10)))", + "MULTIPOLYGON(((10 10,10 12,12 10,10 10)),((0 0,0 7,4 2,2 0,0 0)))", + true); + + // check different types + test_geometry<polygon, mp>("c1_p_mp", case1_p, case1, true); + test_geometry<mp, polygon>("c1_mp_p", case1, case1_p, 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/libs/geometry/test/algorithms/relational_operations/multi_intersects.cpp b/libs/geometry/test/algorithms/relational_operations/multi_intersects.cpp new file mode 100644 index 000000000..1880064f8 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/multi_intersects.cpp @@ -0,0 +1,51 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2012 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 <iostream> +#include <string> + + +#include <geometry_test_common.hpp> + +#include "test_intersects.hpp" + +#include <boost/geometry.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +template <typename P> +void test_all() +{ + typedef bg::model::polygon<P> polygon; + typedef bg::model::multi_polygon<polygon> mp; + + test_geometry<mp, mp>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + true); + + test_geometry<P, mp>("POINT(0 0)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + true); + +} + +int test_main(int, char* []) +{ + //test_all<bg::model::d2::point_xy<float> >(); + 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/libs/geometry/test/algorithms/relational_operations/multi_touches.cpp b/libs/geometry/test/algorithms/relational_operations/multi_touches.cpp new file mode 100644 index 000000000..86456b04a --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/multi_touches.cpp @@ -0,0 +1,95 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2010-2012 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/multi/algorithms/area.hpp> +#include <boost/geometry/multi/algorithms/num_geometries.hpp> +#include <boost/geometry/multi/algorithms/within.hpp> +#include <boost/geometry/multi/algorithms/detail/sections/range_by_section.hpp> +#include <boost/geometry/multi/algorithms/detail/sections/sectionalize.hpp> +#include <boost/geometry/multi/algorithms/detail/for_each_range.hpp> +#include <boost/geometry/multi/core/closure.hpp> +#include <boost/geometry/multi/core/geometry_id.hpp> +#include <boost/geometry/multi/core/topological_dimension.hpp> +#include <boost/geometry/multi/core/ring_type.hpp> +#include <boost/geometry/multi/views/detail/range_type.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +#include <boost/geometry/multi/io/wkt/read.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/libs/geometry/test/algorithms/relational_operations/overlaps.cpp b/libs/geometry/test/algorithms/relational_operations/overlaps.cpp new file mode 100644 index 000000000..3d627af43 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/overlaps.cpp @@ -0,0 +1,124 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 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_pp() +{ + typedef bg::model::multi_point<P> mpt; + + 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_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); +} + +template <typename P> +void test_2d() +{ + test_pp<P>(); + test_ll<P>(); + test_aa<P>(); + + 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/libs/geometry/test/algorithms/relational_operations/relate/Jamfile.v2 b/libs/geometry/test/algorithms/relational_operations/relate/Jamfile.v2 new file mode 100644 index 000000000..7e6bb61c9 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/relate/Jamfile.v2 @@ -0,0 +1,23 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +# +# This file was modified by Oracle on 2014. +# Modifications copyright (c) 2014, 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-relate + : + [ run relate_areal_areal.cpp ] + [ run relate_linear_areal.cpp ] + [ run relate_linear_linear.cpp ] + [ run relate_pointlike_xxx.cpp ] + ; diff --git a/libs/geometry/test/algorithms/relational_operations/relate/relate_areal_areal.cpp b/libs/geometry/test/algorithms/relational_operations/relate/relate_areal_areal.cpp new file mode 100644 index 000000000..bae133d07 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/relate/relate_areal_areal.cpp @@ -0,0 +1,411 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 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_relate.hpp" + +//#include <to_svg.hpp> + +template <typename P> +void test_polygon_polygon() +{ + typedef bg::model::polygon<P> poly; + typedef bg::model::ring<P> ring; + + // touching + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((10 0,10 10,20 10,20 0,10 0))", + "FF2F11212"); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((0 -10,0 0,10 0,10 -10,0 -10))", + "FF2F11212"); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((10 0,15 10,20 10,20 0,10 0))", + "FF2F01212"); + + // containing + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((5 5,5 10,6 10,6 5,5 5))", + "212F11FF2"); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((5 5,5 10,6 5,5 5))", + "212F01FF2"); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((5 5,5 6,6 6,6 5,5 5))", + "212FF1FF2"); + + // fully containing + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((5 5,5 9,6 9,6 5,5 5))", + "212FF1FF2"); + // fully containing, with a hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(3 3,7 3,7 7,3 7,3 3))", + "POLYGON((1 1,1 9,9 9,9 1,1 1))", + "2121F12F2"); + // fully containing, both with holes + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(3 3,7 3,7 7,3 7,3 3))", + "POLYGON((1 1,1 9,9 9,9 1,1 1),(2 2,8 2,8 8,2 8,2 2))", + "212FF1FF2"); + // fully containing, both with holes + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(3 3,7 3,7 7,3 7,3 3))", + "POLYGON((1 1,1 9,9 9,9 1,1 1),(4 4,6 4,6 6,4 6,4 4))", + "2121F1212"); + + // overlapping + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((5 0,5 10,20 10,20 0,5 0))", + "212111212"); + test_geometry<ring, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((5 0,5 10,20 10,20 0,5 0))", + "212111212"); + test_geometry<ring, ring>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((5 0,5 10,20 10,20 0,5 0))", + "212111212"); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,15 5,10 0,0 0))", + "POLYGON((10 0,5 5,10 10,20 10,20 0,10 0))", + "212101212"); + + // equal + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((10 10,10 5,10 0,5 0,0 0,0 10,5 10,10 10))", + "2FFF1FFF2"); + // hole-sized + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(5 5,6 5,6 6,5 6,5 5))", + "POLYGON((5 5,5 6,6 6,6 5,5 5))", + "FF2F112F2"); + + // disjoint + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((0 20,0 30,10 30,10 20,0 20))", + "FF2FF1212"); + // disjoint + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(3 3,7 3,7 7,3 7,3 3))", + "POLYGON((0 20,0 30,10 30,10 20,0 20))", + "FF2FF1212"); + + // equal non-simple / non-simple hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(5 5,10 5,5 6,5 5))", + "POLYGON((0 0,0 10,10 10,10 5,5 6,5 5,10 5,10 0,0 0))", + "2FFF1FFF2"); + + // within non-simple / simple + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 5,5 6,5 5,10 5,10 0,0 0))", + "POLYGON((0 0,5 5,10 5,10 0,0 0))", + "212F11FF2"); + // within non-simple hole / simple + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(5 5,10 5,5 6,5 5))", + "POLYGON((0 0,5 5,10 5,10 0,0 0))", + "212F11FF2"); + + + // not within non-simple / simple + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 5,5 6,5 5,10 5,10 0,0 0))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + "2FF11F2F2"); + // not within non-simple hole / simple + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(5 5,10 5,5 6,5 5))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + "2FF11F2F2"); + // not within simple hole / simple + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(5 5,9 5,5 6,5 5))", + "POLYGON((0 0,0 10,10 10,9 5,10 0,0 0))", + "2121112F2"); + + // within non-simple fake hole / simple + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 5,4 7,4 3,10 5,10 0,0 0))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + "2FF11F2F2"); + // within non-simple fake hole / non-simple fake hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 5,4 7,4 3,10 5,10 0,0 0))", + "POLYGON((0 0,0 10,10 10,10 5,5 6,5 4,10 5,10 0,0 0))", + "2FF11F212"); + // within non-simple fake hole / non-simple hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 5,4 7,4 3,10 5,10 0,0 0))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,5 6,5 4,10 5))", + "2FF11F212"); + // containing non-simple fake hole / non-simple hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 5,4 7,4 3,10 5,10 0,0 0))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,3 8,3 2,10 5))", + "212F11FF2"); + + // within non-simple hole / simple + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,4 7,4 3,10 5))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + "2FF11F2F2"); + // within non-simple hole / non-simple fake hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,4 7,4 3,10 5))", + "POLYGON((0 0,0 10,10 10,10 5,5 6,5 4,10 5,10 0,0 0))", + "2FF11F212"); + // containing non-simple hole / non-simple fake hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,4 7,4 3,10 5))", + "POLYGON((0 0,0 10,10 10,10 5,3 8,3 2,10 5,10 0,0 0))", + "212F11FF2"); + // equal non-simple hole / non-simple fake hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,4 7,4 3,10 5))", + "POLYGON((0 0,0 10,10 10,10 5,4 7,4 3,10 5,10 0,0 0))", + "2FFF1FFF2"); + // within non-simple hole / non-simple hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,4 7,4 3,10 5))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,5 6,5 4,10 5))", + "2FF11F212"); + // containing non-simple hole / non-simple hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,4 7,4 3,10 5))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,3 8,3 2,10 5))", + "212F11FF2"); + // equal non-simple hole / non-simple hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,4 7,4 3,10 5))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,4 7,4 3,10 5))", + "2FFF1FFF2"); + + // intersecting non-simple hole / non-simple hole - touching holes + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(5 5,10 5,5 6,5 5))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(0 5,5 4,5 5,0 5))", + "21211F2F2"); + // intersecting non-simple fake hole / non-simple hole - touching holes + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 5,5 6,5 5,10 5,10 0,0 0))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(0 5,5 4,5 5,0 5))", + "21211F2F2"); + // intersecting non-simple fake hole / non-simple fake hole - touching holes + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 5,5 6,5 5,10 5,10 0,0 0))", + "POLYGON((0 0,0 5,5 4,5 5,0 5,0 10,10 10,10 0,0 0))", + "21211F2F2"); + + // intersecting simple - i/i + test_geometry<poly, poly>("POLYGON((0 0,0 10,4 10,6 8,5 5,6 2,4 0,0 0))", + "POLYGON((5 5,4 8,6 10,10 10,10 0,6 0,4 2,5 5))", + "212101212"); + // intersecting non-simple hole / non-simple hole - i/i + test_geometry<poly, poly>("POLYGON((0 0,0 10,4 10,6 8,5 5,6 2,4 0,0 0),(5 5,2 6,2 4,5 5))", + "POLYGON((5 5,4 8,6 10,10 10,10 0,6 0,4 2,5 5),(5 5,8 4,8 6,5 5))", + "212101212"); + // intersecting non-simple hole / simple - i/i + test_geometry<poly, poly>("POLYGON((0 0,0 10,4 10,6 8,5 5,6 2,4 0,0 0),(5 5,2 6,2 4,5 5))", + "POLYGON((5 5,4 8,6 10,10 10,10 0,6 0,4 2,5 5))", + "212101212"); + + // no turns - disjoint inside a hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(1 1,9 1,9 9,1 9,1 1))", + "POLYGON((3 3,3 7,7 7,7 3,3 3))", + "FF2FF1212"); + // no turns - within + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(1 1,9 1,9 9,1 9,1 1))", + "POLYGON((-1 -1,-1 11,11 11,11 -1,-1 -1))", + "2FF1FF212"); + // no-turns - intersects + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,8 2,8 8,2 8,2 2))", + "POLYGON((1 1,1 9,9 9,9 1,1 1))", + "2121F12F2"); + // no-turns - intersects, hole in a hole + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,8 2,8 8,2 8,2 2))", + "POLYGON((1 1,1 9,9 9,9 1,1 1),(3 3,7 3,7 7,3 7,3 3))", + "2121F1212"); + + // no-turns ring - for exteriors + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,8 2,8 8,2 8,2 2))", + "POLYGON((1 1,1 9,9 9,9 1,1 1),(2 2,8 2,8 8,2 8,2 2))", + "212F11FF2"); + // no-turns ring - for interiors + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(3 3,7 3,7 7,3 7,3 3))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,8 2,8 8,2 8,2 2))", + "212F11FF2"); + + { + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((5 5,5 10,6 10,6 5,5 5))", + "212F11FF2"); + + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((10 0,10 10,20 10,20 0,10 0))", + "FF2F11212"); + + namespace bgdr = bg::detail::relate; + poly p1, p2, p3; + bg::read_wkt("POLYGON((0 0,0 10,10 10,10 0,0 0))", p1); + bg::read_wkt("POLYGON((10 0,10 10,20 10,20 0,10 0))", p2); + bg::read_wkt("POLYGON((5 5,5 10,6 10,6 5,5 5))", p3); + BOOST_CHECK(bgdr::relate(p1, p2, bgdr::mask9("FT*******") + || bgdr::mask9("F**T*****") + || bgdr::mask9("F***T****"))); // touches() + BOOST_CHECK(bgdr::relate(p1, p3, bgdr::mask9("T*****FF*"))); // contains() + BOOST_CHECK(bgdr::relate(p2, p3, bgdr::mask9("FF*FF****"))); // disjoint() + } + + // CCW + { + typedef bg::model::polygon<P, false> poly; + // within non-simple hole / simple + test_geometry<poly, poly>("POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,5 6,10 5,5 5))", + "POLYGON((0 0,10 0,10 5,5 5,0 0))", + "212F11FF2"); + } + // OPEN + { + typedef bg::model::polygon<P, true, false> poly; + // within non-simple hole / simple + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0),(5 5,10 5,5 6))", + "POLYGON((0 0,5 5,10 5,10 0))", + "212F11FF2"); + } + // CCW, OPEN + { + typedef bg::model::polygon<P, false, false> poly; + // within non-simple hole / simple + test_geometry<poly, poly>("POLYGON((0 0,10 0,10 10,0 10),(5 5,5 6,10 5))", + "POLYGON((0 0,10 0,10 5,5 5))", + "212F11FF2"); + } + + // https://svn.boost.org/trac/boost/ticket/10912 + { + // external rings touches and G2's hole is inside G1 + test_geometry<poly, poly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", + "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))", + "21211F212"); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,2 4,4 4,4 2,2 2))", + "212F1FFF2"); + // extended + // external rings touches and G1's hole is inside G2 + test_geometry<poly, poly>("POLYGON((0 0,0 9,9 9,9 0,0 0),(2 2,7 2,7 7,2 7,2 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + "2FF11F212"); + // external rings touches, holes doesn't + test_geometry<poly, poly>("POLYGON((0 0,0 9,9 9,9 0,0 0),(2 2,7 2,7 7,2 7,2 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(1 1,8 1,8 8,1 8,1 1))", + "212111212"); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,7 2,7 7,2 7,2 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(1 1,8 1,8 8,1 8,1 1))", + "212F11FF2"); + // holes touches, external rings doesn't + test_geometry<poly, poly>("POLYGON((1 1,1 9,9 9,9 1,1 1),(2 2,8 2,8 8,2 8,2 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,7 2,7 7,2 7,2 2))", + "2FF11F212"); + test_geometry<poly, poly>("POLYGON((1 1,1 9,9 9,9 1,1 1),(2 2,7 2,7 7,2 7,2 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,8 2,8 8,2 8,2 2))", + "212111212"); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,8 2,8 8,2 8,2 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,7 2,7 7,2 7,2 2))", + "2FF11F212"); + + test_geometry<poly, poly>("POLYGON((3 3,3 9,9 9,9 3,3 3))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2))", + "212101212"); + } + + if ( BOOST_GEOMETRY_CONDITION(( + boost::is_same<typename bg::coordinate_type<P>::type, double>::value )) ) + { + // original - assertion for CCW + //"POLYGON((-0.593220338983050821113352 -8.05084745762711939676137,1.14285714285714279370154 -4,1.50731707317073171381594 1.10243902439024443751237,1.73758865248226967992196 1.37588652482269591104114,1.21739130434782616418943 -3.82608695652173924628414,2 -2,2 1.68750000000000044408921,2.35384615384615436539661 2.10769230769230775379697,2 2.16666666666666651863693,2 4,1.81967213114754100544701 2.1967213114754100544701,1.5882352941176469673934 2.2352941176470588757752,1.8148148148148146585612 5.4074074074074074403029,-0.538461538461538546940233 4.23076923076923083755219,-1.76510067114094004736558 2.89261744966443012927471,-1.64864864864864868465588 2.7567567567567570208098,-1.83962264150943455298659 2.81132075471698161805989,-1.84337349397590433142113 2.80722891566265086993326,-2.14285714285714279370154 2.85714285714285720629846,-2.11111111111111116045436 2.88888888888888883954564,-2.87234042553191448732264 3.10638297872340407579372,-2.91803278688524558859285 3.4262295081967208965068,-3.1733333333333324510761 3.26666666666666660745477,-2.99999999999999822364316 3.14285714285714234961233,-3.25490196078431326398572 3.21568627450980359938626,-3.47368421052631504153396 3.07894736842105265495206,-7.32000000000000028421709 3.72000000000000019539925,-7.54716981132075481752963 3.62264150943396234794136,-7.75 3.79166666666666651863693,-7.79999999999999982236432 3.79999999999999982236432,-7.59999999999999964472863 3.60000000000000008881784,-8.8556701030927822415606 3.06185567010309300783888,-8.82945736434108674473009 2.8914728682170549589614,-7.73333333333333339254523 2.193939393939393855959,-8 2,-5.94736842105263185942476 -1.42105263157894645686952,-5.32558139534883689947264 -0.488372093023255016142059,-5.85714285714285765038767 1.00000000000000066613381,-4.78723404255319184841255 0.319148936170212838003835,-5.32558139534883689947264 -0.488372093023255016142059,-4.74019607843137258385013 -2.12745098039215774221589,-3.17647058823529437887601 -0.705882352941176627325603,-2.93103448275862055183438 -0.862068965517241436735674,-3 -1,-4.57894736842105309904127 -2.57894736842105265495206,-4.47887323943661996850096 -2.85915492957746497637572,-7.58620689655172419918472 -5.18965517241379359347775,-7.52525252525252508206677 -5.5858585858585865224768,-4.18644067796610119813749 -3.67796610169491522412955,-3.44041450777202051369841 -5.76683937823834202873741,-3.73611111111111116045436 -6.56944444444444464181743,-2.8823529411764705621124 -7.7647058823529411242248,-2.88235294117647100620161 -7.7647058823529411242248,-0.593220338983050821113352 -8.05084745762711939676137),(1.66666666666666696272614 1.59999999999999875655021,1.43749999999999911182158 1.8750000000000002220446,0.0869565217391310429917439 2.26086956521739113057379,0.466666666666667118157363 2.60606060606060552231611,1.04878048780487764801705 2.34146341463414664474385,1.43749999999999911182158 1.8750000000000002220446,1.56756756756756754356275 1.83783783783783771781373,1.66666666666666696272614 1.59999999999999875655021))" + //"POLYGON((-2.33333333333333303727386 -8.66666666666666607454772,-2.26315789473684203514381 -8.63157894736842123961651,-2.88235294117647100620161 -7.7647058823529411242248,-2.8823529411764705621124 -7.7647058823529411242248,-4.11949685534591125701809 -7.61006289308176064878353,-4.32530120481927671249878 -8.16867469879518104391991,-2.33333333333333303727386 -8.66666666666666607454772))" + + // assertion failure in 1.57 + test_geometry<poly, poly>("POLYGON((-0.59322033898305082 -8.0508474576271194,-2.882352941176471 -7.7647058823529411,-2.8823529411764706 -7.7647058823529411,-3.7361111111111112 -6.5694444444444446,-3.4404145077720205 -5.766839378238342,-4.1864406779661012 -3.6779661016949152,-7.5252525252525251 -5.5858585858585865,-7.5862068965517242 -5.1896551724137936,-4.47887323943662 -2.859154929577465,-4.5789473684210531 -2.5789473684210527,-3 -1,-2.9310344827586206 -0.86206896551724144,-3.1764705882352944 -0.70588235294117663,-4.7401960784313726 -2.1274509803921577,-5.3255813953488369 -0.48837209302325502,-4.7872340425531918 0.31914893617021284,-5.8571428571428577 1.0000000000000007,-5.3255813953488369 -0.48837209302325502,-5.9473684210526319 -1.4210526315789465,-8 2,-7.7333333333333334 2.1939393939393939,-8.8294573643410867 2.891472868217055,-8.8556701030927822 3.061855670103093,-7.5999999999999996 3.6000000000000001,-7.7999999999999998 3.7999999999999998,-7.75 3.7916666666666665,-7.5471698113207548 3.6226415094339623,-7.3200000000000003 3.7200000000000002,-3.473684210526315 3.0789473684210527,-3.2549019607843133 3.2156862745098036,-2.9999999999999982 3.1428571428571423,-3.1733333333333325 3.2666666666666666,-2.9180327868852456 3.4262295081967209,-2.8723404255319145 3.1063829787234041,-2.1111111111111112 2.8888888888888888,-2.1428571428571428 2.8571428571428572,-1.8433734939759043 2.8072289156626509,-1.8396226415094346 2.8113207547169816,-1.6486486486486487 2.756756756756757,-1.76510067114094 2.8926174496644301,-0.53846153846153855 4.2307692307692308,1.8148148148148147 5.4074074074074074,1.588235294117647 2.2352941176470589,1.819672131147541 2.1967213114754101,2 4,2 2.1666666666666665,2.3538461538461544 2.1076923076923078,2 1.6875000000000004,2 -2,1.2173913043478262 -3.8260869565217392,1.7375886524822697 1.3758865248226959,1.5073170731707317 1.1024390243902444,1.1428571428571428 -4,-0.59322033898305082 -8.0508474576271194),(1.666666666666667 1.5999999999999988,1.5675675675675675 1.8378378378378377,1.4374999999999991 1.8750000000000002,1.0487804878048776 2.3414634146341466,0.46666666666666712 2.6060606060606055,0.086956521739131043 2.2608695652173911,1.4374999999999991 1.8750000000000002,1.666666666666667 1.5999999999999988))", + "POLYGON((-2.333333333333333 -8.6666666666666661,-4.3253012048192767 -8.168674698795181,-4.1194968553459113 -7.6100628930817606,-2.8823529411764706 -7.7647058823529411,-2.882352941176471 -7.7647058823529411,-2.263157894736842 -8.6315789473684212,-2.333333333333333 -8.6666666666666661))", + "*********"); + // simpler case + test_geometry<poly, poly>("POLYGON((0 0, -0.59322033898305082 -8.0508474576271194, -2.8823529411764710 -7.7647058823529411, -3.7361111111111112 -6.5694444444444446, 0 0))", + "POLYGON((-10 -10, -4.1194968553459113 -7.6100628930817606, -2.8823529411764706 -7.7647058823529411, -2.2631578947368420 -8.6315789473684212, -10 -10))", + "FF2F01212"); + // sanity check + test_geometry<poly, poly>("POLYGON((0 0, -0.59322033898305082 -8.0508474576271194, -2.8823529411764710 -7.7647058823529411, -3.7361111111111112 -6.5694444444444446, 0 0))", + "POLYGON((-10 -10, -4.1194968553459113 -7.6100628930817606, -2.8823529411764710 -7.7647058823529411, -2.2631578947368420 -8.6315789473684212, -10 -10))", + "FF2F01212"); + + // compatibility check + /*test_geometry<poly, poly>("POLYGON((0 0,0 1,1 1,1 0,0 0))", + "POLYGON((1 1,1 2,2 2,2 1,1 1))", + "****0****"); + test_geometry<P, P>("POINT(0.9999999999999998 0.9999999999999998)", + "POINT(1 1)", + "0********"); + test_geometry<P, P>("POINT(0.9999999999999995 0.9999999999999995)", + "POINT(1 1)", + "F********"); + test_geometry<poly, poly>("POLYGON((0 0,0 1,0.9999999999999998 0.9999999999999998,1 0,0 0))", + "POLYGON((1 1,1 2,2 2,2 1,1 1))", + "****0****"); + test_geometry<poly, poly>("POLYGON((0 0,0 1,0.9999999999999995 0.9999999999999995,1 0,0 0))", + "POLYGON((1 1,1 2,2 2,2 1,1 1))", + "****F****");*/ + } +} + +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<poly, mpoly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "MULTIPOLYGON(((5 5,5 10,6 10,6 5,5 5)),((0 20,0 30,10 30,10 20,0 20)))", + "212F11212"); + test_geometry<ring, mpoly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "MULTIPOLYGON(((5 5,5 10,6 10,6 5,5 5)),((0 20,0 30,10 30,10 20,0 20)))", + "212F11212"); + + 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))", + "212F11FF2"); + test_geometry<poly, mpoly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "2FF11F212"); + test_geometry<poly, mpoly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", + "MULTIPOLYGON(((0 0,0 -10,-10 -10,-10 0,0 0)),((0 0,0 10,10 10,10 0,0 0)))", + "2FF11F212"); + test_geometry<poly, mpoly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "2FFF1F212"); +} + +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>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + "MULTIPOLYGON(((5 5,5 10,6 10,6 5,5 5)),((0 20,0 30,10 30,10 20,0 20)))", + "212F11212"); + test_geometry<mpoly, mpoly>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 20,0 30,10 30,10 20,0 20)))", + "MULTIPOLYGON(((5 5,5 10,6 10,6 5,5 5)))", + "212F11FF2"); + + test_geometry<mpoly, mpoly>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + "MULTIPOLYGON(((5 5,5 6,6 6,6 5,5 5)),((0 20,0 30,10 30,10 20,0 20)))", + "212FF1212"); + test_geometry<mpoly, mpoly>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 20,0 30,10 30,10 20,0 20)))", + "MULTIPOLYGON(((5 5,5 6,6 6,6 5,5 5)))", + "212FF1FF2"); +} + +template <typename P> +void test_all() +{ + test_polygon_polygon<P>(); + test_polygon_multi_polygon<P>(); + test_multi_polygon_multi_polygon<P>(); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/relate/relate_linear_areal.cpp b/libs/geometry/test/algorithms/relational_operations/relate/relate_linear_areal.cpp new file mode 100644 index 000000000..fbd399f01 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/relate/relate_linear_areal.cpp @@ -0,0 +1,518 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 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_relate.hpp" + +//TEST +//#include <to_svg.hpp> + +template <typename P> +void test_linestring_polygon() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::polygon<P> poly; + typedef bg::model::ring<P> ring; + + // LS disjoint + test_geometry<ls, poly>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "FF1FF0212"); + test_geometry<ls, ring>("LINESTRING(11 0,11 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "FF1FF0212"); + + // II BB + test_geometry<ls, poly>("LINESTRING(0 0,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1FFF0F212"); + test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1FFF0F212"); + test_geometry<ls, poly>("LINESTRING(5 1,5 5,9 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1FF0FF212"); + + // IE + test_geometry<ls, poly>("LINESTRING(11 1,11 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "FF1FF0212"); + // IE IB0 + test_geometry<ls, poly>("LINESTRING(11 1,10 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "FF1F00212"); + // IE IB1 + test_geometry<ls, poly>("LINESTRING(11 1,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212"); + test_geometry<ls, poly>("LINESTRING(11 1,10 10,0 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212"); + test_geometry<ls, poly>("LINESTRING(11 1,10 0,0 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212"); + test_geometry<ls, poly>("LINESTRING(0 -1,1 0,2 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212"); + // IE IB0 II + test_geometry<ls, poly>("LINESTRING(11 1,10 5,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1010F0212"); + // IE IB0 lring + test_geometry<ls, poly>("LINESTRING(11 1,10 5,11 5,11 1)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F01FFF212"); + // IE IB1 lring + test_geometry<ls, poly>("LINESTRING(11 1,10 5,10 10,11 5,11 1)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11FFF212"); + + // IB1 II + test_geometry<ls, poly>("LINESTRING(0 0,5 0,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11F00F212"); + // BI0 II IB1 + test_geometry<ls, poly>("LINESTRING(5 0,5 5,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11FF0F212"); + + // IB1 II IB1 + test_geometry<ls, poly>("LINESTRING(1 0,2 0,3 1,4 0,5 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11FF0F212"); + // IB1 IE IB1 + test_geometry<ls, poly>("LINESTRING(1 0,2 0,3 -1,4 0,5 0)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F0F212"); + + // II IB1 + test_geometry<ls, poly>("LINESTRING(5 5,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11F00F212"); + // IB1 II + test_geometry<ls, poly>("LINESTRING(10 10,10 5,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "11F00F212"); + // IE IB1 + test_geometry<ls, poly>("LINESTRING(15 5,10 5,10 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212"); + // IB1 IE + test_geometry<ls, poly>("LINESTRING(10 10,10 5,15 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "F11F00212"); + + // duplicated points + { + // II IB0 IE + test_geometry<ls, poly>("LINESTRING(5 5,10 5,15 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1010F0212"); + test_geometry<ls, poly>("LINESTRING(5 5,5 5,5 5,10 5,10 5,10 5,15 10,15 10,15 10)", + "POLYGON((0 0,0 0,0 0,0 10,0 10,0 10,10 10,10 10,10 10,10 0,10 0,10 0,0 0,0 0,0 0))", + "1010F0212"); + test_geometry<ls, poly>("LINESTRING(5 5,5 5,5 5,10 0,10 0,10 0,15 10,15 10,15 10)", + "POLYGON((0 0,0 0,0 0,0 10,0 10,0 10,10 10,10 10,10 10,10 0,10 0,10 0,0 0,0 0,0 0))", + "1010F0212"); + // IE IB0 II + test_geometry<ls, poly>("LINESTRING(15 10,15 10,15 10,10 5,10 5,10 5,5 5,5 5,5 5)", + "POLYGON((0 0,0 0,0 0,0 10,0 10,0 10,10 10,10 10,10 10,10 0,10 0,10 0,0 0,0 0,0 0))", + "1010F0212"); + test_geometry<ls, poly>("LINESTRING(15 10,15 10,15 10,10 0,10 0,10 0,5 5,5 5,5 5)", + "POLYGON((0 0,0 0,0 0,0 10,0 10,0 10,10 10,10 10,10 10,10 0,10 0,10 0,0 0,0 0,0 0))", + "1010F0212"); + + // TEST + //test_geometry<ls, poly>("LINESTRING(5 5,5 5,5 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1010F0212"); + test_geometry<ls, poly>("LINESTRING(5 5,5 5,5 5,15 5,15 5,15 5)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", "1010F0212"); + } + + // non-simple polygon with hole + 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))", + "10F0FF212"); + test_geometry<ls, poly>("LINESTRING(10 1,10 5,10 9)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))", + "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(2 8,10 5,2 2)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))", + "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(10 1,10 5,2 2)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))", + "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(10 1,10 5,2 8)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))", + "F1FF0F212"); + + // non-simple polygon with hole, linear ring + 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))", + "10FFFF212"); + test_geometry<ls, poly>("LINESTRING(10 5,10 9,11 5,10 1,10 5)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))", + "F11FFF212"); + test_geometry<ls, poly>("LINESTRING(11 5,10 1,10 5,10 9,11 5)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5))", + "F11FFF212"); + + // non-simple polygon with self-touching holes + test_geometry<ls, poly>("LINESTRING(7 1,8 5,7 9)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(8 1,9 1,9 9,8 9,8 1),(2 2,8 5,2 8,2 2))", + "10F0FF212"); + test_geometry<ls, poly>("LINESTRING(8 2,8 5,8 8)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(8 1,9 1,9 9,8 9,8 1),(2 2,8 5,2 8,2 2))", + "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(2 8,8 5,2 2)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(8 1,9 1,9 9,8 9,8 1),(2 2,8 5,2 8,2 2))", + "F1FF0F212"); + + // non-simple polygon self-touching + test_geometry<ls, poly>("LINESTRING(9 1,10 5,9 9)", + "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))", + "10F0FF212"); + test_geometry<ls, poly>("LINESTRING(10 1,10 5,10 9)", + "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))", + "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(2 8,10 5,2 2)", + "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))", + "F1FF0F212"); + + // non-simple polygon self-touching, linear ring + 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 5,2 8,2 2,10 5,10 0,0 0))", + "10FFFF212"); + test_geometry<ls, poly>("LINESTRING(10 5,10 9,11 5,10 1,10 5)", + "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))", + "F11FFF212"); + test_geometry<ls, poly>("LINESTRING(11 5,10 1,10 5,10 9,11 5)", + "POLYGON((0 0,0 10,10 10,10 5,2 8,2 2,10 5,10 0,0 0))", + "F11FFF212"); + + // polygons with some ring equal to the linestring + 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))", + "F1FFFF2F2"); + 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),(2 2,5 5,2 8,2 2))", + "F1FFFF212"); + test_geometry<ls, poly>("LINESTRING(2 2,5 5,2 8,2 2)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,5 5,2 8,2 2))", + "F1FFFF212"); + + // self-IP going on the boundary then into the exterior and to the boundary again + test_geometry<ls, poly>("LINESTRING(2 10,5 10,5 15,6 15,5 10,8 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", + "F11F0F212"); + // self-IP going on the boundary then into the interior and to the boundary again + test_geometry<ls, poly>("LINESTRING(2 10,5 10,5 5,6 5,5 10,8 10)", "POLYGON((0 0,0 10,10 10,10 0,0 0))", + "11FF0F212"); + + // self-IP with a hole -> B to I to B to E + test_geometry<ls, poly>("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))", + "FF1F00212"); + + // ccw + { + typedef bg::model::polygon<P, false> ccwpoly; + + // IE IB0 II + test_geometry<ls, ccwpoly>("LINESTRING(11 1,10 5,5 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1010F0212"); + // IE IB1 II + test_geometry<ls, ccwpoly>("LINESTRING(11 1,10 1,10 5,5 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1110F0212"); + test_geometry<ls, ccwpoly>("LINESTRING(11 1,10 5,10 1,5 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1110F0212"); + // II IB0 IE + test_geometry<ls, ccwpoly>("LINESTRING(5 1,10 5,11 1)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1010F0212"); + // IE IB1 II + test_geometry<ls, ccwpoly>("LINESTRING(5 5,10 1,10 5,11 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1110F0212"); + test_geometry<ls, ccwpoly>("LINESTRING(5 5,10 5,10 1,11 5)", "POLYGON((0 0,10 0,10 10,0 10,0 0))", "1110F0212"); + + } + + { + // SPIKES + + test_geometry<ls, poly>("LINESTRING(0 0,2 2,3 3,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(0 0,3 3,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(0 0,2 2,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(1 1,3 3,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(1 1,2 2,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FFFF212"); + + test_geometry<ls, poly>("LINESTRING(3 3,1 1,0 0,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(3 3,0 0,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(2 2,0 0,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(3 3,1 1,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FF0F212"); + test_geometry<ls, poly>("LINESTRING(2 2,1 1,2 2)", "POLYGON((0 0,3 3,3 0,0 0))", "F1FFFF212"); + + test_geometry<ls, poly>("LINESTRING(0 0,2 2,4 4,1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F11F0F212"); + + test_geometry<ls, poly>("LINESTRING(0 1,1 1,0 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F01FFF212"); + test_geometry<ls, poly>("LINESTRING(0 1,3 3,0 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F01FFF212"); + test_geometry<ls, poly>("LINESTRING(0 1,0 0,0 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F01FFF212"); + + test_geometry<ls, poly>("LINESTRING(0 1,1 1,-1 1)", "POLYGON((0 0,3 3,3 0,0 0))", "F01FF0212"); + } + + { + // POLYGON SPIKES + // note that those are invalid Polygons and in general the result is undefined + + // MySQL bug 15.12.2014 (assertion for invalid polygon) + test_geometry<ls, poly>("LINESTRING(6 3,9 0)", + "POLYGON((0 0,5 8,6 1,6 3,8 1,5 4,9 6,2 5,7 4,1 7,0 0))", + "F11F00212"); + test_geometry<ls, poly>("LINESTRING(9 0,2 7)", + "POLYGON((4 1,3 2,5 9,8 4,4 5,3 6,8 1,6 2,2 4,6 0,4 1))", + "F11FF0212"); + + test_geometry<ls, poly>("LINESTRING(6 3,9 0)", + "POLYGON((6 1,6 3,8 1,5 4,6 1))", + "F11F00212"); + test_geometry<ls, poly>("LINESTRING(6 3,8 1,9 0)", + "POLYGON((6 1,6 3,8 1,5 4,6 1))", + "F11F00212"); + + // entry-point spikes are not handled + test_geometry<ls, poly>("LINESTRING(9 0,6 3)", + "POLYGON((6 1,6 3,8 1,5 4,6 1))", + "**1*00212"); + test_geometry<ls, poly>("LINESTRING(9 0,8 1,6 3)", + "POLYGON((6 1,6 3,8 1,5 4,6 1))", + "F11F00212"); + + // Ls going out-in on 2 collinear spikes touching each other + // this works partially, other invalid effect is noticeable here, + // the bottom of a spike shouldn't be there so the algorithm + // thinks the linestring is going into the interior + test_geometry<ls, poly>("LINESTRING(2 2,6 6)", + "POLYGON((0 0,0 2,2 2,4 4,3 3,5 3,5 5,4 4,7 7,7 0,0 0))", + "*1FF0F212"); + // Ls going out-in on 2 collinear spikes NOT touching each other + // This is not supported, plus the same as above + test_geometry<ls, poly>("LINESTRING(2 2,6 6)", + "POLYGON((0 0,0 2,2 2,3 3,2 2,5 3,5 5,4 4,7 7,7 0,0 0))", + "*1*F0*212"); + } + + // 21.01.2015 + test_geometry<ls, poly>("LINESTRING(3 7, 9 1)", + "POLYGON((0 0,0 10,10 10,10 0,5 5,0 0))", + "11F00F212"); + + // inspired by the bug for mls/poly + test_geometry<ls, poly>("LINESTRING(0 0, 7 7)", + "POLYGON((5 5,5 15,15 15,15 5,5 5))", + "1010F0212"); + + // 25.01.2015 + test_geometry<ls, poly>("LINESTRING(4 5, 0 6, 5 6)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))", + "11FF0F212"); + test_geometry<ls, poly>("LINESTRING(2 3, 4 5, 0 6, 5 6)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))", + "11F00F212"); + test_geometry<ls, poly>("LINESTRING(2 9, 1 1, 10 1, 10 10, 1 10, 0 6, 5 6)", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,4 6,6 6,6 4,4 4))", + "11F00F212"); +} + +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)))", + "F1FF0F212"); + 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)))", + "F1FF0F212"); + + test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,2 2)", + "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)))", + "F1FF0F212"); + test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,2 2)", + "MULTIPOLYGON(((0 20,0 30,10 30,10 20,0 20)),((0 0,0 10,10 10,10 0,0 0)))", + "11F00F212"); + + test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,2 2)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))", + "F1FF0F212"); + test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,2 8)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))", + "F1FF0F212"); + test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,3 3)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))", + "F1FF0F212"); + test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,3 7)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))", + "F1FF0F212"); + test_geometry<ls, mpoly>("LINESTRING(10 1,10 5,5 5)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(10 5,2 8,2 2,10 5)),((10 5,3 3,3 7,10 5)))", + "11F00F212"); + + test_geometry<ls, mpoly>("LINESTRING(0 0,10 0,10 10,0 10,0 0)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((20 0,20 10,30 20,20 0)))", + "F1FFFF212"); + + // degenerated points + test_geometry<ls, mpoly>("LINESTRING(5 5,10 10,10 10,10 10,15 15)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((10 10,10 20,20 20,20 10,10 10)))", + "10F0FF212"); + + // self-IP polygon with a hole and second polygon with a hole -> B to I to B to B to I to B to E + test_geometry<ls, mpoly>("LINESTRING(0 0,3 3)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)),((0 0,2 8,8 8,8 2,0 0),(0 0,7 3,7 7,3 7,0 0)))", + "FF1F00212"); + // self-IP polygon with a hole and second polygon -> B to I to B to B to I + test_geometry<ls, mpoly>("LINESTRING(0 0,3 3)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)),((0 0,2 8,8 8,8 2,0 0)))", + "1FF00F212"); + test_geometry<ls, mpoly>("LINESTRING(0 0,3 3)", + "MULTIPOLYGON(((0 0,2 8,8 8,8 2,0 0)),((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 9,1 9,0 0)))", + "1FF00F212"); + + // MySQL report 18.12.2014 (https://svn.boost.org/trac/boost/ticket/10887) + test_geometry<ls, mpoly>("LINESTRING(5 -2,5 2)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + "10F0FF212"); + test_geometry<ls, mpoly>("LINESTRING(5 -2,5 5)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + "10F00F212"); + test_geometry<ls, mpoly>("LINESTRING(5 -2,5 0)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + "1FF00F212"); + // MySQL report 18.12.2014 - extended + test_geometry<ls, mpoly>("LINESTRING(5 -2,5 0)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)),((5 0,7 1,7 -1,5 0)))", + "1FF00F212"); + test_geometry<ls, mpoly>("LINESTRING(0 0,5 0)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)),((5 0,7 1,7 -1,5 0)))", + "FF1F00212"); + + // 22.01.2015 + test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,10 0)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "11F00F212"); + test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,0 10)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "11F00F212"); + // extended + test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,2 1)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "10F0FF212"); + test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,5 -5)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "1010F0212"); + test_geometry<ls, mpoly>("LINESTRING(5 5,0 0,5 -5,5 1)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "1010FF212"); + test_geometry<ls, mpoly>("LINESTRING(-5 5,0 0,5 -5)", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "F01FF0212"); +} + +template <typename P> +void test_multi_linestring_polygon() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::polygon<P> poly; + + 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))", + "1F10F0212"); + test_geometry<mls, poly>("MULTILINESTRING((10 0, 18 12),(2 2,2 1))", + "POLYGON((5 0,0 -5,-5 0,0 5,5 0))", + "1F10F0212"); + + if ( BOOST_GEOMETRY_CONDITION(( + boost::is_same<typename bg::coordinate_type<P>::type, double>::value )) ) + { + // assertion failure in 1.57 + test_geometry<mls, poly>("MULTILINESTRING((-0.59322033898305082 -8.0508474576271194,-2.882352941176471 -7.7647058823529411,-2.8823529411764706 -7.7647058823529411,-3.7361111111111112 -6.5694444444444446,-3.4404145077720205 -5.766839378238342,-4.1864406779661012 -3.6779661016949152,-7.5252525252525251 -5.5858585858585865,-7.5862068965517242 -5.1896551724137936,-4.47887323943662 -2.859154929577465,-4.5789473684210531 -2.5789473684210527,-3 -1,-2.9310344827586206 -0.86206896551724144,-3.1764705882352944 -0.70588235294117663,-4.7401960784313726 -2.1274509803921577,-5.3255813953488369 -0.48837209302325502,-4.7872340425531918 0.31914893617021284,-5.8571428571428577 1.0000000000000007,-5.3255813953488369 -0.48837209302325502,-5.9473684210526319 -1.4210526315789465,-8 2,-7.7333333333333334 2.1939393939393939,-8.8294573643410867 2.891472868217055,-8.8556701030927822 3.061855670103093,-7.5999999999999996 3.6000000000000001,-7.7999999999999998 3.7999999999999998,-7.75 3.7916666666666665,-7.5471698113207548 3.6226415094339623,-7.3200000000000003 3.7200000000000002,-3.473684210526315 3.0789473684210527,-3.2549019607843133 3.2156862745098036,-2.9999999999999982 3.1428571428571423,-3.1733333333333325 3.2666666666666666,-2.9180327868852456 3.4262295081967209,-2.8723404255319145 3.1063829787234041,-2.1111111111111112 2.8888888888888888,-2.1428571428571428 2.8571428571428572,-1.8433734939759043 2.8072289156626509,-1.8396226415094346 2.8113207547169816,-1.6486486486486487 2.756756756756757,-1.76510067114094 2.8926174496644301,-0.53846153846153855 4.2307692307692308,1.8148148148148147 5.4074074074074074,1.588235294117647 2.2352941176470589,1.819672131147541 2.1967213114754101,2 4,2 2.1666666666666665,2.3538461538461544 2.1076923076923078,2 1.6875000000000004,2 -2,1.2173913043478262 -3.8260869565217392,1.7375886524822697 1.3758865248226959,1.5073170731707317 1.1024390243902444,1.1428571428571428 -4,-0.59322033898305082 -8.0508474576271194),(1.666666666666667 1.5999999999999988,1.5675675675675675 1.8378378378378377,1.4374999999999991 1.8750000000000002,1.0487804878048776 2.3414634146341466,0.46666666666666712 2.6060606060606055,0.086956521739131043 2.2608695652173911,1.4374999999999991 1.8750000000000002,1.666666666666667 1.5999999999999988))", + "POLYGON((-2.333333333333333 -8.6666666666666661,-4.3253012048192767 -8.168674698795181,-4.1194968553459113 -7.6100628930817606,-2.8823529411764706 -7.7647058823529411,-2.882352941176471 -7.7647058823529411,-2.263157894736842 -8.6315789473684212,-2.333333333333333 -8.6666666666666661))", + "*********"); + test_geometry<mls, poly>("MULTILINESTRING((-2.333333333333333 -8.6666666666666661,-4.3253012048192767 -8.168674698795181,-4.1194968553459113 -7.6100628930817606,-2.8823529411764706 -7.7647058823529411,-2.882352941176471 -7.7647058823529411,-2.263157894736842 -8.6315789473684212,-2.333333333333333 -8.6666666666666661))", + "POLYGON((-0.59322033898305082 -8.0508474576271194,-2.882352941176471 -7.7647058823529411,-2.8823529411764706 -7.7647058823529411,-3.7361111111111112 -6.5694444444444446,-3.4404145077720205 -5.766839378238342,-4.1864406779661012 -3.6779661016949152,-7.5252525252525251 -5.5858585858585865,-7.5862068965517242 -5.1896551724137936,-4.47887323943662 -2.859154929577465,-4.5789473684210531 -2.5789473684210527,-3 -1,-2.9310344827586206 -0.86206896551724144,-3.1764705882352944 -0.70588235294117663,-4.7401960784313726 -2.1274509803921577,-5.3255813953488369 -0.48837209302325502,-4.7872340425531918 0.31914893617021284,-5.8571428571428577 1.0000000000000007,-5.3255813953488369 -0.48837209302325502,-5.9473684210526319 -1.4210526315789465,-8 2,-7.7333333333333334 2.1939393939393939,-8.8294573643410867 2.891472868217055,-8.8556701030927822 3.061855670103093,-7.5999999999999996 3.6000000000000001,-7.7999999999999998 3.7999999999999998,-7.75 3.7916666666666665,-7.5471698113207548 3.6226415094339623,-7.3200000000000003 3.7200000000000002,-3.473684210526315 3.0789473684210527,-3.2549019607843133 3.2156862745098036,-2.9999999999999982 3.1428571428571423,-3.1733333333333325 3.2666666666666666,-2.9180327868852456 3.4262295081967209,-2.8723404255319145 3.1063829787234041,-2.1111111111111112 2.8888888888888888,-2.1428571428571428 2.8571428571428572,-1.8433734939759043 2.8072289156626509,-1.8396226415094346 2.8113207547169816,-1.6486486486486487 2.756756756756757,-1.76510067114094 2.8926174496644301,-0.53846153846153855 4.2307692307692308,1.8148148148148147 5.4074074074074074,1.588235294117647 2.2352941176470589,1.819672131147541 2.1967213114754101,2 4,2 2.1666666666666665,2.3538461538461544 2.1076923076923078,2 1.6875000000000004,2 -2,1.2173913043478262 -3.8260869565217392,1.7375886524822697 1.3758865248226959,1.5073170731707317 1.1024390243902444,1.1428571428571428 -4,-0.59322033898305082 -8.0508474576271194),(1.666666666666667 1.5999999999999988,1.5675675675675675 1.8378378378378377,1.4374999999999991 1.8750000000000002,1.0487804878048776 2.3414634146341466,0.46666666666666712 2.6060606060606055,0.086956521739131043 2.2608695652173911,1.4374999999999991 1.8750000000000002,1.666666666666667 1.5999999999999988))", + "*********"); + } + + // 21.01.2015 + test_geometry<mls, poly>("MULTILINESTRING((6 6,15 15),(0 0, 7 7))", + "POLYGON((5 5,5 15,15 15,15 5,5 5))", + "101000212"); + test_geometry<mls, poly>("MULTILINESTRING((15 15,6 6),(0 0, 7 7))", + "POLYGON((5 5,5 15,15 15,15 5,5 5))", + "101000212"); + // extended + test_geometry<mls, poly>("MULTILINESTRING((15 15,6 6),(4 14,6 16))", + "POLYGON((5 5,5 15,15 15,15 5,5 5))", + "101000212"); + + // 23.01.2015 + test_geometry<mls, poly>("MULTILINESTRING((4 10, 3 10, 10 6),(5 0, 7 5, 9 10))", + "POLYGON((0 0,0 10,10 10,10 0,5 5,0 0))", + "111F00212"); + + // 23.01.2015 + test_geometry<mls, poly>("MULTILINESTRING((3 10, 1 5, 1 10, 3 4, 7 8, 6 10, 10 2))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", + "10FF0F212"); +} + +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; + + // polygons with some ring equal to the linestrings + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,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)))", + "F11FFF2F2"); + + 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)))", + "F1FFFF2F2"); + + + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,10 0,10 10),(10 10,0 10,0 0))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + "F1FFFF2F2"); + 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)))", + "F11FFF2F2"); + + // disjoint + test_geometry<mls, mpoly>("MULTILINESTRING((20 20,30 30),(30 30,40 40))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + "FF1FF0212"); + + test_geometry<mls, mpoly>("MULTILINESTRING((5 5,0 5),(5 5,5 0),(10 10,10 5,5 5,5 10,10 10))", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)),((5 5,10 1,10 0,5 5)))", + "F1FF0F212"); + test_geometry<mls, mpoly>("MULTILINESTRING((5 5,0 5),(5 5,5 0),(0 5,0 0,5 0),(10 10,10 5,5 5,5 10,10 10))", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)),((5 5,10 1,10 0,5 5)))", + "F1FFFF212"); + test_geometry<mls, mpoly>("MULTILINESTRING((5 5,0 0),(5 5,5 0),(10 10,10 5,5 5,5 10,10 10))", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)),((5 5,10 1,10 0,5 5)))", + "11FF0F212"); + + // MySQL report 18.12.2014 - extended + 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)))", + "10FFFF212"); + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,0 1,5 0),(0 0,0 -1,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + "F01FFF212"); + test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(6 -2,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + "10F0FF212"); + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,0 1,5 0),(0 -1,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + "F01FF0212"); + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,5 0),(5 -2,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + "1010F0212"); + test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,5 0),(0 0,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + "1010F0212"); + + // 22.01.2015 - extended + test_geometry<mls, mpoly>("MULTILINESTRING((10 10,0 10),(5 5,0 0,10 0))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "11F00F212"); + test_geometry<mls, mpoly>("MULTILINESTRING((5 5,0 0,5 -5),(0 0,9 1))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "101000212"); + test_geometry<mls, mpoly>("MULTILINESTRING((5 -5,0 0,5 5),(0 0,5 -1))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + "101000212"); +} + +template <typename P> +void test_all() +{ + test_linestring_polygon<P>(); + test_linestring_multi_polygon<P>(); + test_multi_linestring_polygon<P>(); + test_multi_linestring_multi_polygon<P>(); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/relate/relate_linear_linear.cpp b/libs/geometry/test/algorithms/relational_operations/relate/relate_linear_linear.cpp new file mode 100644 index 000000000..2794e89d4 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/relate/relate_linear_linear.cpp @@ -0,0 +1,433 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 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. + +// 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#include "test_relate.hpp" + +//TEST +//#include <to_svg.hpp> + +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)", "1FFF0FFF2"); + test_geometry<ls, ls>("LINESTRING(0 0,3 2)", "LINESTRING(0 0, 2 2, 3 2)", "FF1F0F1F2"); + test_geometry<ls, ls>("LINESTRING(1 0,2 2,2 3)", "LINESTRING(0 0, 2 2, 3 2)", "0F1FF0102"); + + test_geometry<ls, ls>("LINESTRING(0 0,5 0)", "LINESTRING(0 0,1 1,2 0,2 -1)", "0F1F00102"); + + test_geometry<ls, ls>("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", "1FFF0FFF2"); + test_geometry<ls, ls>("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(0 0, 2 2, 3 2)", "1FFF0FFF2"); + test_geometry<ls, ls>("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(3 2, 2 2, 0 0)", "1FFF0FFF2"); + test_geometry<ls, ls>("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(3 2, 2 2, 0 0)", "1FFF0FFF2"); + + test_geometry<ls, ls>("LINESTRING(3 1, 2 2, 1 1, 0 0)", "LINESTRING(0 0, 2 2, 3 2)", "1F1F00102"); + test_geometry<ls, ls>("LINESTRING(3 3, 2 2, 1 1, 0 0)", "LINESTRING(0 0, 2 2, 3 2)", "1F1F00102"); + + test_geometry<ls, ls>("LINESTRING(0 0, 1 1, 2 2, 2 3)", "LINESTRING(0 0, 2 2, 2 3)", "1FFF0FFF2"); + test_geometry<ls, ls>("LINESTRING(2 3, 2 2, 1 1, 0 0)", "LINESTRING(0 0, 2 2, 2 3)", "1FFF0FFF2"); + test_geometry<ls, ls>("LINESTRING(0 0, 1 1, 2 2, 2 3)", "LINESTRING(2 3, 2 2, 0 0)", "1FFF0FFF2"); + test_geometry<ls, ls>("LINESTRING(2 3, 2 2, 1 1, 0 0)", "LINESTRING(2 3, 2 2, 0 0)", "1FFF0FFF2"); + + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", "1FF0FF102"); + + test_geometry<ls, ls>("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(0 0, 2 2, 4 2)", "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(4 2, 2 2, 0 0)", "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(4 2, 2 2, 0 0)", "1FF0FF102"); + +// test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", true); + +// test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false); + +// test_geometry<ls, ls>("LINESTRING(0 1, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry<ls, ls>("LINESTRING(0 1, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry<ls, ls>("LINESTRING(1 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry<ls, ls>("LINESTRING(1 0, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); + +// test_geometry<ls, ls>("LINESTRING(0 0)", "LINESTRING(0 0)", false); +// test_geometry<ls, ls>("LINESTRING(1 1)", "LINESTRING(0 0, 2 2)", true); +// test_geometry<ls, ls>("LINESTRING(0 0)", "LINESTRING(0 0, 2 2)", false); +// test_geometry<ls, ls>("LINESTRING(0 0, 1 1)", "LINESTRING(0 0)", false); + +// test_geometry<ls, ls>("LINESTRING(0 0,5 0,3 0,6 0)", "LINESTRING(0 0,6 0)", true); +// test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,3 3,6 3)", true); + + // SPIKES! + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,1 1,5 3)", "LINESTRING(0 0,3 3,6 3)", "1F100F102"); + test_geometry<ls, ls>("LINESTRING(5 3,1 1,3 3,2 2,0 0)", "LINESTRING(0 0,3 3,6 3)", "1F100F102"); + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,1 1,5 3)", "LINESTRING(6 3,3 3,0 0)", "1F100F102"); + test_geometry<ls, ls>("LINESTRING(5 3,1 1,3 3,2 2,0 0)", "LINESTRING(6 3,3 3,0 0)", "1F100F102"); + + test_geometry<ls, ls>("LINESTRING(6 3,3 3,0 0)", "LINESTRING(0 0,2 2,3 3,1 1,5 3)", "101F001F2"); + + test_geometry<ls, ls>("LINESTRING(0 0,10 0)", "LINESTRING(1 0,9 0,2 0)", "101FF0FF2"); + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,3 3,6 3)", "1FF00F102"); + // TODO: REWRITE MATRICES + // BEGIN + /*test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,4 4,6 3)", "1FF00F102"); + + test_geometry<ls, ls>("LINESTRING(0 0,2 0,1 0)", "LINESTRING(0 1,0 0,2 0)", "1FF00F102"); + test_geometry<ls, ls>("LINESTRING(2 0,0 0,1 0)", "LINESTRING(0 1,0 0,2 0)", "1FF00F102"); + + test_geometry<ls, ls>("LINESTRING(0 0,3 3,1 1)", "LINESTRING(3 0,3 3,3 1)", "0F1FF0102"); + test_geometry<ls, ls>("LINESTRING(0 0,3 3,1 1)", "LINESTRING(2 0,2 3,2 1)", "0F1FF0102"); + test_geometry<ls, ls>("LINESTRING(0 0,3 3,1 1)", "LINESTRING(2 0,2 2,2 1)", "0F1FF0102"); + + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,4 4)", "LINESTRING(0 0,1 1,4 4)", "1FFF0FFF2");*/ + // END + + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,4 4)", "LINESTRING(0 0,1 1,4 4)", "1FFF0FFF2"); + + // loop i/i i/i u/u u/u + test_geometry<ls, ls>("LINESTRING(0 0,10 0)", + "LINESTRING(1 1,1 0,6 0,6 1,4 1,4 0,9 0,9 1)", "1F1FF0102"); + + // self-intersecting and self-touching equal + test_geometry<ls, ls>("LINESTRING(0 5,5 5,10 5,10 10,5 10,5 5,5 0)", + "LINESTRING(0 5,5 5,5 10,10 10,10 5,5 5,5 0)", "1FFF0FFF2"); + // self-intersecting loop and self-touching equal + test_geometry<ls, ls>("LINESTRING(0 5,5 5,10 5,10 10,5 10,5 5,10 5,10 10,5 10,5 5,5 0)", + "LINESTRING(0 5,5 5,5 10,10 10,10 5,5 5,5 0)", "1FFF0FFF2"); + + test_geometry<ls, ls>("LINESTRING(0 0,1 1)", "LINESTRING(0 1,1 0)", "0F1FF0102"); + test_geometry<ls, ls>("LINESTRING(0 0,1 1)", "LINESTRING(1 1,2 0)", "FF1F00102"); + test_geometry<ls, ls>("LINESTRING(0 0,1 1)", "LINESTRING(2 0,1 1)", "FF1F00102"); + + test_geometry<ls, ls>("LINESTRING(0 0,1 0,2 1,3 5,4 0)", "LINESTRING(1 0,2 1,3 5)", "101FF0FF2"); + test_geometry<ls, ls>("LINESTRING(0 0,1 0,2 1,3 5,4 0)", "LINESTRING(3 5,2 1,1 0)", "101FF0FF2"); + test_geometry<ls, ls>("LINESTRING(1 0,2 1,3 5)", "LINESTRING(4 0,3 5,2 1,1 0,0 0)", "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(3 5,2 1,1 0)", "LINESTRING(4 0,3 5,2 1,1 0,0 0)", "1FF0FF102"); + + test_geometry<ls, ls>("LINESTRING(0 0,10 0)", "LINESTRING(-1 -1,1 0,10 0,20 -1)", "1F10F0102"); + test_geometry<ls, ls>("LINESTRING(0 0,10 0)", "LINESTRING(20 -1,10 0,1 0,-1 -1)", "1F10F0102"); + + test_geometry<ls, ls>("LINESTRING(-1 1,0 0,1 0,5 0,5 5,10 5,15 0,31 0)", + "LINESTRING(-1 -1,0 0,1 0,2 0,3 1,4 0,30 0)", + "101FF0102"); + test_geometry<ls, ls>("LINESTRING(-1 1,0 0,1 0,5 0,5 5,10 5,15 0,31 0)", + "LINESTRING(30 0,4 0,3 1,2 0,1 0,0 0,-1 -1)", + "101FF0102"); + test_geometry<ls, ls>("LINESTRING(31 0,15 0,10 5,5 5,5 0,1 0,0 0,-1 1)", + "LINESTRING(-1 -1,0 0,1 0,2 0,3 1,4 0,30 0)", + "101FF0102"); + test_geometry<ls, ls>("LINESTRING(31 0,15 0,10 5,5 5,5 0,1 0,0 0,-1 1)", + "LINESTRING(30 0,4 0,3 1,2 0,1 0,0 0,-1 -1)", + "101FF0102"); + + // self-IP + test_geometry<ls, ls>("LINESTRING(1 0,9 0)", + "LINESTRING(0 0,10 0,10 10,5 0,0 10)", + "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(1 0,5 0,9 0)", + "LINESTRING(0 0,10 0,10 10,5 0,0 10)", + "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(1 0,9 0)", + "LINESTRING(0 0,10 0,10 10,5 10,5 -1)", + "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(1 0,9 0)", + "LINESTRING(0 0,10 0,5 0,5 5)", + "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(1 0,7 0)", "LINESTRING(0 0,10 0,10 10,4 -1)", + "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(1 0,5 0,7 0)", "LINESTRING(0 0,10 0,10 10,4 -1)", + "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(1 0,7 0,8 1)", "LINESTRING(0 0,10 0,10 10,4 -1)", + "1F10F0102"); + test_geometry<ls, ls>("LINESTRING(1 0,5 0,7 0,8 1)", "LINESTRING(0 0,10 0,10 10,4 -1)", + "1F10F0102"); + + // self-IP going out and in on the same point + test_geometry<ls, ls>("LINESTRING(2 0,5 0,5 5,6 5,5 0,8 0)", "LINESTRING(1 0,9 0)", + "1F10FF102"); + + // duplicated points + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", "1FF0FF102"); + test_geometry<ls, ls>("LINESTRING(1 1, 1 1, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", "1FF0FF102"); + + // linear ring + test_geometry<ls, ls>("LINESTRING(0 0,10 0)", "LINESTRING(5 0,9 0,5 5,1 0,5 0)", "1F1FF01F2"); + test_geometry<ls, ls>("LINESTRING(0 0,5 0,10 0)", "LINESTRING(5 0,9 0,5 5,1 0,5 0)", "1F1FF01F2"); + test_geometry<ls, ls>("LINESTRING(0 0,5 0,10 0)", "LINESTRING(5 0,10 0,5 5,1 0,5 0)", "1F10F01F2"); + + test_geometry<ls, ls>("LINESTRING(0 0,5 0)", "LINESTRING(5 0,10 0,5 5,0 0,5 0)", "1FF0FF1F2"); + test_geometry<ls, ls>("LINESTRING(0 0,5 0)", "LINESTRING(5 0,10 0,5 5,5 0)", "FF10F01F2"); + + test_geometry<ls, ls>("LINESTRING(1 0,1 6)", "LINESTRING(0 0,5 0,5 5,0 5)", "0F10F0102"); + + // point-size Linestring + test_geometry<ls, ls>("LINESTRING(1 0,1 0)", "LINESTRING(0 0,5 0)", "0FFFFF102"); + test_geometry<ls, ls>("LINESTRING(1 0,1 0)", "LINESTRING(1 0,5 0)", "F0FFFF102"); + test_geometry<ls, ls>("LINESTRING(1 0,1 0)", "LINESTRING(0 0,1 0)", "F0FFFF102"); + test_geometry<ls, ls>("LINESTRING(1 0,1 0)", "LINESTRING(1 0,1 0)", "0FFFFFFF2"); + test_geometry<ls, ls>("LINESTRING(1 0,1 0)", "LINESTRING(0 0,0 0)", "FF0FFF0F2"); + + //to_svg<ls, ls>("LINESTRING(0 0,5 0)", "LINESTRING(5 0,10 0,5 5,5 0)", "test_relate_00.svg"); + + // INVALID LINESTRINGS + // 1-point LS (a Point) NOT disjoint + //test_geometry<ls, ls>("LINESTRING(1 0)", "LINESTRING(0 0,5 0)", "0FFFFF102"); + //test_geometry<ls, ls>("LINESTRING(0 0,5 0)", "LINESTRING(1 0)", "0F1FF0FF2"); + //test_geometry<ls, ls>("LINESTRING(0 0,5 0)", "LINESTRING(1 0,1 0,1 0)", "0F1FF0FF2"); + // Point/Point + //test_geometry<ls, ls>("LINESTRING(0 0)", "LINESTRING(0 0)", "0FFFFFFF2"); + + if ( BOOST_GEOMETRY_CONDITION( + boost::is_floating_point<typename bg::coordinate_type<ls>::type>::value ) ) + { + // https://svn.boost.org/trac/boost/ticket/10904 + // very small segments + test_geometry<ls, ls>("LINESTRING(5.6956521739130430148634331999347 -0.60869565217391330413931882503675,5.5 -0.50000000000000066613381477509392)", + "LINESTRING(5.5 -0.50000000000000066613381477509392,5.5 -0.5)", + "FF1F00102"); + test_geometry<ls, ls>("LINESTRING(-3.2333333333333333925452279800083 5.5999999999999978683717927196994,-3.2333333333333333925452279800083 5.5999999999999996447286321199499)", + "LINESTRING(-3.2333333333333325043668082798831 5.5999999999999996447286321199499,-3.2333333333333333925452279800083 5.5999999999999996447286321199499)", + "FF1F00102", "F0FFFF102"); // on some platforms the first Linestring may be detected as degenerated to Point + + // detected as collinear + test_geometry<ls, ls>("LINESTRING(1 -10, 3.069359e+307 3.069359e+307)", + "LINESTRING(1 6, 1 0)", + "*********"); // TODO: be more specific with the result + } + + // OTHER MASKS + { + namespace bgdr = bg::detail::relate; + ls ls1, ls2, ls3, ls4; + bg::read_wkt("LINESTRING(0 0,2 0)", ls1); + bg::read_wkt("LINESTRING(2 0,4 0)", ls2); + bg::read_wkt("LINESTRING(1 0,1 1)", ls3); + bg::read_wkt("LINESTRING(1 0,4 0)", ls4); + BOOST_CHECK(bgdr::relate(ls1, ls2, bgdr::mask9("FT*******") + || bgdr::mask9("F**T*****") + || bgdr::mask9("F***T****"))); + BOOST_CHECK(bgdr::relate(ls1, ls3, bgdr::mask9("FT*******") + || bgdr::mask9("F**T*****") + || bgdr::mask9("F***T****"))); + BOOST_CHECK(bgdr::relate(ls3, ls1, bgdr::mask9("FT*******") + || bgdr::mask9("F**T*****") + || bgdr::mask9("F***T****"))); + BOOST_CHECK(bgdr::relate(ls2, ls4, bgdr::mask9("T*F**F***"))); // within + } + + // spike - boundary and interior on the same point + test_geometry<ls, ls>("LINESTRING(3 7, 8 8, 2 6)", "LINESTRING(5 7, 10 7, 0 7)", "0010F0102"); + + // 22.01.2015 + test_geometry<ls, ls>("LINESTRING(5 5,10 10)", "LINESTRING(6 6,3 3)", "1010F0102"); + test_geometry<ls, ls>("LINESTRING(5 5,2 8)", "LINESTRING(4 6,7 3)", "1010F0102"); +} + +template <typename P> +void test_linestring_multi_linestring() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + + // LS disjoint + test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,2 0),(1 1,2 1))", "101FF0102"); + // linear ring disjoint + test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,2 0),(1 1,2 1,2 2,1 1))", "101FF01F2"); + // 2xLS forming non-simple linear ring disjoint + test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,2 0),(1 1,2 1,2 2),(1 1,2 2))", "101FF01F2"); + + test_geometry<ls, mls>("LINESTRING(0 0,10 0)", + "MULTILINESTRING((1 0,9 0),(9 0,2 0))", + "101FF0FF2"); + + // rings + 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))", + "1FFFFFFF2"); + test_geometry<ls, mls>("LINESTRING(0 0,5 0,5 5,0 5,0 0)", + "MULTILINESTRING((5 5,5 0,0 0),(0 0,0 5,5 5))", + "1FFFFFFF2"); + // overlapping rings + 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,0 5))", + "10FFFFFF2"); + test_geometry<ls, mls>("LINESTRING(0 0,5 0,5 5,0 5,0 0)", + "MULTILINESTRING((5 5,5 0,0 0),(0 0,0 5,5 5,5 0))", + "10FFFFFF2"); + + // INVALID LINESTRINGS + // 1-point LS (a Point) disjoint + //test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,2 0),(1 1))", "101FF00F2"); + //test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,2 0),(1 1,1 1))", "101FF00F2"); + //test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,2 0),(1 1,1 1,1 1))", "101FF00F2"); + // 1-point LS (a Point) NOT disjoint + //test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,9 0),(2 0))", "101FF0FF2"); + //test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,9 0),(2 0,2 0))", "101FF0FF2"); + //test_geometry<ls, mls>("LINESTRING(0 0,10 0)", "MULTILINESTRING((1 0,9 0),(2 0,2 0,2 0))", "101FF0FF2"); + + // point-like + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 1 0),(2 0, 2 0))", // |------| * + "101F00FF2"); + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 1 0),(1 0, 1 0))", // |------* + "101F00FF2"); + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((5 0, 1 0),(1 0, 1 0))", // *-------| + "101F00FF2"); + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 1 0),(5 0, 5 0))", // |------| * + "10100FFF2"); + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 1 0),(0 0, 0 0))", // *------| + "101000FF2"); + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((4 0, 5 0),(5 0, 5 0))", // |------* + "101000FF2"); + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((1 0, 2 0),(0 0, 0 0))", // * |------| + "1010F0FF2"); + + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((2 0, 2 0),(2 0, 2 2))", // * + "001FF0102"); // | + + // for consistency + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 5 0),(0 0, 2 0))", // |--------------| + "10F00FFF2"); // |------| + + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 5 0),(3 0, 5 0))", // |--------------| + "10F00FFF2"); // |------| + + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 5 0),(0 0, 6 0))", // |--------------| + "1FF00F102"); // |----------------| + + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 5 0),(-1 0, 5 0))", // |--------------| + "1FF00F102"); // |----------------| + + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 5 0),(-1 0, 6 0))", // |--------------| + "1FF00F102"); // |------------------| + + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 5 0),(-1 0, 2 0))", // |--------------| + "10F00F102"); // |-------| + + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 5 0),(2 0, 6 0))", // |--------------| + "10F00F102"); // |-------| + + test_geometry<ls, mls>("LINESTRING(0 0, 5 0)", // |--------------| + "MULTILINESTRING((0 0, 5 0),(2 0, 2 2))", // |--------------| + "10FF0F102"); // | + // | + + if ( BOOST_GEOMETRY_CONDITION(boost::is_floating_point<typename bg::coordinate_type<ls>::type>::value) ) + { + // related to https://svn.boost.org/trac/boost/ticket/10904 + test_geometry<ls, mls>("LINESTRING(-2305843009213693956 4611686018427387906, -33 -92, 78 83)", + "MULTILINESTRING((20 100, 31 -97, -46 57, -20 -4),(-71 -4))", + "*********"); // TODO: be more specific with the result + } + + // 22.01.2015 + // inspired by L/A and A/A + test_geometry<ls, mls>("LINESTRING(1 1,2 2)", "MULTILINESTRING((0 0,1 1),(1 1,3 3))", "1FF0FF102"); + + // 25.01.2015 + test_geometry<ls, mls>("LINESTRING(1 1, 5 5, 4 4)", + "MULTILINESTRING((2 5, 7 5, 8 3, 6 3, 4 0),(0 0,10 10))", + "1FF0FF102"); + test_geometry<ls, mls>("LINESTRING(4 1, 4 5, 4 4)", + "MULTILINESTRING((2 5, 7 5, 8 3, 6 3, 4 0),(4 0, 4 8, 0 4))", + "1FF0FF102"); + test_geometry<ls, mls>("LINESTRING(1 1,5 5,4 4)", + "MULTILINESTRING((5 0,5 5,5 10),(0 0,10 10))", + "1FF0FF102"); + test_geometry<ls, mls>("LINESTRING(1 1,5 5,1 0)", + "MULTILINESTRING((5 0,5 5,5 10),(0 0,5 5,1 0))", + "1FF00F102"); + test_geometry<ls, mls>("LINESTRING(5 5,4 4)", + "MULTILINESTRING((5 0,5 5,5 10),(0 0,10 10))", + "1FF0FF102"); + test_geometry<ls, mls>("LINESTRING(6 6,5 5,4 4)", + "MULTILINESTRING((5 0,5 5,5 10),(0 0,10 10))", + "1FF0FF102"); + test_geometry<ls, mls>("LINESTRING(5 5,4 4)", + "MULTILINESTRING((5 0,5 5,5 10))", + "FF10F0102"); +} + +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))", + "1F1F00102"); + 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),(1 10,1 10,1 0,1 0,1 -10),(2 0,2 0),(3 0,3 0,3 0),(0 0,0 0,0 10,0 10),(30 0,30 0,31 0,31 0))", + "MULTILINESTRING((0 10,5 0,20 0,20 0,30 0),(1 10,1 10,1 0,1 0,1 -10),(0 0,0 0,0 10,0 10),(30 0,30 0,31 0,31 0))", + "1F100F102"); + 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),(0 0,0 0,0 10,0 10))", + "1F1F0F1F2"); + + // point-like + test_geometry<mls, mls>("MULTILINESTRING((0 0, 0 0),(1 1, 1 1))", + "MULTILINESTRING((0 0, 0 0))", + "0F0FFFFF2"); + test_geometry<mls, mls>("MULTILINESTRING((0 0, 0 0),(1 1, 1 1))", + "MULTILINESTRING((0 0, 0 0),(1 1, 1 1))", + "0FFFFFFF2"); + test_geometry<mls, mls>("MULTILINESTRING((0 0, 0 0),(1 1, 1 1))", + "MULTILINESTRING((2 2, 2 2),(3 3, 3 3))", + "FF0FFF0F2"); + + test_geometry<mls, mls>("MULTILINESTRING((0 5,10 5,10 10,5 10),(5 10,5 0,5 2),(5 2,5 5,0 5))", + "MULTILINESTRING((5 5,0 5),(5 5,5 0),(10 10,10 5,5 5,5 10,10 10))", + "10FFFFFF2"); + + if ( BOOST_GEOMETRY_CONDITION(( + boost::is_same<typename bg::coordinate_type<P>::type, double>::value )) ) + { + // assertion failure in 1.57 + test_geometry<mls, mls>("MULTILINESTRING((-0.59322033898305082 -8.0508474576271194,-2.882352941176471 -7.7647058823529411,-2.8823529411764706 -7.7647058823529411,-3.7361111111111112 -6.5694444444444446,-3.4404145077720205 -5.766839378238342,-4.1864406779661012 -3.6779661016949152,-7.5252525252525251 -5.5858585858585865,-7.5862068965517242 -5.1896551724137936,-4.47887323943662 -2.859154929577465,-4.5789473684210531 -2.5789473684210527,-3 -1,-2.9310344827586206 -0.86206896551724144,-3.1764705882352944 -0.70588235294117663,-4.7401960784313726 -2.1274509803921577,-5.3255813953488369 -0.48837209302325502,-4.7872340425531918 0.31914893617021284,-5.8571428571428577 1.0000000000000007,-5.3255813953488369 -0.48837209302325502,-5.9473684210526319 -1.4210526315789465,-8 2,-7.7333333333333334 2.1939393939393939,-8.8294573643410867 2.891472868217055,-8.8556701030927822 3.061855670103093,-7.5999999999999996 3.6000000000000001,-7.7999999999999998 3.7999999999999998,-7.75 3.7916666666666665,-7.5471698113207548 3.6226415094339623,-7.3200000000000003 3.7200000000000002,-3.473684210526315 3.0789473684210527,-3.2549019607843133 3.2156862745098036,-2.9999999999999982 3.1428571428571423,-3.1733333333333325 3.2666666666666666,-2.9180327868852456 3.4262295081967209,-2.8723404255319145 3.1063829787234041,-2.1111111111111112 2.8888888888888888,-2.1428571428571428 2.8571428571428572,-1.8433734939759043 2.8072289156626509,-1.8396226415094346 2.8113207547169816,-1.6486486486486487 2.756756756756757,-1.76510067114094 2.8926174496644301,-0.53846153846153855 4.2307692307692308,1.8148148148148147 5.4074074074074074,1.588235294117647 2.2352941176470589,1.819672131147541 2.1967213114754101,2 4,2 2.1666666666666665,2.3538461538461544 2.1076923076923078,2 1.6875000000000004,2 -2,1.2173913043478262 -3.8260869565217392,1.7375886524822697 1.3758865248226959,1.5073170731707317 1.1024390243902444,1.1428571428571428 -4,-0.59322033898305082 -8.0508474576271194),(1.666666666666667 1.5999999999999988,1.5675675675675675 1.8378378378378377,1.4374999999999991 1.8750000000000002,1.0487804878048776 2.3414634146341466,0.46666666666666712 2.6060606060606055,0.086956521739131043 2.2608695652173911,1.4374999999999991 1.8750000000000002,1.666666666666667 1.5999999999999988))", + "MULTILINESTRING((-2.333333333333333 -8.6666666666666661,-4.3253012048192767 -8.168674698795181,-4.1194968553459113 -7.6100628930817606,-2.8823529411764706 -7.7647058823529411,-2.882352941176471 -7.7647058823529411,-2.263157894736842 -8.6315789473684212,-2.333333333333333 -8.6666666666666661))", + "*********"); + } +} + +template <typename P> +void test_all() +{ + test_linestring_linestring<P>(); + test_linestring_multi_linestring<P>(); + test_multi_linestring_multi_linestring<P>(); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/relate/relate_pointlike_xxx.cpp b/libs/geometry/test/algorithms/relational_operations/relate/relate_pointlike_xxx.cpp new file mode 100644 index 000000000..f9314454f --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/relate/relate_pointlike_xxx.cpp @@ -0,0 +1,103 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2013, 2014. +// Modifications copyright (c) 2013-2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#include "test_relate.hpp" + +//TEST +//#include <to_svg.hpp> + +template <typename P> +void test_point_point() +{ + test_geometry<P, P>("POINT(0 0)", "POINT(0 0)", "0FFFFFFF2"); + test_geometry<P, P>("POINT(1 0)", "POINT(0 0)", "FF0FFF0F2"); +} + +template <typename P> +void test_point_multipoint() +{ + typedef bg::model::multi_point<P> mpt; + + test_geometry<P, mpt>("POINT(0 0)", "MULTIPOINT(0 0)", "0FFFFFFF2"); + test_geometry<P, mpt>("POINT(1 0)", "MULTIPOINT(0 0)", "FF0FFF0F2"); + test_geometry<P, mpt>("POINT(0 0)", "MULTIPOINT(0 0, 1 0)", "0FFFFF0F2"); +} + +template <typename P> +void test_multipoint_multipoint() +{ + typedef bg::model::multi_point<P> mpt; + + test_geometry<mpt, mpt>("MULTIPOINT(0 0)", "MULTIPOINT(0 0)", "0FFFFFFF2"); + test_geometry<mpt, mpt>("MULTIPOINT(1 0)", "MULTIPOINT(0 0)", "FF0FFF0F2"); + test_geometry<mpt, mpt>("MULTIPOINT(0 0)", "MULTIPOINT(0 0, 1 0)", "0FFFFF0F2"); + test_geometry<mpt, mpt>("MULTIPOINT(0 0, 1 0)", "MULTIPOINT(0 0)", "0F0FFFFF2"); + test_geometry<mpt, mpt>("MULTIPOINT(0 0, 1 1)", "MULTIPOINT(0 0, 1 0)", "0F0FFF0F2"); + + //typedef bg::model::d2::point_xy<float> ptf; + //typedef bg::model::multi_point<ptf> mptf; + //test_geometry<mptf, mpt>("MULTIPOINT(0 0)", "MULTIPOINT(0 0)", "0FFFFFFF2"); +} + +template <typename P> +void test_point_linestring() +{ + typedef bg::model::linestring<P> ls; + + test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0, 2 2, 3 2)", "F0FFFF102"); + test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0, 2 2, 3 2)", "0FFFFF102"); + test_geometry<P, ls>("POINT(3 2)", "LINESTRING(0 0, 2 2, 3 2)", "F0FFFF102"); + test_geometry<P, ls>("POINT(1 0)", "LINESTRING(0 0, 2 2, 3 2)", "FF0FFF102"); + + test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0, 2 2, 3 2, 0 0)", "0FFFFF1F2"); + test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0, 2 2, 3 2, 0 0)", "0FFFFF1F2"); + test_geometry<P, ls>("POINT(3 2)", "LINESTRING(0 0, 2 2, 3 2, 0 0)", "0FFFFF1F2"); + test_geometry<P, ls>("POINT(1 0)", "LINESTRING(0 0, 2 2, 3 2, 0 0)", "FF0FFF1F2"); +} + +template <typename P> +void test_point_multilinestring() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0, 2 0, 2 2),(0 0, 0 2))", "0FFFFF102"); + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0, 2 0, 2 2),(0 0, 0 2, 2 2))", "0FFFFF1F2"); + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0, 2 0, 2 2),(0 0, 0 2, 2 2),(0 0, 1 1))", "F0FFFF102"); + + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,5 0),(0 0,0 5,5 0),(0 0,-5 0),(0 0,0 -5,-5 0))", "0FFFFF1F2"); + test_geometry<P, mls>("POINT(5 0)", "MULTILINESTRING((0 0,5 0),(0 0,0 5,5 0),(0 0,-5 0),(0 0,0 -5,-5 0))", "0FFFFF1F2"); + test_geometry<P, mls>("POINT(1 0)", "MULTILINESTRING((0 0,5 0),(0 0,0 5,5 0),(0 0,-5 0),(0 0,0 -5,-5 0))", "0FFFFF1F2"); +} + +template <typename P> +void test_all() +{ + test_point_point<P>(); + test_point_multipoint<P>(); + test_multipoint_multipoint<P>(); + test_point_linestring<P>(); + test_point_multilinestring<P>(); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/relate/test_relate.hpp b/libs/geometry/test/algorithms/relational_operations/relate/test_relate.hpp new file mode 100644 index 000000000..3cdd3e6a9 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/relate/test_relate.hpp @@ -0,0 +1,157 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2013, 2014. +// Modifications copyright (c) 2013-2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#ifndef BOOST_GEOMETRY_TEST_RELATE_HPP +#define BOOST_GEOMETRY_TEST_RELATE_HPP + +#include <geometry_test_common.hpp> + +#include <boost/geometry/core/ring_type.hpp> +#include <boost/geometry/algorithms/detail/relate/relate.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/geometry/strategies/cartesian/point_in_box.hpp> +#include <boost/geometry/strategies/cartesian/box_in_box.hpp> +#include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp> + +namespace bgdr = bg::detail::relate; + +std::string transposed(std::string matrix) +{ + if ( !matrix.empty() ) + { + std::swap(matrix[1], matrix[3]); + std::swap(matrix[2], matrix[6]); + std::swap(matrix[5], matrix[7]); + } + return matrix; +} + +bool matrix_compare(std::string const& m1, std::string const& m2) +{ + BOOST_ASSERT(m1.size() == 9 && m2.size() == 9); + for ( size_t i = 0 ; i < 9 ; ++i ) + { + if ( m1[i] == '*' || m2[i] == '*' ) + continue; + + if ( m1[i] != m2[i] ) + return false; + } + return true; +} + +bool matrix_compare(std::string const& m, std::string const& res1, std::string const& res2) +{ + return matrix_compare(m, res1) + || ( !res2.empty() ? matrix_compare(m, res2) : false ); +} + +std::string matrix_format(std::string const& matrix1, std::string const& matrix2) +{ + return matrix1 + + ( !matrix2.empty() ? " || " : "" ) + matrix2; +} + +template <typename Geometry1, typename Geometry2> +void check_geometry(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& wkt1, + std::string const& wkt2, + std::string const& expected1, + std::string const& expected2 = std::string()) +{ + { + std::string res_str = bgdr::relate<bgdr::matrix9>(geometry1, geometry2); + bool ok = matrix_compare(res_str, expected1, expected2); + BOOST_CHECK_MESSAGE(ok, + "relate: " << wkt1 + << " and " << wkt2 + << " -> Expected: " << matrix_format(expected1, expected2) + << " detected: " << res_str); + } + + // changed sequence of geometries - transposed result + { + std::string res_str = bgdr::relate(geometry2, geometry1, bgdr::matrix9()); + std::string expected1_tr = transposed(expected1); + std::string expected2_tr = transposed(expected2); + bool ok = matrix_compare(res_str, expected1_tr, expected2_tr); + BOOST_CHECK_MESSAGE(ok, + "relate: " << wkt2 + << " and " << wkt1 + << " -> Expected: " << matrix_format(expected1_tr, expected2_tr) + << " detected: " << res_str); + } + + if ( expected2.empty() ) + { + { + bool result = bgdr::relate(geometry1, geometry2, bgdr::mask9(expected1)); + // TODO: SHOULD BE !interrupted - CHECK THIS! + BOOST_CHECK_MESSAGE(result, + "relate: " << wkt1 + << " and " << wkt2 + << " -> Expected: " << expected1); + } + + if ( BOOST_GEOMETRY_CONDITION(( + bg::detail::relate::interruption_enabled<Geometry1, Geometry2>::value )) ) + { + // brake the expected output + std::string expected_interrupt = expected1; + bool changed = false; + BOOST_FOREACH(char & c, expected_interrupt) + { + if ( c >= '0' && c <= '9' ) + { + if ( c == '0' ) + c = 'F'; + else + --c; + + changed = true; + } + } + + if ( changed ) + { + bool result = bgdr::relate(geometry1, geometry2, bgdr::mask9(expected_interrupt)); + // TODO: SHOULD BE interrupted - CHECK THIS! + BOOST_CHECK_MESSAGE(!result, + "relate: " << wkt1 + << " and " << wkt2 + << " -> Expected interrupt for:" << expected_interrupt); + } + } + } +} + +template <typename Geometry1, typename Geometry2> +void test_geometry(std::string const& wkt1, + std::string const& wkt2, + std::string const& expected1, + std::string const& expected2 = std::string()) +{ + Geometry1 geometry1; + Geometry2 geometry2; + bg::read_wkt(wkt1, geometry1); + bg::read_wkt(wkt2, geometry2); + check_geometry(geometry1, geometry2, wkt1, wkt2, expected1, expected2); +} + +#endif // BOOST_GEOMETRY_TEST_RELATE_HPP diff --git a/libs/geometry/test/algorithms/relational_operations/test_covered_by.hpp b/libs/geometry/test/algorithms/relational_operations/test_covered_by.hpp new file mode 100644 index 000000000..b9d8f5853 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/test_covered_by.hpp @@ -0,0 +1,144 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// 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_COVERED_BY_HPP +#define BOOST_GEOMETRY_TEST_COVERED_BY_HPP + + +#include <geometry_test_common.hpp> + +#include <boost/variant/variant.hpp> + +#include <boost/geometry/core/ring_type.hpp> +#include <boost/geometry/algorithms/covered_by.hpp> +#include <boost/geometry/strategies/strategies.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/io/wkt/read.hpp> + +#include <boost/geometry/multi/algorithms/covered_by.hpp> +#include <boost/geometry/multi/geometries/multi_linestring.hpp> +#include <boost/geometry/multi/io/wkt/read.hpp> + +template <typename Geometry1, typename Geometry2> +void check_geometry(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& wkt1, + std::string const& wkt2, + bool expected) +{ + bool detected = bg::covered_by(geometry1, geometry2); + + BOOST_CHECK_MESSAGE(detected == expected, + "covered_by: " << wkt1 + << " in " << wkt2 + << " -> 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); + boost::variant<Geometry1> v1(geometry1); + boost::variant<Geometry2> v2(geometry2); + + check_geometry(geometry1, geometry2, wkt1, wkt2, expected); + check_geometry(v1, geometry2, wkt1, wkt2, expected); + check_geometry(geometry1, v2, wkt1, wkt2, expected); + check_geometry(v1, v2, wkt1, wkt2, expected); +} + +/* + +template <typename Point, bool Clockwise, bool Closed> +void test_ordered_ring(std::string const& wkt_point, + std::string const& wkt_geometry, bool expected) +{ + typedef bg::model::ring<Point, Clockwise, Closed> ring_type; + ring_type ring; + Point point; + + bg::read_wkt(wkt_geometry, ring); + if (! Clockwise) + { + std::reverse(boost::begin(ring), boost::end(ring)); + } + if (! Closed) + { + ring.resize(ring.size() - 1); + } + + bg::read_wkt(wkt_point, point); + + bool detected = bg::covered_by(point, ring); + + BOOST_CHECK_MESSAGE(detected == expected, + "covered_by: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + + // other strategy (note that this one cannot detect OnBorder + // (without modifications) + + bg::strategy::covered_by::franklin<Point> franklin; + detected = bg::covered_by(point, ring, franklin); + if (! on_border) + { + BOOST_CHECK_MESSAGE(detected == expected, + "covered_by: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + } + + + bg::strategy::covered_by::crossings_multiply<Point> cm; + detected = bg::covered_by(point, ring, cm); + if (! on_border) + { + BOOST_CHECK_MESSAGE(detected == expected, + "covered_by: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + } +} + +template <typename Point> +void test_ring(std::string const& wkt_point, + std::string const& wkt_geometry, + bool expected) +{ + test_ordered_ring<Point, true, true>(wkt_point, wkt_geometry, expected); + test_ordered_ring<Point, false, true>(wkt_point, wkt_geometry, expected); + test_ordered_ring<Point, true, false>(wkt_point, wkt_geometry, expected); + test_ordered_ring<Point, false, false>(wkt_point, wkt_geometry, expected); + test_geometry<Point, bg::model::polygon<Point> >(wkt_point, wkt_geometry, expected); +} +*/ + +#endif diff --git a/libs/geometry/test/algorithms/relational_operations/test_crosses.hpp b/libs/geometry/test/algorithms/relational_operations/test_crosses.hpp new file mode 100644 index 000000000..768ed91f6 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/test_crosses.hpp @@ -0,0 +1,83 @@ +// Generic Geometry2 Library +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#ifndef BOOST_GEOMETRY_TEST_CROSSES_HPP +#define BOOST_GEOMETRY_TEST_CROSSES_HPP + + +#include <geometry_test_common.hpp> + +#include <boost/geometry/core/ring_type.hpp> +#include <boost/geometry/algorithms/crosses.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> + + +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); + + bool detected = bg::crosses(geometry1, geometry2); + + BOOST_CHECK_MESSAGE(detected == expected, + "crosses: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + +#if !defined(BOOST_GEOMETRY_TEST_DEBUG) + detected = bg::crosses( + geometry1, + boost::variant<Geometry2>(geometry2)); + + BOOST_CHECK_MESSAGE(detected == expected, + "crosses: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + + detected = bg::crosses( + boost::variant<Geometry1>(geometry1), + geometry2); + + BOOST_CHECK_MESSAGE(detected == expected, + "crosses: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + + detected = bg::crosses( + boost::variant<Geometry1>(geometry1), + boost::variant<Geometry2>(geometry2)); + + BOOST_CHECK_MESSAGE(detected == expected, + "crosses: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); +#endif +} + + +#endif // BOOST_GEOMETRY_TEST_CROSSES_HPP diff --git a/libs/geometry/test/algorithms/relational_operations/test_equals.hpp b/libs/geometry/test/algorithms/relational_operations/test_equals.hpp new file mode 100644 index 000000000..485dc700c --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/test_equals.hpp @@ -0,0 +1,69 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. + +// 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_EQUALS_HPP +#define BOOST_GEOMETRY_TEST_EQUALS_HPP + + +#include <geometry_test_common.hpp> + +#include <boost/geometry/core/ring_type.hpp> +#include <boost/geometry/algorithms/equals.hpp> +#include <boost/geometry/strategies/strategies.hpp> +#include <boost/geometry/io/wkt/read.hpp> +#include <boost/variant/variant.hpp> + + +template <typename Geometry1, typename Geometry2> +void check_geometry(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& caseid, + std::string const& wkt1, + std::string const& wkt2, + bool expected) +{ + bool detected = bg::equals(geometry1, geometry2); + + BOOST_CHECK_MESSAGE(detected == expected, + "case: " << caseid + << " equals: " << wkt1 + << " to " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + + detected = bg::equals(geometry2, geometry1); + + BOOST_CHECK_MESSAGE(detected == expected, + "case: " << caseid + << " equals: " << wkt1 + << " to " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); +} + + +template <typename Geometry1, typename Geometry2> +void test_geometry(std::string const& caseid, + std::string const& wkt1, + std::string const& wkt2, bool expected) +{ + Geometry1 geometry1; + Geometry2 geometry2; + + bg::read_wkt(wkt1, geometry1); + bg::read_wkt(wkt2, geometry2); + + check_geometry(geometry1, geometry2, caseid, wkt1, wkt2, expected); + check_geometry(boost::variant<Geometry1>(geometry1), geometry2, caseid, wkt1, wkt2, expected); + check_geometry(geometry1, boost::variant<Geometry2>(geometry2), caseid, wkt1, wkt2, expected); + check_geometry(boost::variant<Geometry1>(geometry1), boost::variant<Geometry2>(geometry2), caseid, wkt1, wkt2, expected); +} + +#endif diff --git a/libs/geometry/test/algorithms/relational_operations/test_intersects.hpp b/libs/geometry/test/algorithms/relational_operations/test_intersects.hpp new file mode 100644 index 000000000..7a8af7161 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/test_intersects.hpp @@ -0,0 +1,81 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// 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_INTERSECTS_HPP +#define BOOST_GEOMETRY_TEST_INTERSECTS_HPP + + +#include <geometry_test_common.hpp> + +#include <boost/geometry/core/ring_type.hpp> +#include <boost/geometry/algorithms/intersects.hpp> +#include <boost/geometry/strategies/strategies.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/io/wkt/read.hpp> + +#include <boost/geometry/multi/core/geometry_id.hpp> +#include <boost/geometry/multi/core/point_order.hpp> +#include <boost/geometry/multi/core/ring_type.hpp> +#include <boost/geometry/multi/algorithms/covered_by.hpp> +#include <boost/geometry/multi/algorithms/detail/point_on_border.hpp> +#include <boost/geometry/multi/algorithms/detail/sections/sectionalize.hpp> +#include <boost/geometry/multi/algorithms/detail/sections/range_by_section.hpp> +#include <boost/geometry/multi/views/detail/range_type.hpp> +#include <boost/geometry/multi/geometries/multi_linestring.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +#include <boost/geometry/multi/io/wkt/read.hpp> + +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); + + bool detected = bg::intersects(geometry1, geometry2); + bool detected2 = bg::intersects(geometry2, geometry1); + + BOOST_CHECK_MESSAGE(detected == expected, + "intersects: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + BOOST_CHECK_MESSAGE(detected2 == expected, + "intersects: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected2); +} + + +template <typename Geometry> +void test_self_intersects(std::string const& wkt, bool expected) +{ + Geometry geometry; + + bg::read_wkt(wkt, geometry); + + bool detected = bg::intersects(geometry); + + BOOST_CHECK_MESSAGE(detected == expected, + "intersects: " << wkt + << " -> Expected: " << expected + << " detected: " << detected); +} + + + +#endif diff --git a/libs/geometry/test/algorithms/relational_operations/test_overlaps.hpp b/libs/geometry/test/algorithms/relational_operations/test_overlaps.hpp new file mode 100644 index 000000000..862fe7389 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/test_overlaps.hpp @@ -0,0 +1,52 @@ +// Generic Geometry2 Library +// Unit Test + +// Copyright (c) 2007-2012 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) + +#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> + + +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); + + bool detected = bg::overlaps(geometry1, geometry2); + + BOOST_CHECK_MESSAGE(detected == expected, + "overlaps: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); + + detected = bg::overlaps(geometry2, geometry1); + + BOOST_CHECK_MESSAGE(detected == expected, + "overlaps: " << wkt1 + << " with " << wkt2 + << " -> Expected: " << expected + << " detected: " << detected); +} + + +#endif diff --git a/libs/geometry/test/algorithms/relational_operations/test_touches.hpp b/libs/geometry/test/algorithms/relational_operations/test_touches.hpp new file mode 100644 index 000000000..60df672c5 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/test_touches.hpp @@ -0,0 +1,98 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-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) + +#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> + +template <typename Geometry1, typename Geometry2> +void check_touches(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& wkt1, + std::string const& wkt2, + bool expected) +{ + 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); + + check_touches(geometry1, geometry2, wkt1, wkt2, expected); + check_touches(v1, geometry2, wkt1, wkt2, expected); + check_touches(geometry1, v2, wkt1, wkt2, expected); + check_touches(v1, v2, 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/libs/geometry/test/algorithms/relational_operations/touches.cpp b/libs/geometry/test/algorithms/relational_operations/touches.cpp new file mode 100644 index 000000000..d7a92c8e0 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/touches.cpp @@ -0,0 +1,244 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2013, 2014. +// Modifications copyright (c) 2013, 2014, 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#include "test_touches.hpp" + +template <typename P> +void test_all() +{ + typedef bg::model::box<P> box; + 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; + + // 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); + + // 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 + ); + + // 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); + + // 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); + + 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/libs/geometry/test/algorithms/relational_operations/within/Jamfile.v2 b/libs/geometry/test/algorithms/relational_operations/within/Jamfile.v2 new file mode 100644 index 000000000..dc33b40cc --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/within/Jamfile.v2 @@ -0,0 +1,25 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +# +# This file was modified by Oracle on 2014. +# Modifications copyright (c) 2014, 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-within + : + [ run multi_within.cpp ] + [ run within.cpp ] + [ run within_areal_areal.cpp ] + [ run within_linear_areal.cpp ] + [ run within_linear_linear.cpp ] + [ run within_pointlike_xxx.cpp ] + ; diff --git a/libs/geometry/test/algorithms/relational_operations/within/multi_within.cpp b/libs/geometry/test/algorithms/relational_operations/within/multi_within.cpp new file mode 100644 index 000000000..cf5573aa6 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/within/multi_within.cpp @@ -0,0 +1,59 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2007-2012 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 <geometry_test_common.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> +#include <boost/geometry/multi/io/wkt/wkt.hpp> + +#include <boost/geometry/algorithms/correct.hpp> +#include <boost/geometry/algorithms/within.hpp> + +#include <boost/geometry/geometries/box.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/multi/core/point_order.hpp> +#include <boost/geometry/multi/algorithms/within.hpp> + +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +#include "test_within.hpp" + + +template <typename P> +void test_all() +{ + typedef bg::model::multi_polygon<bg::model::polygon<P> > mp; + + // test multi-with-one-polygon (trivial case) + test_geometry<P, mp>("POINT(1 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", true); + test_geometry<P, mp>("POINT(3 3)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + test_geometry<P, mp>("POINT(0 1)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + test_geometry<P, mp>("POINT(4 4)", "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)))", false); + + // test if it is in one of them + std::string multi("MULTIPOLYGON(" + "((0 0,0 2,2 2,2 0,0 0))" + "((3 3,3 6,6 6,6 3,3 3))" + ")"); + test_geometry<P, mp>("POINT(4 4)", multi, true); + test_geometry<P, mp>("POINT(1 1)", multi, true); + test_geometry<P, mp>("POINT(0 1)", multi, false); +} + +int test_main( int , char* [] ) +{ + //test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/within/test_within.hpp b/libs/geometry/test/algorithms/relational_operations/within/test_within.hpp new file mode 100644 index 000000000..c82bdaf7e --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/within/test_within.hpp @@ -0,0 +1,150 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#ifndef BOOST_GEOMETRY_TEST_WITHIN_HPP +#define BOOST_GEOMETRY_TEST_WITHIN_HPP + + +#include <boost/variant/variant.hpp> + +#include <geometry_test_common.hpp> + +#include <boost/geometry/core/ring_type.hpp> + +#include <boost/geometry/strategies/strategies.hpp> +#include <boost/geometry/geometries/ring.hpp> +#include <boost/geometry/geometries/polygon.hpp> + +#include <boost/geometry/io/wkt/read.hpp> + +#include <boost/geometry/strategies/cartesian/point_in_box.hpp> +#include <boost/geometry/strategies/cartesian/box_in_box.hpp> +#include <boost/geometry/strategies/agnostic/point_in_point.hpp> +#include <boost/geometry/strategies/agnostic/point_in_box_by_side.hpp> +#include <boost/geometry/strategies/agnostic/point_in_poly_winding.hpp> +#include <boost/geometry/strategies/agnostic/relate.hpp> + +#include <boost/geometry/algorithms/within.hpp> + +#include <boost/geometry/multi/algorithms/covered_by.hpp> +#include <boost/geometry/multi/geometries/multi_linestring.hpp> +#include <boost/geometry/multi/io/wkt/read.hpp> + +template <typename Geometry1, typename Geometry2> +void check_geometry(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& wkt1, + std::string const& wkt2, + bool expected) +{ + bool detected = bg::within(geometry1, geometry2); + + BOOST_CHECK_MESSAGE(detected == expected, + "within: " << wkt1 + << " in " << wkt2 + << " -> 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); + boost::variant<Geometry1> v1(geometry1); + boost::variant<Geometry2> v2(geometry2); + + check_geometry(geometry1, geometry2, wkt1, wkt2, expected); + check_geometry(v1, geometry2, wkt1, wkt2, expected); + check_geometry(geometry1, v2, wkt1, wkt2, expected); + check_geometry(v1, v2, wkt1, wkt2, expected); +} + +template <typename Point, bool Clockwise, bool Closed> +void test_ordered_ring(std::string const& wkt_point, + std::string const& wkt_geometry, bool expected, bool on_border) +{ + typedef bg::model::ring<Point, Clockwise, Closed> ring_type; + ring_type ring; + Point point; + + bg::read_wkt(wkt_geometry, ring); + if ( BOOST_GEOMETRY_CONDITION(! Clockwise) ) + { + std::reverse(boost::begin(ring), boost::end(ring)); + } + + bg::read_wkt(wkt_point, point); + + bool detected = bg::within(point, ring); + + BOOST_CHECK_MESSAGE(detected == expected, + "within: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + + // other strategy (note that this one cannot detect OnBorder + // (without modifications) + + bg::strategy::within::franklin<Point> franklin; + detected = bg::within(point, ring, franklin); + if (! on_border) + { + BOOST_CHECK_MESSAGE(detected == expected, + "within: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + } + + + bg::strategy::within::crossings_multiply<Point> cm; + detected = bg::within(point, ring, cm); + if (! on_border) + { + BOOST_CHECK_MESSAGE(detected == expected, + "within: " << wkt_point + << " in " << wkt_geometry + << " -> Expected: " << expected + << " detected: " << detected + << " clockwise: " << int(Clockwise) + << " closed: " << int(Closed) + ); + } +} + +template <typename Point> +void test_ring(std::string const& wkt_point, + std::string const& wkt_geometry, + bool expected, bool on_border) +{ + test_ordered_ring<Point, true, true>(wkt_point, wkt_geometry, expected, on_border); + test_ordered_ring<Point, false, true>(wkt_point, wkt_geometry, expected, on_border); + test_ordered_ring<Point, true, false>(wkt_point, wkt_geometry, expected, on_border); + test_ordered_ring<Point, false, false>(wkt_point, wkt_geometry, expected, on_border); + test_geometry<Point, bg::model::polygon<Point> >(wkt_point, wkt_geometry, expected); +} + +#endif diff --git a/libs/geometry/test/algorithms/relational_operations/within/within.cpp b/libs/geometry/test/algorithms/relational_operations/within/within.cpp new file mode 100644 index 000000000..2300a4ec5 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/within/within.cpp @@ -0,0 +1,193 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#include "test_within.hpp" + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/multi.hpp> +#include <boost/geometry/multi/geometries/multi_point.hpp> +#include <boost/geometry/multi/geometries/multi_linestring.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +template <typename P> +void test_all() +{ + typedef bg::model::box<P> box_type; + + test_geometry<P, box_type>("POINT(1 1)", "BOX(0 0,2 2)", true); + test_geometry<P, box_type>("POINT(0 0)", "BOX(0 0,2 2)", false); + test_geometry<P, box_type>("POINT(2 2)", "BOX(0 0,2 2)", false); + test_geometry<P, box_type>("POINT(0 1)", "BOX(0 0,2 2)", false); + test_geometry<P, box_type>("POINT(1 0)", "BOX(0 0,2 2)", false); + + test_geometry<box_type, box_type>("BOX(1 1,2 2)", "BOX(0 0,3 3)", true); + test_geometry<box_type, box_type>("BOX(0 0,3 3)", "BOX(1 1,2 2)", false); + + test_geometry<box_type, box_type>("BOX(1 1,3 3)", "BOX(0 0,3 3)", true); + test_geometry<box_type, box_type>("BOX(3 1,3 3)", "BOX(0 0,3 3)", false); + + /* + test_within_code<P, box_type>("POINT(1 1)", "BOX(0 0,2 2)", 1); + test_within_code<P, box_type>("POINT(1 0)", "BOX(0 0,2 2)", 0); + test_within_code<P, box_type>("POINT(0 1)", "BOX(0 0,2 2)", 0); + test_within_code<P, box_type>("POINT(0 3)", "BOX(0 0,2 2)", -1); + test_within_code<P, box_type>("POINT(3 3)", "BOX(0 0,2 2)", -1); + + test_within_code<box_type, box_type>("BOX(1 1,2 2)", "BOX(0 0,3 3)", 1); + test_within_code<box_type, box_type>("BOX(0 1,2 2)", "BOX(0 0,3 3)", 0); + test_within_code<box_type, box_type>("BOX(1 0,2 2)", "BOX(0 0,3 3)", 0); + test_within_code<box_type, box_type>("BOX(1 1,2 3)", "BOX(0 0,3 3)", 0); + test_within_code<box_type, box_type>("BOX(1 1,3 2)", "BOX(0 0,3 3)", 0); + test_within_code<box_type, box_type>("BOX(1 1,3 4)", "BOX(0 0,3 3)", -1); + */ +} + +template <typename Point> +void test_spherical() +{ + // Test spherical boxes + // See also http://www.gcmap.com/mapui?P=1E45N-19E45N-19E55N-1E55N-1E45N,10E55.1N,10E45.1N + bg::model::box<Point> box; + bg::read_wkt("POLYGON((1 45,19 55))", box); + BOOST_CHECK_EQUAL(bg::within(Point(10, 55.1), box), true); + BOOST_CHECK_EQUAL(bg::within(Point(10, 55.2), box), true); + BOOST_CHECK_EQUAL(bg::within(Point(10, 55.3), box), true); + BOOST_CHECK_EQUAL(bg::within(Point(10, 55.4), box), false); + + BOOST_CHECK_EQUAL(bg::within(Point(10, 45.1), box), false); + BOOST_CHECK_EQUAL(bg::within(Point(10, 45.2), box), false); + BOOST_CHECK_EQUAL(bg::within(Point(10, 45.3), box), false); + BOOST_CHECK_EQUAL(bg::within(Point(10, 45.4), box), true); + + // Crossing the dateline (Near Tuvalu) + // http://www.gcmap.com/mapui?P=178E10S-178W10S-178W6S-178E6S-178E10S,180W5.999S,180E9.999S + // http://en.wikipedia.org/wiki/Tuvalu + + bg::model::box<Point> tuvalu(Point(178, -10), Point(-178, -6)); + BOOST_CHECK_EQUAL(bg::within(Point(180, -8), tuvalu), true); + BOOST_CHECK_EQUAL(bg::within(Point(-180, -8), tuvalu), true); + BOOST_CHECK_EQUAL(bg::within(Point(180, -5.999), tuvalu), false); + BOOST_CHECK_EQUAL(bg::within(Point(180, -10.001), tuvalu), true); +} + +void test_3d() +{ + typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> point_type; + typedef boost::geometry::model::box<point_type> box_type; + box_type box(point_type(0, 0, 0), point_type(4, 4, 4)); + BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 2), box), true); + BOOST_CHECK_EQUAL(bg::within(point_type(2, 4, 2), box), false); + BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 4), box), false); + BOOST_CHECK_EQUAL(bg::within(point_type(2, 2, 5), box), false); + + box_type box2(point_type(2, 2, 2), point_type(3, 3, 3)); + BOOST_CHECK_EQUAL(bg::within(box2, box), true); + +} + +template <typename P1, typename P2> +void test_mixed_of() +{ + typedef boost::geometry::model::polygon<P1> polygon_type1; + typedef boost::geometry::model::polygon<P2> polygon_type2; + typedef boost::geometry::model::box<P1> box_type1; + typedef boost::geometry::model::box<P2> box_type2; + + polygon_type1 poly1; + polygon_type2 poly2; + boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly1); + boost::geometry::read_wkt("POLYGON((0 0,0 5,5 5,5 0,0 0))", poly2); + + box_type1 box1(P1(1, 1), P1(4, 4)); + box_type2 box2(P2(0, 0), P2(5, 5)); + P1 p1(3, 3); + P2 p2(3, 3); + + BOOST_CHECK_EQUAL(bg::within(p1, poly2), true); + BOOST_CHECK_EQUAL(bg::within(p2, poly1), true); + BOOST_CHECK_EQUAL(bg::within(p2, box1), true); + BOOST_CHECK_EQUAL(bg::within(p1, box2), true); + BOOST_CHECK_EQUAL(bg::within(box1, box2), true); + BOOST_CHECK_EQUAL(bg::within(box2, box1), false); +} + + +void test_mixed() +{ + // Mixing point types and coordinate types + test_mixed_of + < + boost::geometry::model::d2::point_xy<double>, + boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> + >(); + test_mixed_of + < + boost::geometry::model::d2::point_xy<float>, + boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> + >(); + test_mixed_of + < + boost::geometry::model::d2::point_xy<int>, + boost::geometry::model::d2::point_xy<double> + >(); +} + +void test_strategy() +{ + // Test by explicitly specifying a strategy + typedef bg::model::d2::point_xy<double> point_type; + typedef bg::model::box<point_type> box_type; + point_type p(3, 3); + box_type b(point_type(0, 0), point_type(5, 5)); + box_type b0(point_type(0, 0), point_type(5, 0)); + + bool r = bg::within(p, b, + bg::strategy::within::point_in_box<point_type, box_type>()); + BOOST_CHECK_EQUAL(r, true); + + r = bg::within(b, b, + bg::strategy::within::box_in_box<box_type, box_type>()); + BOOST_CHECK_EQUAL(r, true); + + r = bg::within(b0, b0, + bg::strategy::within::box_in_box<box_type, box_type>()); + BOOST_CHECK_EQUAL(r, false); + + r = bg::within(p, b, + bg::strategy::within::point_in_box_by_side<point_type, box_type>()); + BOOST_CHECK_EQUAL(r, true); +} + + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + test_all<bg::model::d2::point_xy<double> >(); + + test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >(); + + test_mixed(); + test_3d(); + test_strategy(); + + +#if defined(HAVE_TTMATH) + test_all<bg::model::d2::point_xy<ttmath_big> >(); + test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >(); +#endif + + return 0; +} diff --git a/libs/geometry/test/algorithms/relational_operations/within/within_areal_areal.cpp b/libs/geometry/test/algorithms/relational_operations/within/within_areal_areal.cpp new file mode 100644 index 000000000..a2901ba4b --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/within/within_areal_areal.cpp @@ -0,0 +1,96 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// 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_within.hpp" + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/multi.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +template <typename P> +void test_a_a() +{ + typedef bg::model::polygon<P> poly; + typedef bg::model::ring<P> ring; + typedef bg::model::multi_polygon<poly> mpoly; + + test_geometry<ring, ring>("POLYGON((0 0,0 2,2 2,2 0,0 0))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry<ring, poly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry<poly, ring>("POLYGON((0 0,0 6,6 6,6 0,0 0))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + + test_geometry<poly, poly>("POLYGON((0 0,0 9,9 9,9 0,0 0),(3 3,6 3,6 6,3 6,3 3))", + "POLYGON((0 0,0 9,9 9,9 0,0 0),(3 3,6 3,6 6,3 6,3 3))", true); + test_geometry<poly, poly>("POLYGON((0 0,0 9,9 9,9 0,0 0),(3 3,6 3,6 6,3 6,3 3))", + "POLYGON((0 0,0 9,9 9,9 0,0 0),(4 4,5 4,5 5,4 5,4 4))", true); + test_geometry<poly, poly>("POLYGON((1 1,1 8,8 8,8 1,1 1),(3 3,6 3,6 6,3 6,3 3))", + "POLYGON((0 0,0 9,9 9,9 0,0 0),(3 3,6 3,6 6,3 6,3 3))", true); + test_geometry<poly, poly>("POLYGON((1 1,1 8,8 8,8 1,1 1),(3 3,6 3,6 6,3 6,3 3))", + "POLYGON((0 0,0 9,9 9,9 0,0 0),(4 4,5 4,5 5,4 5,4 4))", true); + + test_geometry<ring, mpoly>("POLYGON((0 0,0 2,2 2,2 0,0 0))", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", true); + test_geometry<poly, mpoly>("POLYGON((0 0,0 2,2 2,2 0,0 0))", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", true); + + test_geometry<mpoly, ring>("MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", true); + test_geometry<mpoly, poly>("MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((15 15,15 110,110 110,110 15,15 15)))", + "POLYGON((0 0,0 10,10 10,10 0,0 0))", false); + + test_geometry<mpoly, poly>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(3 3,4 3,4 4,3 4,3 3))", false); + + test_geometry<mpoly, mpoly>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))", + "MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))", true); + test_geometry<mpoly, mpoly>("MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", true); + test_geometry<mpoly, mpoly>("MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", + "MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((3 3,3 4,4 3,3 3)))", false); + + // https://svn.boost.org/trac/boost/ticket/10912 + test_geometry<poly, poly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", + "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))", + false); + test_geometry<poly, poly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,2 4,4 4,4 2,2 2))", + false); + + test_geometry<poly, mpoly>("POLYGON((0 0,0 5,5 5,5 0,0 0))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + true); + test_geometry<poly, mpoly>("POLYGON((0 0,0 10,10 10,10 0,0 0))", + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 0,0 -10,-10 -10,-10 0,0 0)))", + true); +} + +template <typename P> +void test_all() +{ + test_a_a<P>(); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/within/within_linear_areal.cpp b/libs/geometry/test/algorithms/relational_operations/within/within_linear_areal.cpp new file mode 100644 index 000000000..889ff3692 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/within/within_linear_areal.cpp @@ -0,0 +1,121 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#include "test_within.hpp" + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/multi.hpp> +#include <boost/geometry/multi/geometries/multi_linestring.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +template <typename P> +void test_l_a() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + typedef bg::model::polygon<P> poly; + typedef bg::model::ring<P> ring; + typedef bg::model::multi_polygon<poly> mpoly; + + // B,I + test_geometry<ls, ring>("LINESTRING(0 0, 2 2)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + + // B,I + test_geometry<ls, poly>("LINESTRING(0 0, 2 2)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + // I + test_geometry<ls, poly>("LINESTRING(1 1, 2 2)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + // I,E + test_geometry<ls, poly>("LINESTRING(1 1, 6 6)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + // B + test_geometry<ls, poly>("LINESTRING(0 0, 5 0)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + test_geometry<ls, poly>("LINESTRING(0 0, 0 5)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + // E + test_geometry<ls, poly>("LINESTRING(6 0, 6 5)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + + // BIBIB + test_geometry<ls, mpoly>("LINESTRING(0 0, 10 10)", "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", true); + // BIBEBIB + test_geometry<ls, mpoly>("LINESTRING(0 0, 10 10)", "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((6 6,5 10,10 10,10 5,6 6)))", false); + + // MySQL report 18.12.2014 (https://svn.boost.org/trac/boost/ticket/10887) + test_geometry<ls, mpoly>("LINESTRING(5 -2,5 2)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + true); + test_geometry<ls, mpoly>("LINESTRING(5 -2,5 5)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + true); + test_geometry<ls, mpoly>("LINESTRING(5 -2,5 0)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + true); + // MySQL report 18.12.2014 - extended + test_geometry<ls, mpoly>("LINESTRING(5 -2,5 0)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)),((5 0,7 1,7 -1,5 0)))", + true); + test_geometry<ls, mpoly>("LINESTRING(0 0,5 0)", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)),((5 0,7 1,7 -1,5 0)))", + false); + 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)))", + true); + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,0 1,5 0),(0 0,0 -1,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + false); + test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,4 -2,5 0),(6 -2,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + true); + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,0 1,5 0),(0 -1,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + false); + test_geometry<mls, mpoly>("MULTILINESTRING((0 0,5 0),(5 -2,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + false); + test_geometry<mls, mpoly>("MULTILINESTRING((5 -2,5 0),(0 0,5 0))", + "MULTIPOLYGON(((5 0,0 5,10 5,5 0)),((5 0,10 -5,0 -5,5 0)))", + false); + + // BI + test_geometry<mls, poly>("MULTILINESTRING((0 0,2 2),(2 2,3 3))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + // I E + test_geometry<mls, poly>("MULTILINESTRING((1 1,2 2),(6 6,7 7))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + + // I I + test_geometry<mls, mpoly>("MULTILINESTRING((1 1,5 5),(6 6,7 7))", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", + true); + // I E + test_geometry<mls, mpoly>("MULTILINESTRING((1 1,5 5),(11 11,12 12))", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))", + false); +} + +template <typename P> +void test_all() +{ + test_l_a<P>(); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/within/within_linear_linear.cpp b/libs/geometry/test/algorithms/relational_operations/within/within_linear_linear.cpp new file mode 100644 index 000000000..6467e0110 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/within/within_linear_linear.cpp @@ -0,0 +1,99 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#include "test_within.hpp" + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/multi.hpp> +#include <boost/geometry/multi/geometries/multi_linestring.hpp> + +template <typename P> +void test_l_l() +{ + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + + test_geometry<ls, ls>("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true); + + test_geometry<ls, ls>("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true); + test_geometry<ls, ls>("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(0 0, 2 2, 3 2)", true); + test_geometry<ls, ls>("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(3 2, 2 2, 0 0)", true); + test_geometry<ls, ls>("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(3 2, 2 2, 0 0)", true); + + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", true); + test_geometry<ls, ls>("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(0 0, 2 2, 4 2)", true); + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(4 2, 2 2, 0 0)", true); + test_geometry<ls, ls>("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(4 2, 2 2, 0 0)", true); + + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false); + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false); + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false); + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 3 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false); + + test_geometry<ls, ls>("LINESTRING(0 1, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); + test_geometry<ls, ls>("LINESTRING(0 1, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); + test_geometry<ls, ls>("LINESTRING(1 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); + test_geometry<ls, ls>("LINESTRING(1 0, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); + + // duplicated points + test_geometry<ls, ls>("LINESTRING(1 1, 2 2, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", true); + test_geometry<ls, ls>("LINESTRING(1 1, 1 1, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", true); + + test_geometry<ls, ls>("LINESTRING(0 0, 0 0, 0 0, 1 1, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 2 2, 3 3)", + "LINESTRING(0 0, 2 2, 4 4)", true); + + // invalid linestrings +// test_geometry<ls, ls>("LINESTRING(0 0)", "LINESTRING(0 0)", false); +// test_geometry<ls, ls>("LINESTRING(1 1)", "LINESTRING(0 0, 2 2)", true); +// test_geometry<ls, ls>("LINESTRING(0 0)", "LINESTRING(0 0, 2 2)", false); +// test_geometry<ls, ls>("LINESTRING(0 0, 1 1)", "LINESTRING(0 0)", false); + + // spikes + // FOR NOW DISABLED + + /*test_geometry<ls, ls>("LINESTRING(0 0,5 0,3 0,6 0)", "LINESTRING(0 0,6 0)", true); + + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,3 3,6 3)", true); + test_geometry<ls, ls>("LINESTRING(0 0,3 3,6 3)", "LINESTRING(0 0,2 2,3 3,1 1)", false); + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,4 4,6 3)", true); + test_geometry<ls, ls>("LINESTRING(0 0,4 4,6 3)", "LINESTRING(0 0,2 2,3 3,1 1)", false); + + test_geometry<ls, ls>("LINESTRING(0 0,2 2,3 3,1 1,5 3)", "LINESTRING(0 0,3 3,6 3)", false);*/ + + test_geometry<ls, mls>("LINESTRING(1 1, 2 2)", "MULTILINESTRING((0 0, 2 2),(3 3, 4 4))", true); + + test_geometry<mls, ls>("MULTILINESTRING((0 0, 2 2),(3 3, 4 4))", "LINESTRING(0 0, 5 5)", true); + + test_geometry<mls, mls>("MULTILINESTRING((1 1, 2 2),(3 3, 4 4))", "MULTILINESTRING((1 1, 2 2),(2 2, 5 5))", true); +} + +template <typename P> +void test_all() +{ + test_l_l<P>(); +} + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<int> >(); + 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/libs/geometry/test/algorithms/relational_operations/within/within_pointlike_xxx.cpp b/libs/geometry/test/algorithms/relational_operations/within/within_pointlike_xxx.cpp new file mode 100644 index 000000000..5ea4f09f2 --- /dev/null +++ b/libs/geometry/test/algorithms/relational_operations/within/within_pointlike_xxx.cpp @@ -0,0 +1,253 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#include "test_within.hpp" + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/multi/multi.hpp> +#include <boost/geometry/multi/geometries/multi_point.hpp> +#include <boost/geometry/multi/geometries/multi_linestring.hpp> +#include <boost/geometry/multi/geometries/multi_polygon.hpp> + +template <typename P> +void test_p_p() +{ + typedef bg::model::multi_point<P> mpt; + + test_geometry<P, P>("POINT(0 0)", "POINT(0 0)", true); + test_geometry<P, P>("POINT(0 0)", "POINT(1 1)", false); + + test_geometry<P, mpt>("POINT(0 0)", "MULTIPOINT(0 0, 1 1)", true); + test_geometry<P, mpt>("POINT(0 0)", "MULTIPOINT(1 1, 2 2)", false); +} + +template <typename P> +void test_p_l() +{ + typedef bg::model::segment<P> seg; + typedef bg::model::linestring<P> ls; + typedef bg::model::multi_linestring<ls> mls; + + test_geometry<P, seg>("POINT(1 1)", "LINESTRING(0 0, 2 2)", true); + test_geometry<P, seg>("POINT(0 0)", "LINESTRING(0 0, 1 1)", false); + test_geometry<P, seg>("POINT(1 0)", "LINESTRING(0 0, 1 1)", false); + + test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0,1 1,2 2)", false); + test_geometry<P, ls>("POINT(3 3)", "LINESTRING(0 0,1 1,2 2)", false); + test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0,2 2,3 3)", true); + + test_geometry<P, ls>("POINT(1 1)", "LINESTRING(0 0, 2 2)", true); + test_geometry<P, ls>("POINT(0 0)", "LINESTRING(0 0, 1 1)", false); + + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1))", true); + test_geometry<P, mls>("POINT(0 0)", "MULTILINESTRING((0 0,1 1,2 2),(0 0,0 1),(0 0,1 0))", false); + + test_geometry<P, mls>("POINT(1 1)", "MULTILINESTRING((0 0, 1 1),(1 1, 2 2))", true); + test_geometry<P, mls>("POINT(1 1)", "MULTILINESTRING((0 0, 1 1),(2 2, 3 3))", false); +} + +template <typename P> +void test_p_a() +{ + typedef bg::model::polygon<P> poly; + typedef bg::model::multi_polygon<poly> mpoly; + + // trivial case + test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", true, false); + + // on border/corner + test_ring<P>("POINT(0 0)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true); + test_ring<P>("POINT(0 1)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", false, true); + + // aligned to segment/vertex + test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", true, false); + test_ring<P>("POINT(1 1)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", true, false); + + // same polygon, but point on border + test_ring<P>("POINT(3 3)", "POLYGON((0 0,0 3,3 3,3 1,2 1,2 0,0 0))", false, true); + test_ring<P>("POINT(3 3)", "POLYGON((0 0,0 3,4 3,3 1,2 2,2 0,0 0))", false, true); + + // holes + test_geometry<P, poly>("POINT(2 2)", + "POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1))", false); + + // Real-life problem (solved now), point is in the middle, 409623 is also a coordinate + // on the border, has been wrong in the past (2009) + test_ring<P>("POINT(146383 409623)", + "POLYGON((146351 410597,146521 410659,147906 410363,148088 410420" + ",148175 410296,148281 409750,148215 409623,148154 409666,148154 409666" + ",148130 409625,148035 409626,148035 409626,148008 409544,147963 409510" + ",147993 409457,147961 409352,147261 408687,147008 408586,145714 408840" + ",145001 409033,144486 409066,144616 409308,145023 410286,145254 410488" + ",145618 410612,145618 410612,146015 410565,146190 410545,146351 410597))", + true, false); + + test_geometry<P, mpoly>("POINT(2 2)", + "MULTIPOLYGON(((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1)),((5 5,5 9,9 9,9 5,5 5)))", false); + test_geometry<P, mpoly>("POINT(1 1)", + "MULTIPOLYGON(((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1)),((5 5,5 9,9 9,9 5,5 5)))", false); + test_geometry<P, mpoly>("POINT(1 1)", + "MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0),(2 2,4 2,4 4,2 4,2 2)),((5 5,5 9,9 9,9 5,5 5)))", true); + test_geometry<P, mpoly>("POINT(6 6)", + "MULTIPOLYGON(((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1)),((5 5,5 9,9 9,9 5,5 5)))", true); +} + +template <typename P> +void test_all() +{ + test_p_p<P>(); + test_p_l<P>(); + test_p_a<P>(); +} + +template <typename Point> +void test_spherical() +{ + bg::model::polygon<Point> wrangel; + + // SQL Server check (no geography::STWithin, so check with intersection trick) + /* + + with q as ( + select geography::STGeomFromText('POLYGON((-178.569 71.5641,-179.034 71.5977,-179.305 71.5514,-179.629 71.5772,-180 71.5358,179.53 71.4383,178.872 71.2175,178.618 71.0355,178.791 70.7964,179.273 70.8886,179.678 70.8955,-180 70.9972,-179.274 70.9078,-178.819 70.98,-177.939 71.0375,-177.62 71.1166,-177.439 71.2269,-177.503 71.2775,-177.833 71.3461,-178.018 71.4497,-178.569 71.5641))',4326) as wrangel + ) + + select wrangel.STArea()/1000000.0 + ,geography::STGeomFromText('POINT(-179.3 71.27)',4326).STIntersection(wrangel).STAsText() as workaround_within_1 + ,geography::STGeomFromText('POINT(-179.9 70.95)',4326).STIntersection(wrangel).STAsText() as workaround_within_2 + ,geography::STGeomFromText('POINT(179.9 70.95)',4326).STIntersection(wrangel).STAsText() as workaround_within_3 + from q + + -> 7669.10402181435 POINT (-179.3 71.27) GEOMETRYCOLLECTION EMPTY GEOMETRYCOLLECTION EMPTY + + PostGIS knows Within for Geography neither, and the intersection trick gives the same result + + */ + + bg::read_wkt("POLYGON((-178.568604 71.564148,-178.017548 71.449692,-177.833313 71.3461,-177.502838 71.277466 ,-177.439453 71.226929,-177.620026 71.116638,-177.9389 71.037491,-178.8186 70.979965,-179.274445 70.907761,-180 70.9972,179.678314 70.895538,179.272766 70.888596,178.791016 70.7964,178.617737 71.035538,178.872192 71.217484,179.530273 71.4383 ,-180 71.535843 ,-179.628601 71.577194,-179.305298 71.551361,-179.03421 71.597748,-178.568604 71.564148))", wrangel); + + bool within = bg::within(Point(-179.3, 71.27), wrangel); + BOOST_CHECK_EQUAL(within, true); + + within = bg::within(Point(-179.9, 70.95), wrangel); + BOOST_CHECK_EQUAL(within, false); + + within = bg::within(Point(179.9, 70.95), wrangel); + BOOST_CHECK_EQUAL(within, false); + + // Test using great circle mapper + // http://www.gcmap.com/mapui?P=5E52N-9E53N-7E50N-5E52N,7E52.5N,8E51.5N,6E51N + + bg::model::polygon<Point> triangle; + bg::read_wkt("POLYGON((5 52,9 53,7 50,5 52))", triangle); + BOOST_CHECK_EQUAL(bg::within(Point(7, 52.5), triangle), true); + BOOST_CHECK_EQUAL(bg::within(Point(8.0, 51.5), triangle), false); + BOOST_CHECK_EQUAL(bg::within(Point(6.0, 51.0), triangle), false); +} + +void test_large_integers() +{ + typedef bg::model::point<int, 2, bg::cs::cartesian> int_point_type; + typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type; + + std::string const polygon_li = "POLYGON((1872000 528000,1872000 192000,1536119 192000,1536000 528000,1200000 528000,1200000 863880,1536000 863880,1872000 863880,1872000 528000))"; + bg::model::polygon<int_point_type> int_poly; + bg::model::polygon<double_point_type> double_poly; + bg::read_wkt(polygon_li, int_poly); + bg::read_wkt(polygon_li, double_poly); + + std::string const point_li = "POINT(1592000 583950)"; + int_point_type int_point; + double_point_type double_point; + bg::read_wkt(point_li, int_point); + bg::read_wkt(point_li, double_point); + + bool wi = bg::within(int_point, int_poly); + bool wd = bg::within(double_point, double_poly); + + BOOST_CHECK_MESSAGE(wi == wd, "within<a double> different from within<an int>"); +} + +void test_tickets() +{ + typedef boost::geometry::model::d2::point_xy<double> pt; + typedef boost::geometry::model::ring<pt> ring; + + // https://svn.boost.org/trac/boost/ticket/9628 + { + ring r; + r.push_back(pt(-19155.669324773193,54820.312032458620)); + r.push_back(pt(-13826.169324773080,54820.312032458627)); + r.push_back(pt(-13826.169324773078,52720.312032458663)); + r.push_back(pt(-12755.169324773129,52720.312032458663)); + r.push_back(pt(-12755.169324773129,51087.312032458671)); + r.push_back(pt(-12760.669324773080,51087.312032458671)); + r.push_back(pt(-12760.669324773082,51070.312032458627)); + r.push_back(pt(-19155.669324779392,51070.312032458620)); + r.push_back(pt(-19155.669324773193,54820.312032458620)); + + pt p( -12260.669324773118, 54820.312032458634 ); + + //boost::geometry::correct(r); + + bool within = boost::geometry::within(p, r); + BOOST_CHECK_EQUAL(within, false); + } + // similar + { + ring r; + r.push_back(pt(-14155.6,54820.312032458620)); + r.push_back(pt(-13826.1,54820.312032458625)); + r.push_back(pt(-12155.6,53720.3)); + r.push_back(pt(-14155.6,54820.312032458620)); + + pt p( -13826.0, 54820.312032458634 ); + + bool within = boost::geometry::within(p, r); + BOOST_CHECK_EQUAL(within, false); + } + + // https://svn.boost.org/trac/boost/ticket/10234 + { + pt p; + ring r; + bg::read_wkt("POINT(0.1377 5.00)", p); + bg::read_wkt("POLYGON((0.1277 4.97, 0.1277 5.00, 0.1278 4.9999999999999982, 0.1278 4.97, 0.1277 4.97))", r); + bool within = boost::geometry::within(p, r); + BOOST_CHECK_EQUAL(within, false); + bool covered_by = boost::geometry::covered_by(p, r); + BOOST_CHECK_EQUAL(covered_by, false); + } +} + +int test_main( int , char* [] ) +{ + test_large_integers(); + + test_all<bg::model::d2::point_xy<int> >(); + test_all<bg::model::d2::point_xy<double> >(); + + test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >(); + +#if defined(HAVE_TTMATH) + test_all<bg::model::d2::point_xy<ttmath_big> >(); + test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >(); +#endif + + test_tickets(); + + return 0; +} |