(rect: Rectangle, size: Size)
| 69 | } |
| 70 | |
| 71 | export function clampRect(rect: Rectangle, size: Size): Rectangle { |
| 72 | const minX = Math.max(0, rect.x) |
| 73 | const minY = Math.max(0, rect.y) |
| 74 | const maxX = Math.min(size.width - 1, rect.x + rect.width - 1) |
| 75 | const maxY = Math.min(size.height - 1, rect.y + rect.height - 1) |
| 76 | return { |
| 77 | x: minX, |
| 78 | y: minY, |
| 79 | width: Math.max(0, maxX - minX + 1), |
| 80 | height: Math.max(0, maxY - minY + 1), |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | export function withinBounds(size: Size, point: Point): boolean { |
| 85 | return ( |