#### /Src/Dependencies/Boost/libs/geometry/doc/src/examples/algorithms/assign.cpp

http://hadesmem.googlecode.com/
C++ | 66 lines | 29 code | 15 blank | 22 comment | 0 complexity | 9e3d4f2e2fc0f5dc9ca7c0655f226a3f 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//[assign
11//` Shows how to assign a geometry from another geometry
12
13#include <iostream>
14
15#include <boost/geometry.hpp>
16#include <boost/geometry/geometries/box.hpp>
17#include <boost/geometry/geometries/point_xy.hpp>
18#include <boost/geometry/geometries/polygon.hpp>
19#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
20
21BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
22
23int main()
24{
25    typedef boost::geometry::model::d2::point_xy<double> point;
26    typedef boost::geometry::model::box<point> box;
27    typedef boost::geometry::model::polygon<point> polygon;
28
29    point p1;
30    box b;
31    boost::geometry::assign_values(p1, 1, 1);
32    boost::geometry::assign_values(b, 1, 1, 2, 2);
33
34    // Assign a box to a polygon (target = source)
35    polygon p;
36    boost::geometry::assign(p, b);
37
38    // Assign a point to another point type (conversion of point-type)
39    boost::tuple<double, double> p2;
40    boost::geometry::assign(p2, p1);
41
42    using boost::geometry::dsv;
43    std::cout
44        << "box: " << dsv(b) << std::endl
45        << "polygon: " << dsv(p) << std::endl
46        << "point: " << dsv(p1) << std::endl
47        << "point tuples: " << dsv(p2) << std::endl
48        ;
49
50    return 0;
51}
52
53//]
54
55
56//[assign_output
57/*`
58Output:
59[pre
60box: ((1, 1), (2, 2))
61polygon: (((1, 1), (1, 2), (2, 2), (2, 1), (1, 1)))
62point: (1, 1)
63point tuples: (1, 1)
64]
65*/
66//]
```