apply method

  1. @override
void apply(
  1. Buffer source,
  2. Buffer target,
  3. double dt
)
override

Implementation

@override
void apply(Buffer source, Buffer target, double dt) {
  final width = source.width();
  final height = source.height();
  if (width <= 0 || height <= 0) return;

  final clampedStrength = strength.clamp(0.0, 1.0);
  if (clampedStrength <= 0) {
    _copyBuffer(source, target);
    return;
  }

  final centerX = (width - 1) / 2.0;
  final centerY = (height - 1) / 2.0;
  final scaleX = math.max(0.0001, centerX * roundness.clamp(0.1, 4.0));
  final scaleY = math.max(0.0001, centerY);

  for (var y = 0; y < height; y++) {
    for (var x = 0; x < width; x++) {
      final cell = source.cellAt(x, y);
      if (cell == null) continue;

      final dx = (x - centerX) / scaleX;
      final dy = (y - centerY) / scaleY;
      final distance = math.min(1.0, math.sqrt(dx * dx + dy * dy));
      final attenuation =
          1.0 -
          (clampedStrength *
              falloff(
                normalizedDistance: distance,
                x: x,
                y: y,
                width: width,
                height: height,
              ).clamp(0.0, 1.0));
      target.setCell(x, y, _scaleCell(cell, attenuation));
    }
  }
}