Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

triangulate-polyline

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

triangulate-polyline - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

test/test.js

6

package.json
{
"name": "triangulate-polyline",
"version": "1.0.1",
"version": "1.0.2",
"description": "Triangulates a complex polygon",

@@ -13,3 +13,5 @@ "main": "tripolyline.js",

},
"devDependencies": {},
"devDependencies": {
"tape": "^3.0.1"
},
"scripts": {

@@ -16,0 +18,0 @@ "test": "echo \"Error: no test specified\" && exit 1"

"use strict"
module.exports = triangulatePolyline
module.exports = triangulateLoop

@@ -14,12 +14,3 @@ var poly2tri = require("poly2tri")

function tryTriangulation(ctx) {
try {
ctx.triangulate()
} catch(e) {
return false
}
return true
}
function triangulatePolyline(loops, positions) {
function triangulatePolyline(loops, positions, perturb) {
//Converts a loop into poly2tri format

@@ -29,3 +20,6 @@ function convertLoop(loop) {

var p = positions[v]
return new PointWrapper(p[0], p[1], v)
return new PointWrapper(
p[0] + (0.5-Math.random())*perturb*(1.0+Math.abs(p[0])),
p[1] + (0.5-Math.random())*perturb*(1.0+Math.abs(p[1])),
v)
})

@@ -64,5 +58,3 @@ }

//Triangulate
if(!tryTriangulation(ctx)) {
return []
}
ctx.triangulate()
var triangles = ctx.getTriangles()

@@ -78,2 +70,17 @@

})
}
//poly2tri is non robust, so we run it in a loop
//If it fails, then we perturb the vertices by increasing amounts
//until it works. (Stupid)
function triangulateLoop(loops, positions) {
var p = 0.0
for(var i=0; i<10; ++i) {
try {
return triangulatePolyline(loops, positions, p)
}catch(e) {
}
p = (p+1e-8)*2
}
return []
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc