]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/doc/src/examples/algorithms/assign_points.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / doc / src / examples / algorithms / assign_points.cpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// QuickBook Example
3
4// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6// Use, modification and distribution is subject to the Boost Software License,
7// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10//[assign_points
11//` Shows usage of Boost.Geometry's assign, Boost.Assign, and Boost.Range to assign ranges of a linestring
12
13#include <iostream>
14
15#include <boost/geometry.hpp>
16#include <boost/geometry/geometries/linestring.hpp>
17#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
18
19#include <boost/assign.hpp>
20#include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>
21
22BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
23
24template <typename T>
25struct x_between
26{
27 x_between(T a, T b)
28 : fa(a), fb(b)
29 {}
30
31 template <typename P>
32 bool operator()(P const& p) const
33 {
34 return boost::geometry::get<0>(p) >= fa
35 && boost::geometry::get<0>(p) <= fb;
36 }
37private :
38 T fa, fb;
39};
40
41
42int main()
43{
44 using namespace boost::assign;
45
46 typedef boost::geometry::model::linestring<boost::tuple<int, int> > ls;
47
48 ls line1, line2, line3;
49
50 line1 = tuple_list_of(0, 0)(2, 3)(4, 0)(6, 3)(8, 0)(10, 3)(12, 0); /*< tuple_list_of is part of Boost.Assign and can be used for Boost.Geometry if points are tuples >*/
51 boost::geometry::assign_points(line2, tuple_list_of(0, 0)(2, 2)(4, 0)(6, 2)(8, 0)); /*< tuple_list_of delivers a range and can therefore be used in boost::geometry::assign >*/
52 boost::geometry::assign_points(line3, line1 | boost::adaptors::filtered(x_between<int>(4, 8))); /*< Boost.Range adaptors can also be used in boost::geometry::assign >*/
53
54 std::cout << "line 1: " << boost::geometry::dsv(line1) << std::endl;
55 std::cout << "line 2: " << boost::geometry::dsv(line2) << std::endl;
56 std::cout << "line 3: " << boost::geometry::dsv(line3) << std::endl;
57
58 return 0;
59}
60
61//]
62
63
64//[assign_points_output
65/*`
66Output:
67[pre
68line 1: ((0, 0), (2, 3), (4, 0), (6, 3), (8, 0), (10, 3), (12, 0))
69line 2: ((0, 0), (2, 2), (4, 0), (6, 2), (8, 0))
70line 3: ((4, 0), (6, 3), (8, 0))
71]
72*/
73//]