]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/include/boost/geometry/extensions/algorithms/inverse.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / extensions / algorithms / inverse.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2//
3// Copyright (c) 2015 Barend Gehrels, Amsterdam, the Netherlands.
4
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)
8
9
10#ifndef BOOST_GEOMETRY_ALGORITHMS_INVERSE_HPP
11#define BOOST_GEOMETRY_ALGORITHMS_INVERSE_HPP
12
13#include <boost/geometry.hpp>
14
15namespace boost { namespace geometry
16{
17
18// TODO: this is shared with sectionalize, move to somewhere else (assign?)
19template <typename Box, typename Value>
20inline void enlarge_box(Box& box, Value value)
21{
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);
26}
27
28// TODO: when this might be moved outside extensions it should of course
29// input/output a Geometry, instead of a WKT
30template <typename Geometry, typename Value>
31inline std::string inverse(std::string const& wkt, Value margin)
32{
33 Geometry geometry;
34 read_wkt(wkt, geometry);
35
36 geometry::correct(geometry);
37
38 geometry::model::box<typename point_type<Geometry>::type> env;
39 geometry::envelope(geometry, env);
40
41 // Make its envelope a bit larger
42 enlarge_box(env, margin);
43
44 Geometry env_as_polygon;
45 geometry::convert(env, env_as_polygon);
46
47 Geometry inversed_result;
48 geometry::difference(env_as_polygon, geometry, inversed_result);
49
50 std::ostringstream out;
51
52 out << geometry::wkt(inversed_result);
53 return out.str();
54}
55
56}} // namespace boost::geometry
57
58
59#endif // BOOST_GEOMETRY_ALGORITHMS_INVERSE_HPP