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