1 // Copyright 2004 The Trustees of Indiana University.
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)
7 // Authors: Douglas Gregor
9 #ifndef BOOST_GRAPH_CIRCLE_LAYOUT_HPP
10 #define BOOST_GRAPH_CIRCLE_LAYOUT_HPP
13 #include <boost/graph/graph_traits.hpp>
17 * \brief Layout the graph with the vertices at the points of a regular
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
26 template<typename VertexListGraph, typename PositionMap, typename Radius>
28 circle_graph_layout(const VertexListGraph& g, PositionMap position,
31 const double pi = 3.14159;
33 #ifndef BOOST_NO_STDC_NAMESPACE
36 #endif // BOOST_NO_STDC_NAMESPACE
38 typedef typename graph_traits<VertexListGraph>::vertices_size_type
41 vertices_size_type n = num_vertices(g);
43 typedef typename graph_traits<VertexListGraph>::vertex_iterator
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);
53 } // end namespace boost
55 #endif // BOOST_GRAPH_CIRCLE_LAYOUT_HPP