Simplifies a planar graph by removing small or nearly flat corners.
var simplify =//Create a circlevar positions =var edges =forvar i=0; i<100; ++ivar theta = i / 100 * MathPI * 20positionsedges//Simplify itconsole
positions:09921147013144779 01253332335643042608090169943749475 05877852522924731048175367410171516 08763066800438637-030901699437494734 09510565162951536-07705132427757891 06374239897486899-09980267284282716 006279051952931358-09510565162951535 -030901699437494773-05877852522924732 -08090169943749473-018738131458572463 -098228725072868870535826794978996 -0844327925502015507705132427757894 -06374239897486896edges: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