~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to libs/geometry/doc/src/examples/geometries/register/point.cpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
//[register_point_2d
 
11
//` Show the use of the macro BOOST_GEOMETRY_REGISTER_POINT_2D
 
12
 
 
13
#include <iostream>
 
14
#include <boost/geometry.hpp>
 
15
#include <boost/geometry/geometries/register/point.hpp>
 
16
 
 
17
/*< Somewhere, any legacy point struct is defined >*/
 
18
struct legacy_point
 
19
{
 
20
    double x, y;
 
21
};
 
22
 
 
23
BOOST_GEOMETRY_REGISTER_POINT_2D(legacy_point, double, cs::cartesian, x, y) /*< The magic: adapt it to Boost.Geometry Point Concept >*/
 
24
 
 
25
int main()
 
26
{
 
27
    legacy_point p1, p2;
 
28
 
 
29
    namespace bg = boost::geometry;
 
30
 
 
31
    /*< Any Boost.Geometry function can be used for legacy point now. Here: assign_values and distance >*/
 
32
    bg::assign_values(p1, 1, 1);
 
33
    bg::assign_values(p2, 2, 2);
 
34
 
 
35
    double d = bg::distance(p1, p2);
 
36
 
 
37
    std::cout << "Distance: " << d << std::endl;
 
38
 
 
39
    return 0;
 
40
}
 
41
 
 
42
//]
 
43
 
 
44
 
 
45
//[register_point_2d_output
 
46
/*`
 
47
Output:
 
48
[pre
 
49
Distance: 1.41421
 
50
]
 
51
*/
 
52
//]