PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/doc/src/examples/views/box_view.cpp

http://hadesmem.googlecode.com/
C++ | 58 lines | 21 code | 16 blank | 21 comment | 2 complexity | 536b2c5fd070b95cbffe899b9392953b MD5 | raw file
 1// Boost.Geometry (aka GGL, Generic Geometry Library)
 2// QuickBook Example
 3
 4// Copyright (c) 2011 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//[box_view
11//` Shows usage of the Boost.Range compatible view on a box
12
13#include <iostream>
14
15#include <boost/geometry.hpp>
16
17
18int main()
19{
20    typedef boost::geometry::model::box
21        <
22            boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
23        > box_type;
24        
25    // Define the Boost.Range compatible type:
26    typedef boost::geometry::box_view<box_type> box_view;        
27        
28    box_type box;
29    boost::geometry::assign_values(box, 0, 0, 4, 4);
30    
31    box_view view(box);
32    
33    // Iterating in clockwise direction over the points of this box
34    for (boost::range_iterator<box_view const>::type it = boost::begin(view);
35        it != boost::end(view); ++it)
36    {
37        std::cout << " " << boost::geometry::dsv(*it);
38    }
39    std::cout << std::endl;
40    
41    // Note that a box_view is tagged as a ring, so supports area etc.
42    std::cout << "Area: " << boost::geometry::area(view) << std::endl;
43    
44    return 0;
45}
46
47//]
48
49
50//[box_view_output
51/*`
52Output:
53[pre
54 (0, 0) (0, 4) (4, 4) (4, 0) (0, 0)
55Area: 16
56]
57*/
58//]