apply method

  1. @override
List<DataPoint> apply(
  1. List<DataPoint> input,
  2. DataPointPipelineContext context
)
override

Implementation

@override
List<DataPoint> apply(
    List<DataPoint> input,
    DataPointPipelineContext context,
    ) {

  if (input.isEmpty) return input;

  var working = List<DataPoint>.from(input);

  while (true) {

    final normalized = _normalizeOnce(working, context);

    if (threshold == null) {
      return normalized;
    }

    // find smallest absolute normalized dy below threshold
    double minValue = double.infinity;

    for (final p in normalized) {
      final v = p.dy.abs();
      if (v < threshold! && v < minValue) {
        minValue = v;
      }
    }

    // nothing to remove → done
    if (minValue == double.infinity) {
      return normalized;
    }

    // remove the corresponding original datapoint
    final indexToRemove = normalized.indexWhere(
          (p) => p.dy.abs() == minValue,
    );

    if (indexToRemove == -1) {
      return normalized;
    }

    working.removeAt(indexToRemove);

    if (working.isEmpty) {
      return const [];
    }
  }
}