import type { Loop } from 'flo-boolean'; import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js'; import { memoize } from 'flo-memoize'; import { getLoopBounds$ } from './get-loop-bounds.js'; /** @internal */ const getShapeBounds = memoize(function(loops: Loop[]) { let minX_ = +Infinity; let maxX_ = -Infinity; let minY_ = +Infinity; let maxY_ = -Infinity; let minX: PrePointOnShape; let maxX: PrePointOnShape; let minY: PrePointOnShape; let maxY: PrePointOnShape; for (const loop of loops) { const bounds = getLoopBounds$(loop); if (bounds.minX.p[0] < minX_) { minX = bounds.minX; minX_ = bounds.minX.p[0]; } if (bounds.maxX.p[0] > maxX_) { maxX = bounds.maxX; maxX_ = bounds.maxX.p[0]; } if (bounds.minY.p[1] < minY_) { minY = bounds.minY; minY_ = bounds.minY.p[1]; } if (bounds.maxY.p[1] > maxY_) { maxY = bounds.maxY; maxY_ = bounds.maxY.p[1]; } } return { minX: minX!, minY: minY!, maxX: maxX!, maxY: maxY! }; }); export { getShapeBounds }