trim method

KeyframeTrack trim(
  1. dynamic startTime,
  2. dynamic endTime
)

Removes keyframes before startTime and after endTime, without changing any values within the range `startTime`, `endTime`.

Implementation

/// any values within the range [`startTime`, `endTime`].
KeyframeTrack trim(startTime, endTime) {
  final times = this.times, nKeys = times.length;

  int from = 0, to = nKeys - 1;

  while (from != nKeys && times[from] < startTime) {
    ++from;
  }

  while (to != -1 && times[to] > endTime) {
    --to;
  }

  ++to; // inclusive -> exclusive bound

  if (from != 0 || to != nKeys) {
    // empty tracks are forbidden, so keep at least one keyframe
    if (from >= to) {
      to = math.max(to, 1).toInt();
      from = to - 1;
    }

    final stride = getValueSize();
    this.times = AnimationUtils.arraySlice(times, from, to);
    values = AnimationUtils.arraySlice(
        values, (from * stride).toInt(), (to * stride).toInt());
  }

  return this;
}