Simplifies a planar graph
Simplifies a planar graph by removing small or nearly flat corners.
var simplify = require"simplify-planar-graph"//Create a circlevar positions =var edges =forvar i=0; i<100; ++ivar theta = i / 100 * MathPI * 2.0positionspushMathcostheta Mathsinthetaedgespushi i+1%100//Simplify itconsole.logsimplifyedges positions 0.1
positions:0.9921147013144779 0.125333233564304260.8090169943749475 0.58778525229247310.48175367410171516 0.8763066800438637-0.30901699437494734 0.9510565162951536-0.7705132427757891 0.6374239897486899-0.9980267284282716 0.06279051952931358-0.9510565162951535 -0.30901699437494773-0.5877852522924732 -0.8090169943749473-0.18738131458572463 -0.98228725072868870.535826794978996 -0.84432792550201550.7705132427757894 -0.6374239897486896edges:0 11 22 33 44 510 05 66 77 88 99 10
npm install simplify-planar-graph
Simplies a planar graph to a given tolerance
edgesare the edges of the graph represented by pairs of vertex indices
positionsis a list of vertex coordinates encoded as an array of 2D arrays
tolerancecontrols the target aspect ratio of the corners of the mesh
Returns A new planar graph encoded as a JSON object with two properties:
edgesis an array of edges encoded as pairs of indices
positionsis 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.
(c) 2014 Mikola Lysenko. MIT License