Click on the following link to try out
clean-pslg in your browser:
This module really only does one thing, which is clean up planar straight line graphs. You invoke it by passing it an array of points and an array of edges like so:
var cleanPSLG =//Create a planar straight line graph with many degenerate crossingsvar points =025 05075 0505 02505 075025 025075 075025 075075 025//These are the edges of the graph//They are defined by pairs of indices of verticesvar edges =0 12 34 56 7//Run clean up on the graphifconsole//clean-pslg operates on the graph in place, so after running it the points/edges will be modifiedconsoleconsole
The program will output the following text:
removed degeneracies from graphpoints =[ [ 0.25, 0.5 ],[ 0.75, 0.5 ],[ 0.5, 0.25 ],[ 0.5, 0.75 ],[ 0.25, 0.25 ],[ 0.75, 0.75 ],[ 0.25, 0.75 ],[ 0.75, 0.25 ],[ 0.5, 0.5 ] ]edges =[ [ 8, 0 ],[ 1, 8 ],[ 8, 2 ],[ 3, 8 ],[ 8, 4 ],[ 5, 8 ],[ 8, 6 ],[ 7, 8 ],[ 8, 8 ] ]
Visually, this corresponds to the following refinement of a planar graph:
npm i clean-pslg
Processes an unoriented planar straight line graph defined by
edges in place.
pointsis an array encoding the vertices of the planar straight line graph as pairs of numbers
edgesis an array encoding the edges of the planar straight line graph as pairs of indices
colorsis an optional array of edge colors. If specified, only merge edges if they have the same color. This can be used to implement orientation preservation or handle solid geometry.
The following degeneracies are handled:
The resulting graph meets all invariants required by
cdt2d, so it may be triangulated. Note that this procedure does not preserve orientation.
true if repairs were necessary, otherwise
Note This is a destructive procedure, which means that the contents of
edges may change. If you don't want this to happen, you should make a deep copy of
edges before calling
(c) 2015 Mikola Lysenko. MIT License