snap-points-2d
Advanced tools
@@ -0,0 +0,0 @@ var gaussRandom = require('gauss-random') |
@@ -0,0 +0,0 @@ var gaussRandom = require('gauss-random') |
+0
-0
@@ -0,0 +0,0 @@ var gaussRandom = require('gauss-random') |
+0
-0
@@ -0,0 +0,0 @@ 'use strict' |
+0
-0
@@ -0,0 +0,0 @@ |
+5
-4
| { | ||
| "name": "snap-points-2d", | ||
| "version": "3.1.0", | ||
| "version": "3.2.0", | ||
| "description": "snap round 2d points", | ||
@@ -28,10 +28,11 @@ "main": "snap.js", | ||
| "homepage": "https://github.com/mikolalysenko/snap-points-2d#readme", | ||
| "dependencies": { | ||
| "typedarray-pool": "^1.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "typedarray-pool": "^1.1.0", | ||
| "almost-equal": "^1.0.0", | ||
| "gauss-random": "^1.0.1", | ||
| "tape": "^4.2.0" | ||
| }, | ||
| "dependencies": { | ||
| "array-bounds": "^1.0.1" | ||
| } | ||
| } |
+6
-5
@@ -14,9 +14,10 @@ snap-points-2d | ||
| #### `var hlod = require('snap-points-2d')(points, ids, weights, [, bounds])` | ||
| Reorders the points hierarchically such that those which are drawn at the same pixel coordinate are grouped together. | ||
| * `points` is an array of 2*n values | ||
| * `ids` is an array which gets the reordered index of the points | ||
| * `weights` is an array of point weights, which can be used for transparent rendering | ||
| * `bounds` is an optional array of 4 values giving the bounding box of the points | ||
| Reorders the `points` hierarchically such that those which are drawn at the same pixel coordinate are grouped together. | ||
| * `points` is an input array of 2*n values, which gets reordered | ||
| * `ids` is an output array which gets the reordered index of the points | ||
| * `weights` is an output array of point weights (number of points at the same pixel), which can be used for transparent rendering | ||
| * `bounds` is an optional input array of 4 values giving the bounding box of the points | ||
| **Returns** An array of LOD scales. Each record is an object with the following properties: | ||
@@ -23,0 +24,0 @@ |
+27
-23
| 'use strict' | ||
| var pool = require('typedarray-pool') | ||
| var sortLevels = require('./lib/sort') | ||
| var getBounds = require('array-bounds') | ||
@@ -40,3 +39,3 @@ module.exports = snapPoints | ||
| function snapPoints(points, ids, weights, bounds) { | ||
| var n = points.length >>> 1 | ||
| var n = points.length >>> 1 | ||
| if(n < 1) { | ||
@@ -46,21 +45,32 @@ return [] | ||
| var lox = Infinity, loy = Infinity | ||
| var hix = -Infinity, hiy = -Infinity | ||
| if (!ids) ids = Array(n) | ||
| if (!weights) weights = Array(n) | ||
| if (!bounds) bounds = [] | ||
| for(var i=0; i<n; ++i) { | ||
| var x = points[2*i] | ||
| var y = points[2*i+1] | ||
| lox = Math.min(lox, x) | ||
| hix = Math.max(hix, x) | ||
| loy = Math.min(loy, y) | ||
| hiy = Math.max(hiy, y) | ||
| ids[i] = i | ||
| } | ||
| if(lox === hix) { | ||
| hix += 1 + Math.abs(hix) | ||
| // empty bounds or invalid bounds are considered as undefined and require recalc | ||
| if (!bounds.length || bounds.length < 4 || bounds[0] >= bounds[2] || bounds[1] >= bounds[3]) { | ||
| var b = getBounds(points, 2) | ||
| if(b[0] === b[2]) { | ||
| b[2] += 1 | ||
| } | ||
| if(b[1] === b[3]) { | ||
| b[3] += 1 | ||
| } | ||
| bounds[0] = b[0] | ||
| bounds[1] = b[1] | ||
| bounds[2] = b[2] | ||
| bounds[3] = b[3] | ||
| } | ||
| if(loy === hiy) { | ||
| hiy += 1 + Math.abs(hix) | ||
| } | ||
| var lox = bounds[0] | ||
| var loy = bounds[1] | ||
| var hix = bounds[2] | ||
| var hiy = bounds[3] | ||
| //Calculate diameter | ||
@@ -71,10 +81,5 @@ var scaleX = 1.0 / (hix - lox) | ||
| bounds = bounds || [0,0,0,0] | ||
| bounds[0] = lox | ||
| bounds[1] = loy | ||
| bounds[2] = hix | ||
| bounds[3] = hiy | ||
| var levels = pool.mallocInt32(n) | ||
| var levels = new Int32Array(n) | ||
| var ptr = 0 | ||
@@ -138,5 +143,4 @@ | ||
| lod.push(new SnapInterval(diam * Math.pow(0.5, level+1), 0, prevOffset)) | ||
| pool.free(levels) | ||
| return lod | ||
| } |
+31
-1
@@ -7,2 +7,3 @@ 'use strict' | ||
| tape('snap-points-2d', function(t) { | ||
@@ -15,3 +16,3 @@ | ||
| var weights = new Array(numPoints) | ||
| var bounds = [0,0,0,0] | ||
| var bounds = [] | ||
@@ -98,1 +99,30 @@ var scales = snap(npoints, ids, weights, bounds) | ||
| }) | ||
| tape('no arguments', function (t) { | ||
| var levels = snap([0,0, 1,1, 2,2]) | ||
| t.end() | ||
| }) | ||
| tape('larger bounds', function (t) { | ||
| var pos = [0,0, 1,1, 2,2, 3,3, 4,4] | ||
| var levels = snap(pos.slice(), [], [], [0,0,4,4]) | ||
| t.deepEqual(levels, [ | ||
| {pixelSize: 2, offset: 4, count: 1}, | ||
| {pixelSize: 1, offset: 2, count: 2}, | ||
| {pixelSize: 0.5, offset: 0, count: 2} | ||
| ]) | ||
| var levels2 = snap(pos.slice(), [], [], [0,0,40,40]) | ||
| t.deepEqual(levels2, [ | ||
| {pixelSize: 20, offset: 4, count: 1}, | ||
| {pixelSize: 10, offset: 3, count: 1}, | ||
| {pixelSize: 5, offset: 2, count: 1}, | ||
| {pixelSize: 2.5, offset: 1, count: 1}, | ||
| {pixelSize: 1.25, offset: 0, count: 1} | ||
| ]) | ||
| t.end() | ||
| }) |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
20389
8.49%526
4.57%32
3.23%4
33.33%1
Infinity%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed