From 2753f5e30ae33f07a42e2827db3e408a8d5cecd5 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Wed, 9 Apr 2014 01:34:34 +0200 Subject: [PATCH] [crosses] add missing files required by bg::crosses() algorithm --- doc/reference/algorithms/crosses.qbk | 20 ++++ include/boost/geometry/algorithms/crosses.hpp | 97 +++++++++++++++++++ test/algorithms/crosses.cpp | 96 ++++++++++++++++++ test/algorithms/test_crosses.hpp | 50 ++++++++++ 4 files changed, 263 insertions(+) create mode 100644 doc/reference/algorithms/crosses.qbk create mode 100644 include/boost/geometry/algorithms/crosses.hpp create mode 100644 test/algorithms/crosses.cpp create mode 100644 test/algorithms/test_crosses.hpp diff --git a/doc/reference/algorithms/crosses.qbk b/doc/reference/algorithms/crosses.qbk new file mode 100644 index 000000000..7ca1717db --- /dev/null +++ b/doc/reference/algorithms/crosses.qbk @@ -0,0 +1,20 @@ +[/============================================================================ + Boost.Geometry (aka GGL, Generic Geometry Library) + + Copyright (c) 2009-2012 Barend Gehrels, Amsterdam, the Netherlands. + Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + Copyright (c) 2009-2012 Bruno Lalande, Paris, France. + + 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 +=============================================================================/] + +[def __this_function__ crosses] + +[heading_conformance_ogc __this_function__..Crosses] diff --git a/include/boost/geometry/algorithms/crosses.hpp b/include/boost/geometry/algorithms/crosses.hpp new file mode 100644 index 000000000..a00da18bf --- /dev/null +++ b/include/boost/geometry/algorithms/crosses.hpp @@ -0,0 +1,97 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// 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) + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +#ifndef BOOST_GEOMETRY_ALGORITHMS_CROSSES_HPP +#define BOOST_GEOMETRY_ALGORITHMS_CROSSES_HPP + +#include + +#include + +#include + +#include + +#include + +namespace boost { namespace geometry +{ + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace crosses +{ + +struct use_relate +{ + template + static inline bool apply(Geometry1 const& g1, Geometry2 const& g2) + { + typedef typename detail::relate:: + static_mask_crosses_type::type static_mask; + + return detail::relate::relate(g1, g2); + } +}; + +}} // namespace detail::crosses +#endif // DOXYGEN_NO_DETAIL + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +< + typename Geometry1, + typename Geometry2, + typename Tag1 = typename tag::type, + typename Tag2 = typename tag::type +> +struct crosses + : detail::crosses::use_relate +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +/*! +\brief \brief_check2{crosses} +\ingroup crosses +\return \return_check2{crosses} + +\qbk{[include reference/algorithms/crosses.qbk]} +*/ +template +inline bool crosses(Geometry1 const& geometry1, Geometry2 const& geometry2) +{ + concept::check(); + concept::check(); + + return dispatch::crosses + < + Geometry1, + Geometry2 + >::apply(geometry1, geometry2); +} + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_CROSSES_HPP diff --git a/test/algorithms/crosses.cpp b/test/algorithms/crosses.cpp new file mode 100644 index 000000000..97743df39 --- /dev/null +++ b/test/algorithms/crosses.cpp @@ -0,0 +1,96 @@ +// 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 + + +#include +#include +#include +#include + +template +void test_pl() +{ + typedef bg::model::multi_point

mpt; + typedef bg::model::linestring

ls; + + // not implemented yet + /*test_geometry("MULTIPOINT(0 0,1 1)", "LINESTRING(0 0,1 0,3 3)", true); + test_geometry("MULTIPOINT(0 0,1 1)", "LINESTRING(0 0,1 1,3 3)", false);*/ +} + +template +void test_pa() +{ + typedef bg::model::multi_point

mpt; + typedef bg::model::polygon

poly; + typedef bg::model::multi_polygon mpoly; + + // not implemented yet + /*test_geometry("MULTIPOINT(0 0,6 6)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry("MULTIPOINT(0 0,1 1)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false);*/ +} + +template +void test_ll() +{ + typedef bg::model::linestring

ls; + typedef bg::model::multi_linestring mls; + + test_geometry("LINESTRING(0 0,2 2,4 4)", "LINESTRING(0 1,2 1,3 1)", true); + test_geometry("LINESTRING(0 0,2 2)", "LINESTRING(0 1,2 1)", true); + test_geometry("LINESTRING(0 0,2 2,4 4)", "LINESTRING(0 1,1 1,2 2,3 2)", false); + + test_geometry("LINESTRING(0 0,2 2,4 4)", "MULTILINESTRING((0 1,4 1),(0 2,4 2))", true); + + test_geometry("MULTILINESTRING((0 0,2 2,4 4),(3 0,3 4))", "MULTILINESTRING((0 1,4 1),(0 2,4 2))", true); +} + +template +void test_la() +{ + typedef bg::model::linestring

ls; + typedef bg::model::multi_linestring mls; + typedef bg::model::polygon

poly; + typedef bg::model::multi_polygon mpoly; + + test_geometry("LINESTRING(0 0, 10 10)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); + test_geometry("LINESTRING(0 0, 10 0)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + test_geometry("LINESTRING(1 1, 5 5)", "POLYGON((0 0,0 5,5 5,5 0,0 0))", false); + + test_geometry("MULTILINESTRING((1 1, 5 5),(6 6,7 7))", "POLYGON((0 0,0 5,5 5,5 0,0 0))", true); +} + +template +void test_2d() +{ + test_pl

(); + test_pa

(); + test_ll

(); + test_la

(); +} + +int test_main( int , char* [] ) +{ + test_2d >(); + test_2d >(); + +#if defined(HAVE_TTMATH) + test_2d >(); +#endif + + //test_3d >(); + + return 0; +} diff --git a/test/algorithms/test_crosses.hpp b/test/algorithms/test_crosses.hpp new file mode 100644 index 000000000..92cbe7f3c --- /dev/null +++ b/test/algorithms/test_crosses.hpp @@ -0,0 +1,50 @@ +// 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 + +#include +#include +#include +#include +#include + +#include + + +template +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); +} + + +#endif // BOOST_GEOMETRY_TEST_CROSSES_HPP