diff --git a/include/boost/geometry/algorithms/detail/relate/linear_linear.hpp b/include/boost/geometry/algorithms/detail/relate/linear_linear.hpp index 1067f43d3..008779a44 100644 --- a/include/boost/geometry/algorithms/detail/relate/linear_linear.hpp +++ b/include/boost/geometry/algorithms/detail/relate/linear_linear.hpp @@ -16,6 +16,8 @@ #include #include +#include + namespace boost { namespace geometry { @@ -86,7 +88,7 @@ struct linear_linear // TODO: handle also linestrings with points_num == 2 and equals(front, back) - treat like point? - result res("FFFFFFFFF"); + result res("FFFFFFFFT"); // TODO: implement generic function working also for multilinestrings, also use it in point_in_geometry bool has_boundary1 = ! detail::equals::equals_point_point(front(geometry1), back(geometry1)); @@ -119,7 +121,7 @@ struct linear_linear std::deque::turn_info> turns; - turns::get_turns::apply(turns, geometry2, geometry2); + turns::get_turns::apply(turns, geometry1, geometry2); // TODO: turns must be analysed this way only if it's possible to go out and in on the same point // for linear geometries union or intersection operation was detected diff --git a/include/boost/geometry/algorithms/detail/relate/relate.hpp b/include/boost/geometry/algorithms/detail/relate/relate.hpp new file mode 100644 index 000000000..4bccdc3d8 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/relate/relate.hpp @@ -0,0 +1,93 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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_ALGORITHMS_DETAIL_RELATE_RELATE_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_RELATE_HPP + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace boost { namespace geometry +{ + +#ifndef DOXYGEN_NO_DETAIL +namespace detail_dispatch { namespace relate { + +template ::type, + typename Tag2 = typename geometry::tag::type> +struct relate : not_implemented +{}; + +template +struct relate + : detail::relate::point_point +{}; + +template +struct relate + : detail::relate::point_geometry +{}; + +template +struct relate + : detail::relate::geometry_point +{}; + +template +struct relate + : detail::relate::linear_linear +{}; + +}} // namespace detail_dispatch::relate + +namespace detail { namespace relate { + +template +inline result relate(Geometry1 const& geometry1, Geometry2 const& geometry2) +{ + return detail_dispatch::relate::relate::apply(geometry1, geometry2); +} + +}} // namespace detail::relate +#endif // DOXYGEN_NO_DETAIL + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_RELATE_HPP diff --git a/include/boost/geometry/algorithms/detail/relate/result.hpp b/include/boost/geometry/algorithms/detail/relate/result.hpp index 544e8d2d8..424162125 100644 --- a/include/boost/geometry/algorithms/detail/relate/result.hpp +++ b/include/boost/geometry/algorithms/detail/relate/result.hpp @@ -67,6 +67,11 @@ public: ::memset(array, v, 9); } + std::pair get_code() const + { + return std::make_pair(array, array+9); + } + private: char array[9]; }; diff --git a/include/boost/geometry/algorithms/within.hpp b/include/boost/geometry/algorithms/within.hpp index 1f5c805de..75040782b 100644 --- a/include/boost/geometry/algorithms/within.hpp +++ b/include/boost/geometry/algorithms/within.hpp @@ -55,8 +55,6 @@ #include #include -#include - namespace boost { namespace geometry { diff --git a/test/algorithms/relate.cpp b/test/algorithms/relate.cpp new file mode 100644 index 000000000..a9dade464 --- /dev/null +++ b/test/algorithms/relate.cpp @@ -0,0 +1,122 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// 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) + +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +namespace bgdr = bg::detail::relate; + +template +void check_geometry(Geometry1 const& geometry1, + Geometry2 const& geometry2, + std::string const& wkt1, + std::string const& wkt2, + std::string const& expected) +{ + bgdr::result res = bgdr::relate(geometry1, geometry2); + std::string res_str(boost::begin(res.get_code()), boost::end(res.get_code())); + bool ok = boost::equal(res_str, expected); + + BOOST_CHECK_MESSAGE(ok, + "relate: " << wkt1 + << " and " << wkt2 + << " -> Expected: " << expected + << " detected: " << res_str); +} + +template +void test_geometry(std::string const& wkt1, + std::string const& wkt2, + std::string const& expected) +{ + Geometry1 geometry1; + Geometry2 geometry2; + bg::read_wkt(wkt1, geometry1); + bg::read_wkt(wkt2, geometry2); + check_geometry(geometry1, geometry2, wkt1, wkt2, expected); +} + +template +void test_linestring_linestring() +{ + typedef bg::model::linestring

ls; +// test_geometry("LINESTRING(0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true); + +// test_geometry("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 3 2)", true); +// test_geometry("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(0 0, 2 2, 3 2)", true); +// test_geometry("LINESTRING(0 0, 1 1, 2 2, 3 2)", "LINESTRING(3 2, 2 2, 0 0)", true); +// test_geometry("LINESTRING(3 2, 2 2, 1 1, 0 0)", "LINESTRING(3 2, 2 2, 0 0)", true); + +// test_geometry("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", true); +// test_geometry("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(0 0, 2 2, 4 2)", true); +// test_geometry("LINESTRING(1 1, 2 2, 3 2)", "LINESTRING(4 2, 2 2, 0 0)", true); +// test_geometry("LINESTRING(3 2, 2 2, 1 1)", "LINESTRING(4 2, 2 2, 0 0)", true); + +// test_geometry("LINESTRING(1 1, 2 2, 2 2)", "LINESTRING(0 0, 2 2, 4 2)", true); + +// test_geometry("LINESTRING(1 1, 2 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry("LINESTRING(1 1, 2 2, 3 2, 3 3)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry("LINESTRING(1 1, 2 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry("LINESTRING(1 1, 2 2, 3 2, 3 1)", "LINESTRING(0 0, 2 2, 4 2)", false); + +// test_geometry("LINESTRING(0 1, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry("LINESTRING(0 1, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry("LINESTRING(1 0, 1 1, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); +// test_geometry("LINESTRING(1 0, 0 0, 2 2, 3 2)", "LINESTRING(0 0, 2 2, 4 2)", false); + +// test_geometry("LINESTRING(0 0)", "LINESTRING(0 0)", false); +// test_geometry("LINESTRING(1 1)", "LINESTRING(0 0, 2 2)", true); +// test_geometry("LINESTRING(0 0)", "LINESTRING(0 0, 2 2)", false); +// test_geometry("LINESTRING(0 0, 1 1)", "LINESTRING(0 0)", false); + +// test_geometry("LINESTRING(0 0,5 0,3 0,6 0)", "LINESTRING(0 0,6 0)", true); +// test_geometry("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,3 3,6 3)", true); + + test_geometry("LINESTRING(0 0,2 2,3 3,1 1,5 3)", "LINESTRING(0 0,3 3,6 3)", "1F100F1FT"); +} + +template +void test_all() +{ + test_linestring_linestring

(); +} + +int test_main( int , char* [] ) +{ + test_all >(); + test_all >(); + +#if defined(HAVE_TTMATH) + test_all >(); +#endif + + return 0; +} diff --git a/test/algorithms/within.cpp b/test/algorithms/within.cpp index c9d7b642d..bf15c8385 100644 --- a/test/algorithms/within.cpp +++ b/test/algorithms/within.cpp @@ -49,20 +49,6 @@ void test_linestring_linestring() test_geometry("LINESTRING(0 0,5 0,3 0,6 0)", "LINESTRING(0 0,6 0)", true); test_geometry("LINESTRING(0 0,2 2,3 3,1 1)", "LINESTRING(0 0,3 3,6 3)", true); test_geometry("LINESTRING(0 0,2 2,3 3,1 1,5 3)", "LINESTRING(0 0,3 3,6 3)", false); - - // RELATE TEST - ls geometry1; - ls geometry2; - bg::read_wkt("LINESTRING(0 0,2 2,3 3,1 1,5 3)", geometry1); - bg::read_wkt("LINESTRING(0 0,3 3,6 3)", geometry2); - namespace bgr = bg::detail::relate; - bgr::result - res = bgr::linear_linear::apply(geometry1, geometry2); - bool ii = res.template get() != 'F'; - bool ie = res.template get() != 'F'; - bool be = res.template get() != 'F'; - bool w = ii && !ie && !be; - BOOST_CHECK(!w); } template