getAsScale method

double getAsScale (Matrix4 transform)

Returns the given transform matrix as a double describing a uniform scale, if the matrix is nothing but a symmetric 2D scale transform.

Otherwise, returns null.

Implementation

static double getAsScale(Matrix4 transform) {
  assert(transform != null);
  final Float64List values = transform.storage;
  // Values are stored in column-major order.
  if (values[1] == 0.0 && // col 1 (value 0 is the scale)
      values[2] == 0.0 &&
      values[3] == 0.0 &&
      values[4] == 0.0 && // col 2 (value 5 is the scale)
      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[12] == 0.0 && // col 4
      values[13] == 0.0 &&
      values[14] == 0.0 &&
      values[15] == 1.0 &&
      values[0] == values[5]) { // uniform scale
    return values[0];
  }
  return null;
}