npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clean-pslg-3d

v0.1.2

Published

Remove self intersections, t-junctions and duplicate edges/vertices from a planar straight line graph

Downloads

6

Readme

This is a fork of https://github.com/mikolalysenko/clean-pslg. Just forked it because I needed support for 3d points.

clean-pslg

Resolves all self intersections, t-junctions, and removes duplicate vertices/edges from a planar straight line graph using iterated snap rounding.

Demo

Click on the following link to try out clean-pslg in your browser:

Example

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 = require("clean-pslg");

//Create a planar straight line graph with many degenerate crossings
var points = [
  [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],
];

//These are the edges of the graph
//They are defined by pairs of indices of vertices
var edges = [
  [0, 1],
  [2, 3],
  [4, 5],
  [6, 7],
];

//Run clean up on the graph
if (cleanPSLG(points, edges)) {
  console.log("removed degeneracies from graph");
}

//clean-pslg operates on the graph in place, so after running it the points/edges will be modified
console.log("points = \n", points);
console.log("edges = \n", edges);

Output

The program will output the following text:

removed degeneracies from graph
points =
 [ [ 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:

Install

npm i clean-pslg

API

require('clean-pslg')(points, edges[, colors])

Processes an unoriented planar straight line graph defined by points and edges in place.

  • points is an array encoding the vertices of the planar straight line graph as pairs of numbers
  • edges is an array encoding the edges of the planar straight line graph as pairs of indices
  • colors is 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:

  • Duplicate points are merged
  • Duplicate edges are merged
  • T-junctions are split
  • Edge crossings are split

The resulting graph meets all invariants required by cdt2d, so it may be triangulated. Note that this procedure does not preserve orientation.

Returns true if repairs were necessary, otherwise false

Note This is a destructive procedure, which means that the contents of points and edges may change. If you don't want this to happen, you should make a deep copy of points and edges before calling clean-pslg

License

(c) 2015 Mikola Lysenko. MIT License