UNPKG

@rxflow/manhattan

Version:

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

65 lines (58 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Rectangle = void 0; var _Point = require("./Point"); /** * Rectangle class representing a bounding box */ class Rectangle { x; y; width; height; constructor(x, y, width, height) { this.x = x; this.y = y; this.width = width; this.height = height; } /** * Create a copy of this rectangle */ clone() { return new Rectangle(this.x, this.y, this.width, this.height); } /** * Get the center point of the rectangle */ getCenter() { return new _Point.Point(this.x + this.width / 2, this.y + this.height / 2); } /** * Get the origin (top-left) point of the rectangle */ getOrigin() { return new _Point.Point(this.x, this.y); } /** * Get the corner (bottom-right) point of the rectangle */ getCorner() { return new _Point.Point(this.x + this.width, this.y + this.height); } /** * Check if a point is contained within this rectangle (interior only, excluding edges) */ 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 */ moveAndExpand(box) { return new Rectangle(this.x + box.x, this.y + box.y, this.width + box.width, this.height + box.height); } } exports.Rectangle = Rectangle;