UNPKG

@rxflow/manhattan

Version:

Manhattan routing algorithm for ReactFlow - generates orthogonal paths with obstacle avoidance

81 lines (74 loc) 3.64 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import { Point } from "./Point"; /** * Rectangle class representing a bounding box */ export var Rectangle = /*#__PURE__*/function () { function Rectangle(x, y, width, height) { _classCallCheck(this, Rectangle); _defineProperty(this, "x", void 0); _defineProperty(this, "y", void 0); _defineProperty(this, "width", void 0); _defineProperty(this, "height", void 0); this.x = x; this.y = y; this.width = width; this.height = height; } /** * Create a copy of this rectangle */ _createClass(Rectangle, [{ key: "clone", value: function clone() { return new Rectangle(this.x, this.y, this.width, this.height); } /** * Get the center point of the rectangle */ }, { key: "getCenter", value: function getCenter() { return new Point(this.x + this.width / 2, this.y + this.height / 2); } /** * Get the origin (top-left) point of the rectangle */ }, { key: "getOrigin", value: function getOrigin() { return new Point(this.x, this.y); } /** * Get the corner (bottom-right) point of the rectangle */ }, { key: "getCorner", value: function getCorner() { return new Point(this.x + this.width, this.y + this.height); } /** * Check if a point is contained within this rectangle (interior only, excluding edges) */ }, { key: "containsPoint", value: function containsPoint(point) { return point.x > this.x && point.x < this.x + this.width && point.y > this.y && point.y < this.y + this.height; } /** * Move and expand the rectangle by a box offset */ }, { key: "moveAndExpand", value: function moveAndExpand(box) { return new Rectangle(this.x + box.x, this.y + box.y, this.width + box.width, this.height + box.height); } }]); return Rectangle; }();