]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/doc/src/examples/algorithms/comparable_distance.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
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)
10 //[comparable_distance
11 //` Shows how to efficiently get the closest point
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
18 #include <boost/numeric/conversion/bounds.hpp>
19 #include <boost/foreach.hpp>
23 typedef boost::geometry::model::d2::point_xy
<double> point_type
;
25 point_type
p(1.4, 2.6);
27 std::vector
<point_type
> v
;
28 for (double x
= 0.0; x
<= 4.0; x
++)
30 for (double y
= 0.0; y
<= 4.0; y
++)
32 v
.push_back(point_type(x
, y
));
37 double min_d
= boost::numeric::bounds
<double>::highest();
38 BOOST_FOREACH(point_type
const& pv
, v
)
40 double d
= boost::geometry::comparable_distance(p
, pv
);
49 << "Closest: " << boost::geometry::dsv(min_p
) << std::endl
50 << "At: " << boost::geometry::distance(p
, min_p
) << std::endl
;
58 //[comparable_distance_output