Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

snap-points-2d

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snap-points-2d - npm Package Compare versions

Comparing version
3.0.0
to
3.1.0
+95
test/test.js
'use strict'
var tape = require('tape')
var snap = require('../snap')
var approxEqual = require('almost-equal')
tape('snap-points-2d', function(t) {
function verifySnap(points) {
var numPoints = points.length>>>1
var npoints = points.slice()
var ids = new Array(numPoints)
var weights = new Array(numPoints)
var bounds = [0,0,0,0]
var scales = snap(npoints, ids, weights, bounds)
var sx = bounds[0]
var sy = bounds[1]
var sw = bounds[2] - bounds[0]
var sh = bounds[3] - bounds[1]
for(var i=0; i<numPoints; ++i) {
var id = ids[i]
t.ok(approxEqual(sx + sw*npoints[2*i], points[2*id], approxEqual.FLT_EPSILON),
'id perm ok: ' + id + ' ' + points[2*id] + ' = ' + (sx + sw*npoints[2*i]))
t.ok(approxEqual(sy + sh*npoints[2*i+1], points[2*id+1], approxEqual.FLT_EPSILON), 'id perm ok: ' + id + ' ' + points[2*id+1] + ' = ' + (sy + sh*npoints[2*i+1]))
}
t.equals(scales[scales.length-1].offset, 0, 'last item')
t.equals(scales[0].offset+scales[0].count, numPoints, 'first item')
for(var i=0; i<scales.length; ++i) {
var s = scales[i]
var r = s.pixelSize
var offs = s.offset
var count = s.count
console.log('level=', i, r, offs, count)
if(i > 0) {
t.equals(offs+count, scales[i-1].offset, 'offset for ' + i)
t.ok(r < scales[i-1].pixelSize, 'test scales ok')
}
k_loop:
for(var k=offs-1; k>=0; --k) {
var ax = npoints[2*k]
var ay = npoints[2*k+1]
var mind = Infinity
for(var j=offs; j<offs+count; ++j) {
var x = npoints[2*j]
var y = npoints[2*j+1]
mind = Math.min(mind, Math.max(Math.abs(ax-x), Math.abs(ay-y)))
}
t.ok(mind <= 2.0 * r, k + ':' + ax + ',' + ay + ' is not covered - closest pt = ' + mind)
}
}
}
t.same(snap([], [], []), [])
verifySnap([
1, 1,
2, 2,
3, 3,
4, 4,
5, 5])
verifySnap([
0,0,
0,0,
0,0,
0,0])
verifySnap([
1, 2,
2, 5,
3, 6,
4, -1
])
var pts = new Array(100)
for(var i=0; i<100; ++i) {
pts[i] = Math.random()
}
verifySnap(pts)
t.end()
})
+4
-2
{
"name": "snap-points-2d",
"version": "3.0.0",
"version": "3.1.0",
"description": "snap round 2d points",

@@ -32,4 +32,6 @@ "main": "snap.js",

"devDependencies": {
"gauss-random": "^1.0.1"
"almost-equal": "^1.0.0",
"gauss-random": "^1.0.1",
"tape": "^4.2.0"
}
}
+22
-10

@@ -57,2 +57,9 @@ 'use strict'

if(lox === hix) {
hix += 1 + Math.abs(hix)
}
if(loy === hiy) {
hiy += 1 + Math.abs(hix)
}
//Calculate diameter

@@ -83,3 +90,9 @@ var scaleX = 1.0 / (hix - lox)

var ny = y+j*diam_2
var nextOffset = partition(points, ids, offset, end, nx, ny, nx+diam_2, ny+diam_2)
var nextOffset = partition(
points
, ids
, offset
, end
, nx, ny
, nx+diam_2, ny+diam_2)
if(nextOffset === offset) {

@@ -101,5 +114,5 @@ continue

var lod = []
var lastLevel = 0
var prevOffset = n-1
var lod = []
var lastLevel = 0
var prevOffset = n
for(var ptr=n-1; ptr>=0; --ptr) {

@@ -116,12 +129,11 @@ points[2*ptr] = (points[2*ptr] - lox) * scaleX

diam * Math.pow(0.5, level),
ptr + 1,
prevOffset - ptr
ptr+1,
prevOffset - (ptr+1)
))
prevOffset = ptr
prevOffset = ptr+1
lastLevel = level
}
if(prevOffset) {
lod.push(new SnapInterval(diam * Math.pow(0.5, level+1), 0, prevOffset))
}
lod.push(new SnapInterval(diam * Math.pow(0.5, level+1), 0, prevOffset))
pool.free(levels)

@@ -128,0 +140,0 @@