You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

rle-core

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

rle-core - npm Package Compare versions

Comparing version
0.0.4
to
0.0.5
+2
-1
index.js

@@ -5,6 +5,7 @@ "use strict"; "use restrict";

var misc = require("./lib/misc.js");
exports.compareCoord = misc.compareCoord;
exports.saturateAbs = misc.saturateAbs;
exports.EPSILON = misc.EPSILON;
exports.POSITIVE_INFINITY = misc.POSITIVE_INFINITY;
exports.NEGATIVE_INFINITY = misc.NEGATIVE_INFINITY;
exports.compareCoord = misc.compareCoord;

@@ -11,0 +12,0 @@ //Basic data types

"use strict"; "use restrict";
//Compares coordinates colexicographically
var compareCoord = new Function("ra", "rb", [
exports.compareCoord = new Function("ra", "rb", [
"for(var i=2;i>=0;--i) {",

@@ -12,5 +12,16 @@ "var d=ra[i]-rb[i];",

exports.compareCoord = compareCoord;
//Clamps |x| to [0,1]
exports.saturateAbs = new Function("x", [
"if(x >= 0.0) {",
"if(x <= 1.0) {",
"return x;",
"}",
"} else if(x >= -1.0) {",
"return -x;",
"}",
"return 1.0;"
].join("\n"));
exports.EPSILON = 1e-6;
exports.POSITIVE_INFINITY = (1<<30);
exports.NEGATIVE_INFINITY = -(1<<30);

@@ -17,3 +17,3 @@ "use strict"; "use restrict";

//Multivolume iterator
function MultiIterator(volumes, stencil, ptrs, coord, stencil_len) {
function MultiIterator(volumes, stencil, ptrs, coord, stencil_len, frontier) {
this.volumes = volumes;

@@ -24,2 +24,3 @@ this.stencil = stencil;

this.stencil_len = stencil_len;
this.frontier = frontier;
}

@@ -38,3 +39,4 @@

new Int32Array([NEGATIVE_INFINITY,NEGATIVE_INFINITY,NEGATIVE_INFINITY]),
stencil_len
stencil_len,
new Uint8Array(volumes.length * stencil_len)
);

@@ -54,13 +56,2 @@ }

//Extract an individual component of this iterator
MultiIterator.prototype.subiterator = function(i) {
var stencil_len = this.stencil_len;
return new StencilIterator(
this.volumes[i],
this.stencil,
new Int32Array(this.ptrs.subarray(3*stencil_len*i, 3*stencil_len*(i+1))),
new Int32Array(this.coord)
);
}
//Checks if iterator has another value

@@ -78,2 +69,3 @@ MultiIterator.prototype.hasNext = function() {

, stencil_len = this.stencil_len
, frontier = this.frontier
, n = 0

@@ -112,5 +104,11 @@ , idx = 0;

}
//Clear out frontier
for(var i=0; i<frontier.length; ++i) {
frontier[i] = 0;
}
//Advance pointers
for(var i=0; i<n; ++i) {
++ptrs[POINTER_LIST[i]];
var idx = POINTER_LIST[i];
++ptrs[idx];
frontier[idx] = 1;
}

@@ -124,2 +122,3 @@ }

, stencil = this.stencil
, frontier = this
, tcoord = new Int32Array(3)

@@ -132,2 +131,3 @@ , idx = 0;

var volume = volumes[k]
, vcoords = volume.coords
, nruns = volume.length();

@@ -138,3 +138,7 @@ for(var i=0,s=0; i<stencil_len; ++i, s+=3) {

}
ptrs[idx++] = volume.bisect(tcoord, 0, nruns-1) ;
ptrs[idx] = volume.bisect(tcoord, 0, nruns-1);
frontier[idx] = (vcoords[0][ptrs[idx]] === tcoord[0] &&
vcoords[1][ptrs[idx]] === tcoord[1] &&
vcoords[2][ptrs[idx]] === tcoord[2]);
++idx;
}

@@ -144,3 +148,32 @@ }

//Reads the values of all the pointers in the stencil
MultiIterator.prototype.getValues = function(phases, distances) {
var ptrs = this.ptrs
, frontier = this.frontier
, idx = 0;
for(var i=0; i<this.volumes.length; ++i) {
var volume = this.volumes[i]
, vphases = volume.phases
, vdistances = volume.distances;
for(var j=0; j<this.stencil_len; ++j) {
var p = ptrs[idx];
phases[idx] = vphases[p];
distances[idx] = frontier[idx] ? vdistances[p] : 1.0;
++idx;
}
}
}
//Extract an individual component of this iterator
MultiIterator.prototype.subiterator = function(i) {
var stencil_len = this.stencil_len;
return new StencilIterator(
this.volumes[i],
this.stencil,
new Int32Array(this.ptrs.subarray(3*stencil_len*i, 3*stencil_len*(i+1))),
new Int32Array(this.coord)
);
}
exports.MultiIterator = MultiIterator;
exports.beginMulti = beginMulti;
"use strict"; "use restrict";
var misc = require("./misc.js");
var saturateAbs = misc.saturateAbs;
var NEGATIVE_INFINITY = misc.NEGATIVE_INFINITY;
var DynamicVolume = require("./volume.js").DynamicVolume;
var NEGATIVE_INFINITY = require("./misc.js").NEGATIVE_INFINITY;
var DEFAULT_DIST_FUNC = new Function("x", "return 1.0;");

@@ -32,3 +35,3 @@

if(phase !== phase_func(y)) {
builder.push(x[0], x[1], x[2], Math.abs(dist_func(x)), phase);
builder.push(x[0], x[1], x[2],saturateAbs(dist_func(x)), phase);
break outer_loop;

@@ -35,0 +38,0 @@ }

@@ -16,3 +16,3 @@ "use strict"; "use restrict";

//Walk a stencil over a volume
function StencilIterator(volume, stencil, ptrs, coord) {
function StencilIterator(volume, stencil, ptrs, coord, frontier) {
this.volume = volume;

@@ -22,2 +22,3 @@ this.stencil = stencil;

this.coord = coord;
this.frontier = frontier;

@@ -37,2 +38,3 @@ //Resize internal buffer

, new Int32Array(this.coord)
, new Uint8Array(this.frontier)
);

@@ -48,8 +50,9 @@ }

StencilIterator.prototype.next = function() {
var coords = this.volume.coords
, nruns = this.volume.length()
, stencil = this.stencil
, ptrs = this.ptrs
, coord = this.coord
, n = 0;
var coords = this.volume.coords
, nruns = this.volume.length()
, frontier = this.frontier
, stencil = this.stencil
, ptrs = this.ptrs
, coord = this.coord
, n = 0;
//Push coordinate to infinity

@@ -83,5 +86,11 @@ for(var i=0; i<3; ++i) {

}
//Clear frontier
for(var i=0; i<ptrs.length; ++i) {
frontier[i] = 0;
}
//Advance pointers
for(var i=0; i<n; ++i) {
++ptrs[POINTER_LIST[i]];
var idx = POINTER_LIST[i]
++ptrs[idx];
frontier[idx] = 1;
}

@@ -92,7 +101,9 @@ }

StencilIterator.prototype.seek = function(coord) {
var volume = this.volume
, nruns = volume.length()
, ptrs = this.ptrs
, stencil = this.stencil
, tcoord = new Int32Array(3);
var volume = this.volume
, vcoords = volume.coords
, nruns = volume.length()
, ptrs = this.ptrs
, stencil = this.stencil
, frontier = this.frontier
, tcoord = new Int32Array(3);
for(var i=0; i<3; ++i) {

@@ -105,6 +116,21 @@ this.coord[i] = coord[i];

}
ptrs[i] = volume.bisect(tcoord, 0, nruns-1) ;
ptrs[i] = volume.bisect(tcoord, 0, nruns-1);
frontier[i] = (vcoords[0][ptrs[i]] === tcoord[0] &&
vcoords[1][ptrs[i]] === tcoord[1] &&
vcoords[2][ptrs[i]] === tcoord[2]);
}
}
//Reads the values of all the pointers in the stencil
StencilIterator.prototype.getValues = function(phases, distances) {
var ptrs = this.ptrs
, frontier = this.frontier
, vphases = this.volume.phases
, vdistances = this.volume.distances;
for(var i=0; i<ptrs.length; ++i) {
var p = ptrs[i];
phases[i] = vphases[p];
distances[i] = frontier[i] ? vdistances[p] : 1.0;
}
}

@@ -120,3 +146,4 @@ //Creates a stencil iterator

ptrs,
coord
coord,
new Uint8Array(ptrs.length)
);

@@ -123,0 +150,0 @@ }

{
"name": "rle-core",
"version": "0.0.4",
"version": "0.0.5",
"description": "Core tools for working with narrow band level sets in JavaScript",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -120,2 +120,5 @@ `rle-core`

### `iter.getValues(phases, distances)`
Retrieves the phases/distance-to-phase-boundary for each point in the iterator.
### `iter.subiterator(n)` (MultiIterator only)

@@ -132,4 +135,12 @@ Returns the stencil iterator associated to volume `n` at the location of the current multiiterator.

And two helper methods:
### `compareCoord(a, b)`
Compares two coordinates lexicographically
### `saturateAbs(x)`
Returns |x| clamped to [0,1]
Acknowledgements
================
(c) 2012-2013 Mikola Lysenko (mikolalysenko@gmail.com). BSD License.