transformRectAroundCenter method
Implementation
Rect transformRectAroundCenter(Matrix4 matrix, Rect rect) {
final center = rect.center;
final translateToOrigin = Matrix4.translationValues(-center.dx, -center.dy, 0.0);
final translateBack = Matrix4.translationValues(center.dx, center.dy, 0.0);
final combinedMatrix = translateBack * matrix * translateToOrigin;
final topLeft = combinedMatrix.transform3(Vector3(rect.left, rect.top, 0.0));
final topRight = combinedMatrix.transform3(Vector3(rect.right, rect.top, 0.0));
final bottomLeft = combinedMatrix.transform3(Vector3(rect.left, rect.bottom, 0.0));
final bottomRight = combinedMatrix.transform3(Vector3(rect.right, rect.bottom, 0.0));
final minX = min(min(min(topLeft.x, topRight.x), bottomLeft.x), bottomRight.x);
final maxX = max(max(max(topLeft.x, topRight.x), bottomLeft.x), bottomRight.x);
final minY = min(min(min(topLeft.y, topRight.y), bottomLeft.y), bottomRight.y);
final maxY = max(max(max(topLeft.y, topRight.y), bottomLeft.y), bottomRight.y);
return Rect.fromLTRB(minX, minY, maxX, maxY);
}