• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 // QuickBook Example
3 
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland.
6 
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 //[box
12 //` Declaration and use of the Boost.Geometry model::box, modelling the Box Concept
13 
14 #include <iostream>
15 #include <boost/geometry.hpp>
16 
17 namespace bg = boost::geometry;
18 
main()19 int main()
20 {
21     typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
22     typedef bg::model::box<point_t> box_t;
23 
24     box_t box1; /*< Default-construct a box. >*/
25     box_t box2(point_t(0.0, 0.0), point_t(5.0, 5.0)); /*< Construct, assigning min and max corner point. >*/
26 
27 #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
28 
29     box_t box3{{0.0, 0.0}, {5.0, 5.0}}; /*< Construct, using C++11 unified initialization syntax. >*/
30 
31 #endif
32 
33     bg::set<bg::min_corner, 0>(box1, 1.0); /*< Set a coordinate, generic. >*/
34     bg::set<bg::min_corner, 1>(box1, 2.0);
35     box1.max_corner().set<0>(3.0); /*< Set a coordinate, class-specific ([*Note]: prefer `bg::set()`). >*/
36     box1.max_corner().set<1>(4.0);
37 
38     double min_x = bg::get<bg::min_corner, 0>(box1); /*< Get a coordinate, generic. >*/
39     double min_y = bg::get<bg::min_corner, 1>(box1);
40     double max_x = box1.max_corner().get<0>(); /*< Get a coordinate, class-specific ([*Note]: prefer `bg::get()`). >*/
41     double max_y = box1.max_corner().get<1>();
42 
43     std::cout << min_x << ", " << min_y << ", " << max_x << ", " << max_y << std::endl;
44 
45     return 0;
46 }
47 
48 //]
49 
50 
51 //[box_output
52 /*`
53 Output:
54 [pre
55 1, 2, 3, 4
56 ]
57 */
58 //]
59