williamr@2: // Copyright 2004 The Trustees of Indiana University. williamr@2: williamr@2: // Distributed under the Boost Software License, Version 1.0. williamr@2: // (See accompanying file LICENSE_1_0.txt or copy at williamr@2: // http://www.boost.org/LICENSE_1_0.txt) williamr@2: williamr@2: // Authors: Douglas Gregor williamr@2: // Andrew Lumsdaine williamr@2: #ifndef BOOST_GRAPH_CIRCLE_LAYOUT_HPP williamr@2: #define BOOST_GRAPH_CIRCLE_LAYOUT_HPP williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: namespace boost { williamr@2: /** williamr@2: * \brief Layout the graph with the vertices at the points of a regular williamr@2: * n-polygon. williamr@2: * williamr@2: * The distance from the center of the polygon to each point is williamr@2: * determined by the @p radius parameter. The @p position parameter williamr@2: * must be an Lvalue Property Map whose value type is a class type williamr@2: * containing @c x and @c y members that will be set to the @c x and williamr@2: * @c y coordinates. williamr@2: */ williamr@2: template williamr@2: void williamr@2: circle_graph_layout(const VertexListGraph& g, PositionMap position, williamr@2: Radius radius) williamr@2: { williamr@2: const double pi = 3.14159; williamr@2: williamr@2: #ifndef BOOST_NO_STDC_NAMESPACE williamr@2: using std::sin; williamr@2: using std::cos; williamr@2: #endif // BOOST_NO_STDC_NAMESPACE williamr@2: williamr@2: typedef typename graph_traits::vertices_size_type williamr@2: vertices_size_type; williamr@2: williamr@2: vertices_size_type n = num_vertices(g); williamr@2: williamr@2: typedef typename graph_traits::vertex_iterator williamr@2: vertex_iterator; williamr@2: williamr@2: vertices_size_type i = 0; williamr@2: for(std::pair v = vertices(g); williamr@2: v.first != v.second; ++v.first, ++i) { williamr@2: position[*v.first].x = radius * cos(i * 2 * pi / n); williamr@2: position[*v.first].y = radius * sin(i * 2 * pi / n); williamr@2: } williamr@2: } williamr@2: } // end namespace boost williamr@2: williamr@2: #endif // BOOST_GRAPH_CIRCLE_LAYOUT_HPP