MCPcopy
hub / github.com/donmccurdy/glTF-Transform / fitWithin

Function fitWithin

packages/functions/src/utils.ts:313–333  ·  view source on GitHub ↗
(size: vec2, limit: vec2)

Source from the content-addressed store, hash-verified

311 * @hidden
312 */
313export 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
335type ResizePreset = 'nearest-pot' | 'ceil-pot' | 'floor-pot';
336

Callers 3

toktxFunction · 0.90
_encodeWithSharpFunction · 0.85
_encodeWithNdarrayPixelsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected