UNPKG

@core-graphics/rect

Version:
86 lines (81 loc) 2.16 kB
import { f as fromPoints, _ as _toConsumableArray } from '../../dist/from-points-e5b0935a.esm.js'; import '../../dist/unsupportedIterableToArray-9785118b.esm.js'; import '../../dist/lite-3fdd983e.esm.js'; import '@core-graphics/point'; import '@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.apply(void 0, _toConsumableArray(r.cornerPoints.map(function (p) { return p.rotate(deg, origin); }))); } export { egdeInset, expand, inset, rotate, shift, shrink };