示例#1
0
BoundaryPoint.prototype.closestCells = function(grid, x) {
  var nbhd = this.cells;
  var d = Number.POSITIVE_INFINITY;
  var r_cells = [];
  var r_points = [];
  var point_result = new Array(x.length);
  for(var i=0; i<nbhd.length; ++i) {
    var c = nbhd[i];
    var t = closestPoint(grid.cells[c], grid.positions, x, point_result);
    if(Math.abs(t - d) < EPSILON) {
      r_cells.push(c);
      r_points.push(point_result.slice(0));
    } else if(t < d) {
      d = t;
      r_cells.length = 1;
      r_cells[0] = c;
      r_points.length = 1;
      r_points[0] = point_result.slice(0);
    }
  }
  return {
    points: r_points,
    cells: r_cells,
    distance: d
  };
}
示例#2
0
function fill3(grid, lo, hi, c) {
  var scoord = [0,0,0];
  var tol = 3.0 * grid.tolerance * grid.tolerance;
  for(var i=lo[2]; i<=hi[2]; ++i) {
    var x = expand3(i)<<2;
    scoord[2] = grid.tolerance * i;
    for(var j=lo[1]; j<=hi[1]; ++j) {
      var y = x + (expand3(j) << 1);
      scoord[1] = grid.tolerance * j;
      for(var k=lo[0]; k<=hi[0]; ++k) {
        scoord[0] = grid.tolerance * k;
        var cdist = closestPoint(grid.cells[c], grid.positions, scoord);
        if( isNaN(cdist) || cdist >= tol) {
            continue;
        }
        var z = y + expand3(k);
        var g = grid.grid[z];
        if(g) {
          g.cells.push(c);
        } else {
          grid.grid[z] = new BoundaryPoint([k,j,i], [c]);;
        }
      }
    }
  }
}
示例#3
0
BoundaryPoint.prototype.neighborhood = function(grid, x, radius) {
  var nbhd = this.cells;
  var r = [];
  var r2 = radius*radius;
  for(var i=0; i<nbhd.length; ++i) {
    var c = nbhd[i];
    if(closestPoint(grid.cells[c], grid.positions, x) <= r2) {
      r.push(c);
    }
  }
  return r;
}
示例#4
0
function fill_rec(grid, lo, hi, c, n, coord) {
  if(n < 0) {
    var scoord = numeric.mul(grid.tolerance, coord);
    var cdist = closestPoint(grid.cells[c], grid.positions, scoord);
    if(isNaN(cdist) || cdist >= (lo.length * grid.tolerance *grid.tolerance) ) {
        return;
    }
    var k = index(coord);
    var bnd = grid.grid[k];
    if(bnd) {
      bnd.cells.push(c);
    } else {
      grid.grid[k] = new BoundaryPoint(coord.slice(0), [c])
    }
  } else {
    for(coord[n]=lo[n]; coord[n]<=hi[n]; ++coord[n]) {
      fill_rec(grid, lo, hi, c, n-1, coord);
    }
  }
}
示例#5
0
function fill2(grid, lo, hi, c) {
  var scoord = [0,0];
  var tol = 2 * grid.tolerance * grid.tolerance;
  for(var i=lo[1]; i<=hi[1]; ++i) {
    var x = expand2(i)<<1;
    scoord[1] = i * grid.tolerance;
    for(var j=lo[0]; j<=hi[0]; ++j) {
      scoord[0] = y * grid.tolerance;
      var cdist = closestPoint(grid.cells[c], grid.positions, scoord);
      if(isNaN(cdist) || cdist >= tol) {
          continue;
      }
      var y = x + expand2(j);
      var g = grid.grid[y];
      if(g) {
        g.cells.push(c);
      } else {
        grid.grid[y] = new BoundaryPoint([j,i], [c]);
      }
    }
  }
}