is_straight_line_drawing

is_straight_line_drawing#

graph_tool.structure.is_straight_line_drawing(g, pos)[git][source]#

Check whether a drawing of a graph with straight edges on an integer grid has no edge crossings.

Parameters:
gGraph

Graph to be used. Edge directions are ignored.

posVertexPropertyMap

Vector-valued vertex positions, which must have integer values.

Returns:
planarbool

True if no two edges, drawn as straight segments, cross or overlap, other than at common endpoints.

See also

is_planar

Planarity test

graph_tool.draw.planar_layout

Straight-line planar drawing

Notes

Two edges cross if they intersect at a point other than a common endpoint, or if one passes through an endpoint of the other, as decided exactly with integer orientation predicates. After sorting the edges by their leftmost coordinate, only the pairs whose horizontal and vertical ranges overlap are tested, which takes time \(O(E\log E)\) plus the number of such pairs, \(O(E^2)\) in the worst case. It verifies the output of planar_layout(), whose coordinates are integers.

Examples

>>> g = gt.lattice([4, 4])
>>> pos = g.new_vp("vector<double>",
...                vals=[(i % 4, i // 4) for i in range(16)])
>>> print(gt.is_straight_line_drawing(g, pos))
True
>>> pos[0] = (3, 3)
>>> print(gt.is_straight_line_drawing(g, pos))
False