@core-graphics/rect
Version:
JS utilities for managing rects
48 lines (39 loc) • 1.51 kB
JavaScript
import { _ as _arrayLikeToArray, a as _unsupportedIterableToArray } from './unsupportedIterableToArray-9785118b.esm.js';
import { R as Rect } from './lite-3fdd983e.esm.js';
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
/**
* Creates a rectangle from a set of points
*/
function fromPoints() {
for (var _len = arguments.length, pts = new Array(_len), _key = 0; _key < _len; _key++) {
pts[_key] = arguments[_key];
}
var xValues = pts.map(function (p) {
return p.x;
});
var yValues = pts.map(function (p) {
return p.y;
});
var x = Math.min.apply(Math, _toConsumableArray(xValues));
var y = Math.min.apply(Math, _toConsumableArray(yValues));
var width = Math.max.apply(Math, _toConsumableArray(xValues)) - x;
var height = Math.max.apply(Math, _toConsumableArray(yValues)) - y;
return new Rect({
x: x,
y: y,
width: width,
height: height
});
}
export { _toConsumableArray as _, fromPoints as f };