Skip to content

Commit

Permalink
Speed improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Feb 3, 2020
1 parent f5bdbaf commit c772c56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions build/mathcell.js
Original file line number Diff line number Diff line change
Expand Up @@ -2601,8 +2601,8 @@ function isosurface( f, xRange, yRange, zRange, options={} ) {
// Szudzik pairing ignoring ordering
var n = u1[4] < u2[4] ? u1[4] + u2[4]*u2[4] : u1[4]*u1[4] + u2[4];

var p = inVertices.indexOf( n );
if ( p >= 0 ) return p;
var p = inVertices[n];
if ( p ) return p;

var m = ( level - u1[3] ) / ( u2[3] - u1[3] );

Expand All @@ -2617,7 +2617,7 @@ function isosurface( f, xRange, yRange, zRange, options={} ) {
var vertices = [], faces = [];

// for filtering vertices
var inVertices = [], a, b, c;
var inVertices = {}, n, a, b, c;

// adapted from paulbourke.net/geometry/polygonise/

Expand Down Expand Up @@ -2665,20 +2665,23 @@ function isosurface( f, xRange, yRange, zRange, options={} ) {

a = v[ triangleTable[index][l] ];
if ( !Number.isInteger(a) ) {
inVertices.push( a[3] );
n = a[3];
a = vertices.push( a.slice(0,3) ) - 1;
inVertices[n] = a;
}

b = v[ triangleTable[index][l+1] ];
if ( !Number.isInteger(b) ) {
inVertices.push( b[3] );
n = b[3];
b = vertices.push( b.slice(0,3) ) - 1;
inVertices[n] = b;
}

c = v[ triangleTable[index][l+2] ];
if ( !Number.isInteger(c) ) {
inVertices.push( c[3] );
n = c[3];
c = vertices.push( c.slice(0,3) ) - 1;
inVertices[n] = c;
}

faces.push( [ a, b, c ] );
Expand Down
15 changes: 9 additions & 6 deletions src/march/marching-cubes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function isosurface( f, xRange, yRange, zRange, options={} ) {
// Szudzik pairing ignoring ordering
var n = u1[4] < u2[4] ? u1[4] + u2[4]*u2[4] : u1[4]*u1[4] + u2[4];

var p = inVertices.indexOf( n );
if ( p >= 0 ) return p;
var p = inVertices[n];
if ( p ) return p;

var m = ( level - u1[3] ) / ( u2[3] - u1[3] );

Expand All @@ -53,7 +53,7 @@ function isosurface( f, xRange, yRange, zRange, options={} ) {
var vertices = [], faces = [];

// for filtering vertices
var inVertices = [], a, b, c;
var inVertices = {}, n, a, b, c;

// adapted from paulbourke.net/geometry/polygonise/

Expand Down Expand Up @@ -101,20 +101,23 @@ function isosurface( f, xRange, yRange, zRange, options={} ) {

a = v[ triangleTable[index][l] ];
if ( !Number.isInteger(a) ) {
inVertices.push( a[3] );
n = a[3];
a = vertices.push( a.slice(0,3) ) - 1;
inVertices[n] = a;
}

b = v[ triangleTable[index][l+1] ];
if ( !Number.isInteger(b) ) {
inVertices.push( b[3] );
n = b[3];
b = vertices.push( b.slice(0,3) ) - 1;
inVertices[n] = b;
}

c = v[ triangleTable[index][l+2] ];
if ( !Number.isInteger(c) ) {
inVertices.push( c[3] );
n = c[3];
c = vertices.push( c.slice(0,3) ) - 1;
inVertices[n] = c;
}

faces.push( [ a, b, c ] );
Expand Down

0 comments on commit c772c56

Please sign in to comment.