clamp method
- Rect bounds
Clamps this rectangle to fit within the given bounds
.
This is different from intersect in that the size of the rectangle is not changed, only its position.
Implementation
Rect clamp(Rect bounds) {
final x = math.max(this.x, bounds.x);
final y = math.max(this.y, bounds.y);
final right = math.min(this.right, bounds.right);
final bottom = math.min(this.bottom, bounds.bottom);
return Rect.fromLTWH(x, y, right - x, bottom - y);
}