getTriangleAt method

bool getTriangleAt(
  1. double x,
  2. double y,
  3. bool edgeClamp,
  4. Vec3 a,
  5. Vec3 b,
  6. Vec3 c,
)

Implementation

bool getTriangleAt(double x, double y, bool edgeClamp,Vec3 a,Vec3 b, Vec3 c) {
  final idx = getHeightAtIdx;
  idx.clear();
  getIndexOfPosition(x, y, idx, edgeClamp);
  int xi = idx[0];
  int yi = idx[1];

  final data = this.data;
  if (edgeClamp) {
    xi = math.min(data.length - 2, math.max(0, xi));
    yi = math.min(data[0].length - 2, math.max(0, yi));
  }

  final elementSize = this.elementSize;
  final lowerDist2 = math.pow((x / elementSize - xi),2) + math.pow((y / elementSize - yi),2);
  final upperDist2 = math.pow((x / elementSize - (xi + 1)), 2) + math.pow((y / elementSize - (yi + 1)),2);
  final upper = lowerDist2 > upperDist2;
  getTriangle(xi, yi, upper, a, b, c);
  return upper;
}