hilbert2D static method

dynamic hilbert2D(
  1. dynamic center,
  2. dynamic size,
  3. dynamic iterations,
  4. dynamic v0,
  5. dynamic v1,
  6. dynamic v2,
  7. dynamic v3,
)

Generates 2D-Coordinates in a very fast way.

Based on work by: @link http://www.openprocessing.org/sketch/15493

@param center Center of Hilbert curve. @param size Total width of Hilbert curve. @param iterations Number of subdivisions. @param v0 Corner index -X, -Z. @param v1 Corner index -X, +Z. @param v2 Corner index +X, +Z. @param v3 Corner index +X, -Z.

Implementation

static hilbert2D(center, size, iterations, v0, v1, v2, v3) {
  // Default Vars
  center = center ?? Vector3(0, 0, 0);
  size = size ?? 10;

  var half = size / 2;
  iterations = iterations ?? 1;
  v0 = v0 ?? 0;
  v1 = v1 ?? 1;
  v2 = v2 ?? 2;
  v3 = v3 ?? 3;

  var vecS = [
    Vector3(center.x - half, center.y, center.z - half),
    Vector3(center.x - half, center.y, center.z + half),
    Vector3(center.x + half, center.y, center.z + half),
    Vector3(center.x + half, center.y, center.z - half)
  ];

  var vec = [vecS[v0], vecS[v1], vecS[v2], vecS[v3]];

  // Recurse iterations
  if (0 <= --iterations) {
    var tmp = [];

    tmp.addAll(GeometryUtils.hilbert2D(vec[0], half, iterations, v0, v3, v2, v1));

    tmp.addAll(GeometryUtils.hilbert2D(vec[1], half, iterations, v0, v1, v2, v3));
    tmp.addAll(GeometryUtils.hilbert2D(vec[2], half, iterations, v0, v1, v2, v3));
    tmp.addAll(GeometryUtils.hilbert2D(vec[3], half, iterations, v2, v1, v0, v3));

    // Return recursive call
    return tmp;
  }

  // Return complete Hilbert Curve.
  return vec;
}