simplify-planar-graph
Simplifies a planar graph by removing small or nearly flat corners.
Example
var simplify = //Create a circlevar positions = var edges = forvar i=0; i<100; ++i var theta = i / 100 * MathPI * 20 positions edges //Simplify itconsole
Output:
positions: 09921147013144779 012533323356430426 08090169943749475 05877852522924731 048175367410171516 08763066800438637 -030901699437494734 09510565162951536 -07705132427757891 06374239897486899 -09980267284282716 006279051952931358 -09510565162951535 -030901699437494773 -05877852522924732 -08090169943749473 -018738131458572463 -09822872507286887 0535826794978996 -08443279255020155 07705132427757894 -06374239897486896 edges: 0 1 1 2 2 3 3 4 4 5 10 0 5 6 6 7 7 8 8 9 9 10
Install
npm install simplify-planar-graph
API
require("simplify-planar-graph")(edges, positions, tolerance)
Simplies a planar graph to a given tolerance
edges
are the edges of the graph represented by pairs of vertex indicespositions
is a list of vertex coordinates encoded as an array of 2D arraystolerance
controls the target aspect ratio of the corners of the mesh
Returns A new planar graph encoded as a JSON object with two properties:
edges
is an array of edges encoded as pairs of indicespositions
is an array of positions for the simplicial complex
Note The current implementation does not detect the removal of features which cross existing line segments. Picking a high tolerance value may result in destroying the planarity of the resulting graph. Eventually if it becomes a priority I may go back and implement code to detect and handle these cases.
Credits
(c) 2014 Mikola Lysenko. MIT License