UNPKG

@core-graphics/rect

Version:
95 lines (88 loc) 2.34 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var fromPoints = require('../../dist/from-points-553fce0b.cjs.dev.js'); require('../../dist/unsupportedIterableToArray-7cc9ff15.cjs.dev.js'); require('../../dist/lite-6b05303c.cjs.dev.js'); require('@core-graphics/point'); require('@core-graphics/size'); /** * Returns the shrinked or expanded version of the rectangle * based on the inset values specified. */ function egdeInset(r, inset) { var rect = r.clone(); var _inset$top = inset.top, top = _inset$top === void 0 ? 0 : _inset$top, _inset$right = inset.right, right = _inset$right === void 0 ? 0 : _inset$right, _inset$bottom = inset.bottom, bottom = _inset$bottom === void 0 ? 0 : _inset$bottom, _inset$left = inset.left, left = _inset$left === void 0 ? 0 : _inset$left; rect.origin.add({ x: left, y: top }); rect.size.set({ width: rect.width - left - right, height: rect.height - top - bottom }); return rect; } function expand(r, v) { var value = typeof v === "number" ? { dx: -v, dy: -v } : v; return inset(r, value); } function shrink(r, v) { var value = typeof v === "number" ? { dx: -v, dy: -v } : v; return inset(r, value); } /** * Returns a symmetrically contracted/expanded Rect based on * the specified amount. */ function inset(r, value) { var _value$dx = value.dx, dx = _value$dx === void 0 ? 0 : _value$dx, _value$dy = value.dy, dy = _value$dy === void 0 ? 0 : _value$dy; var inset = { left: dx, right: dx, top: dy, bottom: dy }; return egdeInset(r, inset); } /** * Returns a new Rect with its origin shifted by the specified offset */ function shift(r, offset) { var rect = r.clone(); var _offset$x = offset.x, x = _offset$x === void 0 ? 0 : _offset$x, _offset$y = offset.y, y = _offset$y === void 0 ? 0 : _offset$y; rect.origin.add({ x: x, y: y }); return rect; } function rotate(r, deg, origin) { return fromPoints.fromPoints.apply(void 0, fromPoints._toConsumableArray(r.cornerPoints.map(function (p) { return p.rotate(deg, origin); }))); } exports.egdeInset = egdeInset; exports.expand = expand; exports.inset = inset; exports.rotate = rotate; exports.shift = shift; exports.shrink = shrink;