@core-graphics/rect
Version:
JS utilities for managing rects
51 lines (41 loc) • 1.64 kB
JavaScript
;
var unsupportedIterableToArray = require('./unsupportedIterableToArray-7cc9ff15.cjs.dev.js');
var lite_dist_coreGraphicsRectLite = require('./lite-6b05303c.cjs.dev.js');
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return unsupportedIterableToArray._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._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 lite_dist_coreGraphicsRectLite.Rect({
x: x,
y: y,
width: width,
height: height
});
}
exports._toConsumableArray = _toConsumableArray;
exports.fromPoints = fromPoints;