[#sec:straight-line-drawing]
= Chrobak-Payne Straight Line Drawing

Creates a straight line drawing of a maximal planar graph on an integer grid.

*Complexity:* _O(n + m)_ +
*Defined in:* `<boost/graph/chrobak_payne_drawing.hpp>`

== Synopsis

[source,cpp]
----
template <typename Graph, typename PlanarEmbedding,
          typename ForwardIterator, typename PositionMap,
          typename VertexIndexMap>
void chrobak_payne_straight_line_drawing(
    const Graph& g,
    PlanarEmbedding perm,
    ForwardIterator ordering_begin,
    ForwardIterator ordering_end,
    PositionMap drawing,
    VertexIndexMap vm);
----

[cols="1,2,5"]
|===
| Direction | Parameter | Description

| IN
| `const Graph& g`
| An undirected graph. The type `Graph` must be a model of
  xref:concepts/VertexListGraph.adoc[VertexListGraph].

| IN
| `PlanarEmbedding perm`
| A Readable Property Map that models the
  xref:concepts/property_types/PlanarEmbedding.adoc[PlanarEmbedding] concept.

| IN
| `ForwardIterator ordering_begin, ordering_end`
| A ForwardIterator range with `value_type` equal to
  `graph_traits<Graph>::vertex_descriptor`, representing a canonical ordering
  of the vertices.

| OUT
| `PositionMap drawing`
| A Writable LValue Property Map that models the Position Map concept. The value mapped to
  must be an object with members `x` and `y`. For example, if `p` models PositionMap and
  `v` is a vertex, `p[v].x` and `p[v].y` are valid expressions. The type of `x` and `y`
  must be implicitly convertible to `std::size_t`.

| IN
| `VertexIndexMap vm`
| A Readable Property Map that maps vertices from `g` to distinct integers in the range
  `[0, num_vertices(g))`. +
  *Default*: `get(vertex_index, g)`
|===

== Description

A _straight line drawing_ of a xref:algorithms/planar/planar_graphs.adoc#planar[planar graph] is a xref:algorithms/planar/planar_graphs.adoc#plane_drawing[plane drawing] where each edge is drawn using a straight line segment.
Since all edges are line segments, the drawing is completely determined by the placement of vertices in the plane.
`chrobak_payne_straight_line_drawing` uses an algorithm of Chrobak and Payne [xref:about/bibliography.adoc#chrobakpayne95[65]] to form a straight line drawing of a planar graph by mapping all _n_ vertices in a planar graph to integer coordinates in a _(2n - 4) x (n - 2)_ grid.

image::figs/straight_line_drawing.png[Straight line drawing example]

The input graph passed to `chrobak_payne_straight_line_drawing` must be a xref:algorithms/planar/make_maximal_planar.adoc[maximal planar graph] with at least 3 vertices.
Self-loops and parallel edges are ignored by this function.
Note that the restriction that the graph be maximal planar does not mean that this function can only draw maximal planar graphs (the graph pictured above is not maximal planar, for example).
If you want to draw a graph _g_, you can create a copy _g'_ of _g_, store a mapping _m_ of vertices in _g'_ to vertices in _g_, xref:algorithms/planar/make_maximal_planar.adoc[triangulate] _g'_, and then send _g'_ in as the input to `chrobak_payne_straight_line_drawing`.
The drawing returned can then be applied to _g_ using _m_ to translate vertices from one graph to another, since _g_ contains a subset of the edges in _g'_.

== Example

See link:../example/straight_line_drawing.cpp[`example/straight_line_drawing.cpp`].

