clamp method
Implementation
Offset clamp(Size imageSize, Size canvasSize) {
double dx = this.dx;
if (dx + imageSize.width > canvasSize.width) {
dx = dx - imageSize.width;
}
double dy = this.dy;
if (-dy < imageSize.height) {
dy = -imageSize.height.toDouble();
} else if (-dy > canvasSize.height) {
dy = -canvasSize.height;
}
return Offset(dx, dy);
}