sampleField function

double sampleField(
  1. NoiseField f,
  2. double u,
  3. double v
)

Implementation

double sampleField(NoiseField f, double u, double v) {
  final x = u.floor();
  final y = v.floor();
  final fx = u - x;
  final fy = v - y;
  final m = f.w - 1;
  final n = f.h - 1;
  final d = f.d;
  final x0 = x & m;
  final x1 = (x + 1) & m;
  final y0 = (y & n) * f.w;
  final y1 = ((y + 1) & n) * f.w;
  final a = d[y0 + x0];
  final b = d[y0 + x1];
  final c = d[y1 + x0];
  final e = d[y1 + x1];
  return a + (b - a) * fx + (c - a + (a - b - c + e) * fx) * fy;
}