transformPath static method

Path transformPath({
  1. required Size size,
  2. required Path path,
  3. double scale = 1.0,
  4. double rotation = 0.0,
  5. Matrix4? matrix,
})

Implementation

static Path transformPath({
  required Size size,
  required Path path,
  double scale = 1.0,
  double rotation = 0.0,
  Matrix4? matrix,
}) {
  final canvasCenter = size.center(.zero);
  final pathCenter = path.getBounds().center;
  (matrix ??= Matrix4.zero())
    ..setIdentity()
    // Translate the path to align its center with the available size center.
    ..translateByDouble(canvasCenter.dx, canvasCenter.dy, 0.0, 1.0)
    // Apply rotation.
    ..rotateZ(rotation)
    // Scale to the desired size.
    ..scaleByDouble(size.width * scale, size.height * scale, 1.0, 1.0)
    // Translate the path to align its center with (0, 0).
    ..translateByDouble(-pathCenter.dx, -pathCenter.dy, 0.0, 1.0);
  return path.transform(matrix.storage);
}