UNPKG

@davepagurek/flo-mat

Version:

Medial / Scale Axis Transform (MAT/SAT) Library.

16 lines 689 B
import { squaredDistanceBetweenPointAndLineSegment, squaredDistanceBetween } from 'flo-vector2d'; /** * @internal */ function getClosestSquaredDistanceToRotatedRect(ps, p) { const ds = [0, 1, 2, 3].map(i => squaredDistanceBetweenPointAndLineSegment(p, [ps[i], ps[(i + 1) % 4]])); const width = squaredDistanceBetween(ps[0], ps[1]); const height = squaredDistanceBetween(ps[0], ps[3]); if (ds[0] <= height && ds[2] <= height && ds[1] <= width && ds[3] <= width) { return 0; // Inside rotated rect } return Math.min(...ds); } export { getClosestSquaredDistanceToRotatedRect }; //# sourceMappingURL=get-closest-squared-distance-to-rotated-rect.js.map