getHeightAt method

double getHeightAt(
  1. double x,
  2. double y,
  3. bool edgeClamp
)

Get the height in the heightfield at a given position

Implementation

double getHeightAt(double x, double y, bool edgeClamp) {
  final data = this.data;
  final a = _getHeightAtA;
  final b = _getHeightAtB;
  final c = _getHeightAtC;
  final idx = getHeightAtIdx;

  getIndexOfPosition(x, y, idx, edgeClamp);
  int xi = idx[0];
  int yi = idx[1];
  if (edgeClamp) {
    xi = math.min(data.length - 2, math.max(0, xi));
    yi = math.min(data[0].length - 2, math.max(0, yi));
  }
  final upper = getTriangleAt(x, y, edgeClamp, a, b, c);
  barycentricWeights(x, y, a.x, a.y, b.x, b.y, c.x, c.y, _getHeightAtWeights);

  final w = _getHeightAtWeights;

  if (upper) {
    // Top triangle verts
    return data[xi + 1][yi + 1] * w.x + data[xi][yi + 1] * w.y + data[xi + 1][yi] * w.z;
  } else {
    // Top triangle verts
    return data[xi][yi] * w.x + data[xi + 1][yi] * w.y + data[xi][yi + 1] * w.z;
  }
}