coverEnvelope function

Rect? coverEnvelope(
  1. Rect previous,
  2. Rect current
)

Cover that is certainly painted while a page moves from previous to current: the intersection of both and of the extrapolated next position. Mirrors motionEnvelope: whichever of the frames native ends up capturing, nothing outside the returned rect is assumed to be hidden.

Implementation

Rect? coverEnvelope(Rect previous, Rect current) {
  const double lookAhead = 1.5;
  final Rect predicted = Rect.fromLTRB(
    current.left + (current.left - previous.left) * lookAhead,
    current.top + (current.top - previous.top) * lookAhead,
    current.right + (current.right - previous.right) * lookAhead,
    current.bottom + (current.bottom - previous.bottom) * lookAhead,
  );
  final Rect cover = previous.intersect(current).intersect(predicted);
  return cover.isEmpty ? null : cover;
}