1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_GEOMETRY_ALGORITHMS_INVERSE_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_INVERSE_HPP
13 #include <boost/geometry.hpp>
15 namespace boost { namespace geometry
18 // TODO: this is shared with sectionalize, move to somewhere else (assign?)
19 template <typename Box, typename Value>
20 inline void enlarge_box(Box& box, Value value)
22 geometry::set<0, 0>(box, geometry::get<0, 0>(box) - value);
23 geometry::set<0, 1>(box, geometry::get<0, 1>(box) - value);
24 geometry::set<1, 0>(box, geometry::get<1, 0>(box) + value);
25 geometry::set<1, 1>(box, geometry::get<1, 1>(box) + value);
28 // TODO: when this might be moved outside extensions it should of course
29 // input/output a Geometry, instead of a WKT
30 template <typename Geometry, typename Value>
31 inline std::string inverse(std::string const& wkt, Value margin)
34 read_wkt(wkt, geometry);
36 geometry::correct(geometry);
38 geometry::model::box<typename point_type<Geometry>::type> env;
39 geometry::envelope(geometry, env);
41 // Make its envelope a bit larger
42 enlarge_box(env, margin);
44 Geometry env_as_polygon;
45 geometry::convert(env, env_as_polygon);
47 Geometry inversed_result;
48 geometry::difference(env_as_polygon, geometry, inversed_result);
50 std::ostringstream out;
52 out << geometry::wkt(inversed_result);
56 }} // namespace boost::geometry
59 #endif // BOOST_GEOMETRY_ALGORITHMS_INVERSE_HPP