transformDeltaViaPositions static method

Offset transformDeltaViaPositions(
  1. {required Offset untransformedEndPosition,
  2. Offset? transformedEndPosition,
  3. required Offset untransformedDelta,
  4. required Matrix4? transform}
)

Transforms untransformedDelta into the coordinate system described by transform.

It uses the provided untransformedEndPosition and transformedEndPosition of the provided delta to increase accuracy.

If transform is null, untransformedDelta is returned.

Implementation

static Offset transformDeltaViaPositions({
  required Offset untransformedEndPosition,
  Offset? transformedEndPosition,
  required Offset untransformedDelta,
  required Matrix4? transform,
}) {
  if (transform == null) {
    return untransformedDelta;
  }
  // We could transform the delta directly with the transformation matrix.
  // While that is mathematically equivalent, in practice we are seeing a
  // greater precision error with that approach. Instead, we are transforming
  // start and end point of the delta separately and calculate the delta in
  // the new space for greater accuracy.
  transformedEndPosition ??= transformPosition(transform, untransformedEndPosition);
  final Offset transformedStartPosition = transformPosition(transform, untransformedEndPosition - untransformedDelta);
  return transformedEndPosition - transformedStartPosition;
}