Chris@16
|
1 // Copyright 2004 The Trustees of Indiana University.
|
Chris@16
|
2
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 // Authors: Douglas Gregor
|
Chris@16
|
8 // Andrew Lumsdaine
|
Chris@16
|
9 #ifndef BOOST_GRAPH_CIRCLE_LAYOUT_HPP
|
Chris@16
|
10 #define BOOST_GRAPH_CIRCLE_LAYOUT_HPP
|
Chris@16
|
11 #include <boost/config/no_tr1/cmath.hpp>
|
Chris@16
|
12 #include <boost/math/constants/constants.hpp>
|
Chris@16
|
13 #include <utility>
|
Chris@16
|
14 #include <boost/graph/graph_traits.hpp>
|
Chris@16
|
15 #include <boost/graph/iteration_macros.hpp>
|
Chris@16
|
16 #include <boost/graph/topology.hpp>
|
Chris@16
|
17 #include <boost/static_assert.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost {
|
Chris@16
|
20 /**
|
Chris@16
|
21 * \brief Layout the graph with the vertices at the points of a regular
|
Chris@16
|
22 * n-polygon.
|
Chris@16
|
23 *
|
Chris@16
|
24 * The distance from the center of the polygon to each point is
|
Chris@16
|
25 * determined by the @p radius parameter. The @p position parameter
|
Chris@16
|
26 * must be an Lvalue Property Map whose value type is a class type
|
Chris@16
|
27 * containing @c x and @c y members that will be set to the @c x and
|
Chris@16
|
28 * @c y coordinates.
|
Chris@16
|
29 */
|
Chris@16
|
30 template<typename VertexListGraph, typename PositionMap, typename Radius>
|
Chris@16
|
31 void
|
Chris@16
|
32 circle_graph_layout(const VertexListGraph& g, PositionMap position,
|
Chris@16
|
33 Radius radius)
|
Chris@16
|
34 {
|
Chris@16
|
35 BOOST_STATIC_ASSERT (property_traits<PositionMap>::value_type::dimensions >= 2);
|
Chris@16
|
36 const double pi = boost::math::constants::pi<double>();
|
Chris@16
|
37
|
Chris@16
|
38 #ifndef BOOST_NO_STDC_NAMESPACE
|
Chris@16
|
39 using std::sin;
|
Chris@16
|
40 using std::cos;
|
Chris@16
|
41 #endif // BOOST_NO_STDC_NAMESPACE
|
Chris@16
|
42
|
Chris@16
|
43 typedef typename graph_traits<VertexListGraph>::vertices_size_type
|
Chris@16
|
44 vertices_size_type;
|
Chris@16
|
45
|
Chris@16
|
46 vertices_size_type n = num_vertices(g);
|
Chris@16
|
47
|
Chris@16
|
48 vertices_size_type i = 0;
|
Chris@16
|
49 double two_pi_over_n = 2. * pi / n;
|
Chris@16
|
50 BGL_FORALL_VERTICES_T(v, g, VertexListGraph) {
|
Chris@16
|
51 position[v][0] = radius * cos(i * two_pi_over_n);
|
Chris@16
|
52 position[v][1] = radius * sin(i * two_pi_over_n);
|
Chris@16
|
53 ++i;
|
Chris@16
|
54 }
|
Chris@16
|
55 }
|
Chris@16
|
56 } // end namespace boost
|
Chris@16
|
57
|
Chris@16
|
58 #endif // BOOST_GRAPH_CIRCLE_LAYOUT_HPP
|