• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_uniqued
11 //` Shows how to use a Boost.Geometry ring, made unique by Boost.Range adaptor
12 
13 #include <iostream>
14 
15 #include <boost/assign.hpp>
16 
17 #include <boost/geometry.hpp>
18 #include <boost/geometry/geometries/point_xy.hpp>
19 #include <boost/geometry/geometries/ring.hpp>
20 #include <boost/geometry/geometries/adapted/boost_range/uniqued.hpp>
21 
22 typedef boost::geometry::model::d2::point_xy<int> xy;
23 
operator ==(xy const & left,xy const & right)24 inline bool operator==(xy const& left, xy const& right)
25 {
26     boost::geometry::equal_to<xy> eq;
27     return eq(left, right);
28 }
29 
30 
main()31 int main()
32 {
33     using namespace boost::assign;
34     using boost::adaptors::uniqued;
35 
36     boost::geometry::model::ring<xy> ring;
37     ring += xy(0, 0);
38     ring += xy(0, 1);
39     ring += xy(0, 2);
40     ring += xy(1, 2);
41     ring += xy(2, 2);
42     ring += xy(2, 2);
43     ring += xy(2, 2);
44     ring += xy(2, 0);
45     ring += xy(0, 0);
46 
47     std::cout
48         << "Normal: " << boost::geometry::dsv(ring) << std::endl
49         << "Unique: " << boost::geometry::dsv(ring | uniqued) << std::endl;
50 
51     return 0;
52 }
53 
54 //]
55 
56 //[boost_range_uniqued_output
57 /*`
58 Output:
59 [pre
60 Normal : ((0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 0), (0, 0))
61 uniqued: ((0, 0), (0, 2), (2, 2), (0, 0))
62 ]
63 */
64 //]
65