1 | // Copyright 2004 The Trustees of Indiana University.
|
---|
2 |
|
---|
3 | // Use, modification and distribution is subject to the Boost Software
|
---|
4 | // License, Version 1.0. (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 <cmath>
|
---|
12 | #include <utility>
|
---|
13 | #include <boost/graph/graph_traits.hpp>
|
---|
14 |
|
---|
15 | namespace boost {
|
---|
16 | /**
|
---|
17 | * \brief Layout the graph with the vertices at the points of a regular
|
---|
18 | * n-polygon.
|
---|
19 | *
|
---|
20 | * The distance from the center of the polygon to each point is
|
---|
21 | * determined by the @p radius parameter. The @p position parameter
|
---|
22 | * must be an Lvalue Property Map whose value type is a class type
|
---|
23 | * containing @c x and @c y members that will be set to the @c x and
|
---|
24 | * @c y coordinates.
|
---|
25 | */
|
---|
26 | template<typename VertexListGraph, typename PositionMap, typename Radius>
|
---|
27 | void
|
---|
28 | circle_graph_layout(const VertexListGraph& g, PositionMap position,
|
---|
29 | Radius radius)
|
---|
30 | {
|
---|
31 | const double pi = 3.14159;
|
---|
32 |
|
---|
33 | #ifndef BOOST_NO_STDC_NAMESPACE
|
---|
34 | using std::sin;
|
---|
35 | using std::cos;
|
---|
36 | #endif // BOOST_NO_STDC_NAMESPACE
|
---|
37 |
|
---|
38 | typedef typename graph_traits<VertexListGraph>::vertices_size_type
|
---|
39 | vertices_size_type;
|
---|
40 |
|
---|
41 | vertices_size_type n = num_vertices(g);
|
---|
42 |
|
---|
43 | typedef typename graph_traits<VertexListGraph>::vertex_iterator
|
---|
44 | vertex_iterator;
|
---|
45 |
|
---|
46 | vertices_size_type i = 0;
|
---|
47 | for(std::pair<vertex_iterator, vertex_iterator> v = vertices(g);
|
---|
48 | v.first != v.second; ++v.first, ++i) {
|
---|
49 | position[*v.first].x = radius * cos(i * 2 * pi / n);
|
---|
50 | position[*v.first].y = radius * sin(i * 2 * pi / n);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | } // end namespace boost
|
---|
54 |
|
---|
55 | #endif // BOOST_GRAPH_CIRCLE_LAYOUT_HPP
|
---|