UNPKG

@rxflow/manhattan

Version:

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

66 lines (59 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.align = align; exports.getGrid = getGrid; exports.round = round; exports.snapToGrid = snapToGrid; var _geometry = require("../geometry"); /** * Grid interface for dynamic grid system */ /** * Get grid dimension for a single axis */ function getGridDimension(diff, step) { // Always return fixed step size to maintain consistent padding // This ensures paths stay at least 'padding' distance from obstacles return step; } /** * Get grid size in x and y dimensions, adapted to source and target positions * Uses global grid system with origin at (0, 0) for path alignment */ function getGrid(step, source, target) { return { source: new _geometry.Point(0, 0), // Use global origin for consistent grid alignment x: getGridDimension(target.x - source.x, step), y: getGridDimension(target.y - source.y, step) }; } /** * Snap a value to grid */ function snapToGrid(value, gridSize) { return Math.round(value / gridSize) * gridSize; } /** * Snap a point to grid */ function snapPointToGrid(point, grid) { const source = grid.source; const x = snapToGrid(point.x - source.x, grid.x) + source.x; const y = snapToGrid(point.y - source.y, grid.y) + source.y; return new _geometry.Point(x, y); } /** * Align point to grid and apply precision */ function align(point, grid, precision) { return snapPointToGrid(point.clone(), grid).round(precision); } /** * Round point coordinates */ function round(point, precision) { return point.round(precision); }