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 //[boost_range_filtered
11 //` Shows how to use a Boost.Geometry linestring, filtered by Boost.Range adaptor
12
13 #include <iostream>
14
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/linestring.hpp>
17 #include <boost/geometry/geometries/point_xy.hpp>
18 #include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>
19
20 struct not_two
21 {
22 template <typename P>
operator ()not_two23 bool operator()(P const& p) const
24 {
25 return boost::geometry::get<1>(p) != 2;
26 }
27 };
28
29
main()30 int main()
31 {
32 typedef boost::geometry::model::d2::point_xy<int> xy;
33 boost::geometry::model::linestring<xy> line;
34 line.push_back(xy(0, 0));
35 line.push_back(xy(1, 1));
36 line.push_back(xy(2, 2));
37 line.push_back(xy(3, 1));
38 line.push_back(xy(4, 0));
39 line.push_back(xy(5, 1));
40 line.push_back(xy(6, 2));
41 line.push_back(xy(7, 1));
42 line.push_back(xy(8, 0));
43
44 using boost::adaptors::filtered;
45 std::cout
46 << boost::geometry::length(line) << std::endl
47 << boost::geometry::length(line | filtered(not_two())) << std::endl
48 << boost::geometry::dsv(line | filtered(not_two())) << std::endl;
49
50 return 0;
51 }
52
53 //]
54
55 //[boost_range_filtered_output
56 /*`
57 Output:
58 [pre
59 11.3137
60 9.65685
61 ((0, 0), (1, 1), (3, 1), (4, 0), (5, 1), (7, 1), (8, 0))
62 ]
63 */
64 //]
65