]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
f67539c2 TL |
19 | namespace boost |
20 | { | |
21 | /** | |
22 | * \brief Layout the graph with the vertices at the points of a regular | |
23 | * n-polygon. | |
24 | * | |
25 | * The distance from the center of the polygon to each point is | |
26 | * determined by the @p radius parameter. The @p position parameter | |
27 | * must be an Lvalue Property Map whose value type is a class type | |
28 | * containing @c x and @c y members that will be set to the @c x and | |
29 | * @c y coordinates. | |
30 | */ | |
31 | template < typename VertexListGraph, typename PositionMap, typename Radius > | |
32 | void circle_graph_layout( | |
33 | const VertexListGraph& g, PositionMap position, Radius radius) | |
34 | { | |
35 | BOOST_STATIC_ASSERT( | |
36 | property_traits< PositionMap >::value_type::dimensions >= 2); | |
37 | const double pi = boost::math::constants::pi< double >(); | |
7c673cae FG |
38 | |
39 | #ifndef BOOST_NO_STDC_NAMESPACE | |
7c673cae | 40 | using std::cos; |
f67539c2 | 41 | using std::sin; |
7c673cae FG |
42 | #endif // BOOST_NO_STDC_NAMESPACE |
43 | ||
f67539c2 TL |
44 | typedef typename graph_traits< VertexListGraph >::vertices_size_type |
45 | vertices_size_type; | |
7c673cae FG |
46 | |
47 | vertices_size_type n = num_vertices(g); | |
f67539c2 | 48 | |
7c673cae FG |
49 | vertices_size_type i = 0; |
50 | double two_pi_over_n = 2. * pi / n; | |
f67539c2 TL |
51 | BGL_FORALL_VERTICES_T(v, g, VertexListGraph) |
52 | { | |
53 | position[v][0] = radius * cos(i * two_pi_over_n); | |
54 | position[v][1] = radius * sin(i * two_pi_over_n); | |
55 | ++i; | |
7c673cae | 56 | } |
f67539c2 | 57 | } |
7c673cae FG |
58 | } // end namespace boost |
59 | ||
60 | #endif // BOOST_GRAPH_CIRCLE_LAYOUT_HPP |