(size: vec2, limit: vec2)
| 311 | * @hidden |
| 312 | */ |
| 313 | export function fitWithin(size: vec2, limit: vec2): vec2 { |
| 314 | const [maxWidth, maxHeight] = limit; |
| 315 | const [srcWidth, srcHeight] = size; |
| 316 | |
| 317 | if (srcWidth <= maxWidth && srcHeight <= maxHeight) return size; |
| 318 | |
| 319 | let dstWidth = srcWidth; |
| 320 | let dstHeight = srcHeight; |
| 321 | |
| 322 | if (dstWidth > maxWidth) { |
| 323 | dstHeight = Math.floor(dstHeight * (maxWidth / dstWidth)); |
| 324 | dstWidth = maxWidth; |
| 325 | } |
| 326 | |
| 327 | if (dstHeight > maxHeight) { |
| 328 | dstWidth = Math.floor(dstWidth * (maxHeight / dstHeight)); |
| 329 | dstHeight = maxHeight; |
| 330 | } |
| 331 | |
| 332 | return [dstWidth, dstHeight]; |
| 333 | } |
| 334 | |
| 335 | type ResizePreset = 'nearest-pot' | 'ceil-pot' | 'floor-pot'; |
| 336 |
no outgoing calls
no test coverage detected