sample static method

UBitMatrix sample(
  1. UBitMatrix image,
  2. int dimensionX,
  3. int dimensionY,
  4. UPerspectiveTransform transform,
)

Implementation

static UBitMatrix sample(UBitMatrix image, int dimensionX, int dimensionY, UPerspectiveTransform transform) {
  if (dimensionX <= 0 || dimensionY <= 0) throw const UCodeDecodeException("Bad sampling dimension");
  final UBitMatrix output = UBitMatrix(dimensionX, dimensionY);
  final Float64List points = Float64List(dimensionX * 2);
  for (int y = 0; y < dimensionY; y++) {
    final double sampleY = y + 0.5;
    for (int x = 0; x < dimensionX; x++) {
      points[x * 2] = x + 0.5;
      points[x * 2 + 1] = sampleY;
    }
    transform.transform(points);
    for (int x = 0; x < dimensionX; x++) {
      final int px = points[x * 2].toInt();
      final int py = points[x * 2 + 1].toInt();
      if (px < 0 || py < 0 || px >= image.width || py >= image.height) continue;
      if (image.get(px, py)) output.set(x, y);
    }
  }
  return output;
}