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