示例#1
0
  public static BitSet toBitSet(IntBag bag, BitSet out) {
    int[] data = bag.getData();
    for (int i = 0, s = bag.size(); s > i; i++) {
      out.set(data[i]);
    }

    return out;
  }
  /**
   * Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) + abs(z-Z) <= dist. This
   * region forms an <a href="http://images.google.com/images?q=octahedron">octohedron</a> 2*dist+1
   * cells from point to opposite point inclusive, centered at (X,Y,Y). If dist==1 this is
   * equivalent to the six neighbors above, below, left, and right, front, and behind (X,Y,Z)), plus
   * (X,Y,Z) itself. Places each x, y, and z value of these locations in the provided IntBags xPos,
   * yPos, and zPos, clearing the bags first. Then places into the result IntBag the elements at
   * each of those <x,y,z> locations clearning it first. Returns the result IntBag (constructing one
   * if null had been passed in). null may be passed in for the various bags, though it is more
   * efficient to pass in a 'scratch bag' for each one.
   */
  public final void getNeighborsHamiltonianDistance(
      final int x,
      final int y,
      final int z,
      final int dist,
      final boolean toroidal,
      IntBag result,
      IntBag xPos,
      IntBag yPos,
      IntBag zPos) {
    if (xPos == null) xPos = new IntBag();
    if (yPos == null) yPos = new IntBag();
    if (zPos == null) zPos = new IntBag();

    getNeighborsHamiltonianDistance(x, y, z, dist, toroidal, xPos, yPos, zPos);

    if (result != null) {
      result.clear();
      result.resize(xPos.size());
    } else result = new IntBag(xPos.size());

    for (int i = 0; i < xPos.numObjs; i++)
      result.add(field[xPos.objs[i]][yPos.objs[i]][zPos.objs[i]]);
  }