getAsTranslation static method

Offset? getAsTranslation(
  1. Matrix4 transform
)

Returns the given transform matrix as an Offset, if the matrix is nothing but a 2D translation.

Otherwise, returns null.

Implementation

static Offset? getAsTranslation(Matrix4 transform) {
  final Float64List values = transform.storage;
  // Values are stored in column-major order.
  if (values[0] == 1.0 && // col 1
      values[1] == 0.0 &&
      values[2] == 0.0 &&
      values[3] == 0.0 &&
      values[4] == 0.0 && // col 2
      values[5] == 1.0 &&
      values[6] == 0.0 &&
      values[7] == 0.0 &&
      values[8] == 0.0 && // col 3
      values[9] == 0.0 &&
      values[10] == 1.0 &&
      values[11] == 0.0 &&
      values[14] == 0.0 && // bottom of col 4 (values 12 and 13 are the x and y offsets)
      values[15] == 1.0) {
    return Offset(values[12], values[13]);
  }
  return null;
}