author | William Roberts <williamr@symbian.org> |
Tue, 16 Mar 2010 16:12:26 +0000 | |
branch | Symbian2 |
changeset 2 | 2fe1408b6811 |
permissions | -rw-r--r-- |
williamr@2 | 1 |
// Copyright 2004 The Trustees of Indiana University. |
williamr@2 | 2 |
|
williamr@2 | 3 |
// Distributed under the Boost Software License, Version 1.0. |
williamr@2 | 4 |
// (See accompanying file LICENSE_1_0.txt or copy at |
williamr@2 | 5 |
// http://www.boost.org/LICENSE_1_0.txt) |
williamr@2 | 6 |
|
williamr@2 | 7 |
// Authors: Douglas Gregor |
williamr@2 | 8 |
// Andrew Lumsdaine |
williamr@2 | 9 |
#ifndef BOOST_GRAPH_CIRCLE_LAYOUT_HPP |
williamr@2 | 10 |
#define BOOST_GRAPH_CIRCLE_LAYOUT_HPP |
williamr@2 | 11 |
#include <cmath> |
williamr@2 | 12 |
#include <utility> |
williamr@2 | 13 |
#include <boost/graph/graph_traits.hpp> |
williamr@2 | 14 |
|
williamr@2 | 15 |
namespace boost { |
williamr@2 | 16 |
/** |
williamr@2 | 17 |
* \brief Layout the graph with the vertices at the points of a regular |
williamr@2 | 18 |
* n-polygon. |
williamr@2 | 19 |
* |
williamr@2 | 20 |
* The distance from the center of the polygon to each point is |
williamr@2 | 21 |
* determined by the @p radius parameter. The @p position parameter |
williamr@2 | 22 |
* must be an Lvalue Property Map whose value type is a class type |
williamr@2 | 23 |
* containing @c x and @c y members that will be set to the @c x and |
williamr@2 | 24 |
* @c y coordinates. |
williamr@2 | 25 |
*/ |
williamr@2 | 26 |
template<typename VertexListGraph, typename PositionMap, typename Radius> |
williamr@2 | 27 |
void |
williamr@2 | 28 |
circle_graph_layout(const VertexListGraph& g, PositionMap position, |
williamr@2 | 29 |
Radius radius) |
williamr@2 | 30 |
{ |
williamr@2 | 31 |
const double pi = 3.14159; |
williamr@2 | 32 |
|
williamr@2 | 33 |
#ifndef BOOST_NO_STDC_NAMESPACE |
williamr@2 | 34 |
using std::sin; |
williamr@2 | 35 |
using std::cos; |
williamr@2 | 36 |
#endif // BOOST_NO_STDC_NAMESPACE |
williamr@2 | 37 |
|
williamr@2 | 38 |
typedef typename graph_traits<VertexListGraph>::vertices_size_type |
williamr@2 | 39 |
vertices_size_type; |
williamr@2 | 40 |
|
williamr@2 | 41 |
vertices_size_type n = num_vertices(g); |
williamr@2 | 42 |
|
williamr@2 | 43 |
typedef typename graph_traits<VertexListGraph>::vertex_iterator |
williamr@2 | 44 |
vertex_iterator; |
williamr@2 | 45 |
|
williamr@2 | 46 |
vertices_size_type i = 0; |
williamr@2 | 47 |
for(std::pair<vertex_iterator, vertex_iterator> v = vertices(g); |
williamr@2 | 48 |
v.first != v.second; ++v.first, ++i) { |
williamr@2 | 49 |
position[*v.first].x = radius * cos(i * 2 * pi / n); |
williamr@2 | 50 |
position[*v.first].y = radius * sin(i * 2 * pi / n); |
williamr@2 | 51 |
} |
williamr@2 | 52 |
} |
williamr@2 | 53 |
} // end namespace boost |
williamr@2 | 54 |
|
williamr@2 | 55 |
#endif // BOOST_GRAPH_CIRCLE_LAYOUT_HPP |