@rxflow/manhattan 0.0.2-alpha.8 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +214 -10
  2. package/esm/getManHattanPath.js +92 -69
  3. package/esm/obstacle/ObstacleMap.js +218 -99
  4. package/esm/obstacle/QuadTree.js +488 -0
  5. package/esm/options/resolver.js +147 -18
  6. package/esm/pathfinder/PathCache.js +278 -0
  7. package/esm/pathfinder/findRoute.js +98 -44
  8. package/esm/pathfinder/index.js +2 -1
  9. package/esm/svg/pathConverter.js +170 -1
  10. package/esm/utils/AdaptiveStepCalculator.js +252 -0
  11. package/esm/utils/ErrorRecovery.js +499 -0
  12. package/esm/utils/GlobalGrid.js +259 -0
  13. package/esm/utils/PerformanceMonitor.js +360 -0
  14. package/esm/utils/getAnchorPoints.js +0 -4
  15. package/esm/utils/grid.js +18 -13
  16. package/esm/utils/heuristics.js +144 -0
  17. package/esm/utils/index.js +7 -1
  18. package/esm/utils/pathProcessing.js +270 -0
  19. package/esm/utils/pathValidation.js +0 -1
  20. package/esm/utils/rect.js +11 -4
  21. package/esm/utils/route.js +18 -2
  22. package/package.json +10 -2
  23. package/cjs/geometry/Line.d.ts +0 -21
  24. package/cjs/geometry/Line.d.ts.map +0 -1
  25. package/cjs/geometry/Line.js +0 -88
  26. package/cjs/geometry/Point.d.ts +0 -49
  27. package/cjs/geometry/Point.d.ts.map +0 -1
  28. package/cjs/geometry/Point.js +0 -94
  29. package/cjs/geometry/Rectangle.d.ts +0 -41
  30. package/cjs/geometry/Rectangle.d.ts.map +0 -1
  31. package/cjs/geometry/Rectangle.js +0 -65
  32. package/cjs/geometry/collision.d.ts +0 -15
  33. package/cjs/geometry/collision.d.ts.map +0 -1
  34. package/cjs/geometry/collision.js +0 -81
  35. package/cjs/geometry/index.d.ts +0 -5
  36. package/cjs/geometry/index.d.ts.map +0 -1
  37. package/cjs/geometry/index.js +0 -45
  38. package/cjs/getManHattanPath.d.ts +0 -53
  39. package/cjs/getManHattanPath.d.ts.map +0 -1
  40. package/cjs/getManHattanPath.js +0 -418
  41. package/cjs/index.d.ts +0 -16
  42. package/cjs/index.d.ts.map +0 -1
  43. package/cjs/index.js +0 -117
  44. package/cjs/obstacle/ObstacleMap.d.ts +0 -34
  45. package/cjs/obstacle/ObstacleMap.d.ts.map +0 -1
  46. package/cjs/obstacle/ObstacleMap.js +0 -223
  47. package/cjs/obstacle/index.d.ts +0 -2
  48. package/cjs/obstacle/index.d.ts.map +0 -1
  49. package/cjs/obstacle/index.js +0 -12
  50. package/cjs/options/defaults.d.ts +0 -16
  51. package/cjs/options/defaults.d.ts.map +0 -1
  52. package/cjs/options/defaults.js +0 -39
  53. package/cjs/options/index.d.ts +0 -4
  54. package/cjs/options/index.d.ts.map +0 -1
  55. package/cjs/options/index.js +0 -38
  56. package/cjs/options/resolver.d.ts +0 -10
  57. package/cjs/options/resolver.d.ts.map +0 -1
  58. package/cjs/options/resolver.js +0 -120
  59. package/cjs/options/types.d.ts +0 -169
  60. package/cjs/options/types.d.ts.map +0 -1
  61. package/cjs/options/types.js +0 -5
  62. package/cjs/pathfinder/SortedSet.d.ts +0 -35
  63. package/cjs/pathfinder/SortedSet.d.ts.map +0 -1
  64. package/cjs/pathfinder/SortedSet.js +0 -95
  65. package/cjs/pathfinder/findRoute.d.ts +0 -8
  66. package/cjs/pathfinder/findRoute.d.ts.map +0 -1
  67. package/cjs/pathfinder/findRoute.js +0 -330
  68. package/cjs/pathfinder/index.d.ts +0 -3
  69. package/cjs/pathfinder/index.d.ts.map +0 -1
  70. package/cjs/pathfinder/index.js +0 -19
  71. package/cjs/svg/index.d.ts +0 -3
  72. package/cjs/svg/index.d.ts.map +0 -1
  73. package/cjs/svg/index.js +0 -31
  74. package/cjs/svg/pathConverter.d.ts +0 -10
  75. package/cjs/svg/pathConverter.d.ts.map +0 -1
  76. package/cjs/svg/pathConverter.js +0 -116
  77. package/cjs/svg/pathParser.d.ts +0 -11
  78. package/cjs/svg/pathParser.d.ts.map +0 -1
  79. package/cjs/svg/pathParser.js +0 -76
  80. package/cjs/utils/direction.d.ts +0 -24
  81. package/cjs/utils/direction.d.ts.map +0 -1
  82. package/cjs/utils/direction.js +0 -54
  83. package/cjs/utils/getAnchorPoints.d.ts +0 -15
  84. package/cjs/utils/getAnchorPoints.d.ts.map +0 -1
  85. package/cjs/utils/getAnchorPoints.js +0 -75
  86. package/cjs/utils/grid.d.ts +0 -27
  87. package/cjs/utils/grid.d.ts.map +0 -1
  88. package/cjs/utils/grid.js +0 -66
  89. package/cjs/utils/index.d.ts +0 -8
  90. package/cjs/utils/index.d.ts.map +0 -1
  91. package/cjs/utils/index.js +0 -82
  92. package/cjs/utils/node.d.ts +0 -27
  93. package/cjs/utils/node.d.ts.map +0 -1
  94. package/cjs/utils/node.js +0 -36
  95. package/cjs/utils/pathValidation.d.ts +0 -11
  96. package/cjs/utils/pathValidation.d.ts.map +0 -1
  97. package/cjs/utils/pathValidation.js +0 -130
  98. package/cjs/utils/rect.d.ts +0 -9
  99. package/cjs/utils/rect.d.ts.map +0 -1
  100. package/cjs/utils/rect.js +0 -103
  101. package/cjs/utils/route.d.ts +0 -19
  102. package/cjs/utils/route.d.ts.map +0 -1
  103. package/cjs/utils/route.js +0 -76
  104. package/esm/geometry/Line.d.ts +0 -21
  105. package/esm/geometry/Line.d.ts.map +0 -1
  106. package/esm/geometry/Point.d.ts +0 -49
  107. package/esm/geometry/Point.d.ts.map +0 -1
  108. package/esm/geometry/Rectangle.d.ts +0 -41
  109. package/esm/geometry/Rectangle.d.ts.map +0 -1
  110. package/esm/geometry/collision.d.ts +0 -15
  111. package/esm/geometry/collision.d.ts.map +0 -1
  112. package/esm/geometry/index.d.ts +0 -5
  113. package/esm/geometry/index.d.ts.map +0 -1
  114. package/esm/getManHattanPath.d.ts +0 -53
  115. package/esm/getManHattanPath.d.ts.map +0 -1
  116. package/esm/index.d.ts +0 -16
  117. package/esm/index.d.ts.map +0 -1
  118. package/esm/obstacle/ObstacleMap.d.ts +0 -34
  119. package/esm/obstacle/ObstacleMap.d.ts.map +0 -1
  120. package/esm/obstacle/index.d.ts +0 -2
  121. package/esm/obstacle/index.d.ts.map +0 -1
  122. package/esm/options/defaults.d.ts +0 -16
  123. package/esm/options/defaults.d.ts.map +0 -1
  124. package/esm/options/index.d.ts +0 -4
  125. package/esm/options/index.d.ts.map +0 -1
  126. package/esm/options/resolver.d.ts +0 -10
  127. package/esm/options/resolver.d.ts.map +0 -1
  128. package/esm/options/types.d.ts +0 -169
  129. package/esm/options/types.d.ts.map +0 -1
  130. package/esm/pathfinder/SortedSet.d.ts +0 -35
  131. package/esm/pathfinder/SortedSet.d.ts.map +0 -1
  132. package/esm/pathfinder/findRoute.d.ts +0 -8
  133. package/esm/pathfinder/findRoute.d.ts.map +0 -1
  134. package/esm/pathfinder/index.d.ts +0 -3
  135. package/esm/pathfinder/index.d.ts.map +0 -1
  136. package/esm/svg/index.d.ts +0 -3
  137. package/esm/svg/index.d.ts.map +0 -1
  138. package/esm/svg/pathConverter.d.ts +0 -10
  139. package/esm/svg/pathConverter.d.ts.map +0 -1
  140. package/esm/svg/pathParser.d.ts +0 -11
  141. package/esm/svg/pathParser.d.ts.map +0 -1
  142. package/esm/utils/direction.d.ts +0 -24
  143. package/esm/utils/direction.d.ts.map +0 -1
  144. package/esm/utils/getAnchorPoints.d.ts +0 -15
  145. package/esm/utils/getAnchorPoints.d.ts.map +0 -1
  146. package/esm/utils/grid.d.ts +0 -27
  147. package/esm/utils/grid.d.ts.map +0 -1
  148. package/esm/utils/index.d.ts +0 -8
  149. package/esm/utils/index.d.ts.map +0 -1
  150. package/esm/utils/node.d.ts +0 -27
  151. package/esm/utils/node.d.ts.map +0 -1
  152. package/esm/utils/pathValidation.d.ts +0 -11
  153. package/esm/utils/pathValidation.d.ts.map +0 -1
  154. package/esm/utils/rect.d.ts +0 -9
  155. package/esm/utils/rect.d.ts.map +0 -1
  156. package/esm/utils/route.d.ts +0 -19
  157. package/esm/utils/route.d.ts.map +0 -1
@@ -1,130 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.pathIntersectsObstacles = pathIntersectsObstacles;
7
- var _geometry = require("../geometry");
8
- var _node = require("./node");
9
- /**
10
- * Get node bounding box
11
- */
12
- function getNodeBBox(nodeId, nodeLookup) {
13
- const node = nodeLookup.get(nodeId);
14
- if (!node) return null;
15
- const dimensions = (0, _node.getNodeDimensions)(node);
16
- const position = (0, _node.getNodePosition)(node);
17
- return new _geometry.Rectangle(position.x, position.y, dimensions.width, dimensions.height);
18
- }
19
-
20
- /**
21
- * Find unique intersection points between a line segment and a rectangle
22
- * Returns array of intersection points (deduplicated)
23
- */
24
- function findSegmentRectIntersections(p1, p2, rect) {
25
- const intersections = [];
26
- const tolerance = 0.01;
27
-
28
- // Define rectangle edges
29
- const edges = [{
30
- start: new _geometry.Point(rect.x, rect.y),
31
- end: new _geometry.Point(rect.x + rect.width, rect.y)
32
- },
33
- // Top
34
- {
35
- start: new _geometry.Point(rect.x + rect.width, rect.y),
36
- end: new _geometry.Point(rect.x + rect.width, rect.y + rect.height)
37
- },
38
- // Right
39
- {
40
- start: new _geometry.Point(rect.x + rect.width, rect.y + rect.height),
41
- end: new _geometry.Point(rect.x, rect.y + rect.height)
42
- },
43
- // Bottom
44
- {
45
- start: new _geometry.Point(rect.x, rect.y + rect.height),
46
- end: new _geometry.Point(rect.x, rect.y)
47
- } // Left
48
- ];
49
-
50
- // Find intersection point with each edge
51
- for (const edge of edges) {
52
- const intersection = getLineSegmentIntersection(p1, p2, edge.start, edge.end);
53
- if (intersection) {
54
- // Check if this point is already in the list (avoid duplicates at corners)
55
- const isDuplicate = intersections.some(existing => Math.abs(existing.x - intersection.x) < tolerance && Math.abs(existing.y - intersection.y) < tolerance);
56
- if (!isDuplicate) {
57
- intersections.push(intersection);
58
- }
59
- }
60
- }
61
- return intersections;
62
- }
63
-
64
- /**
65
- * Get intersection point between two line segments (if exists)
66
- */
67
- function getLineSegmentIntersection(p1, p2, p3, p4) {
68
- const d1 = direction(p3, p4, p1);
69
- const d2 = direction(p3, p4, p2);
70
- const d3 = direction(p1, p2, p3);
71
- const d4 = direction(p1, p2, p4);
72
- if ((d1 > 0 && d2 < 0 || d1 < 0 && d2 > 0) && (d3 > 0 && d4 < 0 || d3 < 0 && d4 > 0)) {
73
- // Lines intersect, calculate intersection point
74
- const t = ((p3.x - p1.x) * (p3.y - p4.y) - (p3.y - p1.y) * (p3.x - p4.x)) / ((p1.x - p2.x) * (p3.y - p4.y) - (p1.y - p2.y) * (p3.x - p4.x));
75
- return new _geometry.Point(p1.x + t * (p2.x - p1.x), p1.y + t * (p2.y - p1.y));
76
- }
77
-
78
- // Check collinear cases
79
- if (d1 === 0 && onSegment(p3, p1, p4)) return p1.clone();
80
- if (d2 === 0 && onSegment(p3, p2, p4)) return p2.clone();
81
- if (d3 === 0 && onSegment(p1, p3, p2)) return p3.clone();
82
- if (d4 === 0 && onSegment(p1, p4, p2)) return p4.clone();
83
- return null;
84
- }
85
- function direction(p1, p2, p3) {
86
- return (p3.x - p1.x) * (p2.y - p1.y) - (p2.x - p1.x) * (p3.y - p1.y);
87
- }
88
- function onSegment(p1, p2, p3) {
89
- return p2.x >= Math.min(p1.x, p3.x) && p2.x <= Math.max(p1.x, p3.x) && p2.y >= Math.min(p1.y, p3.y) && p2.y <= Math.max(p1.y, p3.y);
90
- }
91
-
92
- /**
93
- * Check if a path intersects with any obstacles (nodes)
94
- * A path is considered to intersect if it has >= 2 unique intersection points with a node
95
- *
96
- * Note: pathPoints should be pre-processed by parseSVGPath which samples bezier curves
97
- * into line segments, so this function works correctly with curved paths
98
- */
99
- function pathIntersectsObstacles(pathPoints, nodeLookup) {
100
- const tolerance = 0.01;
101
-
102
- // Iterate through all nodes (including source and target)
103
- for (const [nodeId] of nodeLookup) {
104
- const nodeBBox = getNodeBBox(nodeId, nodeLookup);
105
- if (!nodeBBox) continue;
106
- const allIntersections = [];
107
-
108
- // Collect all unique intersection points for this node
109
- for (let i = 0; i < pathPoints.length - 1; i++) {
110
- const p1 = pathPoints[i];
111
- const p2 = pathPoints[i + 1];
112
- const segmentIntersections = findSegmentRectIntersections(p1, p2, nodeBBox);
113
-
114
- // Add to global list, avoiding duplicates
115
- for (const intersection of segmentIntersections) {
116
- const isDuplicate = allIntersections.some(existing => Math.abs(existing.x - intersection.x) < tolerance && Math.abs(existing.y - intersection.y) < tolerance);
117
- if (!isDuplicate) {
118
- allIntersections.push(intersection);
119
- }
120
- }
121
- }
122
-
123
- // If path has 2 or more unique intersections with this node, it crosses through it
124
- if (allIntersections.length >= 2) {
125
- console.log(`[pathIntersectsObstacles] Path crosses node ${nodeId} with ${allIntersections.length} intersections`);
126
- return true;
127
- }
128
- }
129
- return false;
130
- }
@@ -1,9 +0,0 @@
1
- import { Point, Rectangle } from '../geometry';
2
- import type { ResolvedOptions, Direction } from '../options';
3
- import type { Grid } from './grid';
4
- /**
5
- * Get points around a rectangle taking given directions into account
6
- * Lines are drawn from anchor in given directions, intersections recorded
7
- */
8
- export declare function getRectPoints(anchor: Point, bbox: Rectangle, directionList: Direction[], grid: Grid, options: ResolvedOptions): Point[];
9
- //# sourceMappingURL=rect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rect.d.ts","sourceRoot":"","sources":["../../src/utils/rect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAQ,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AA6ClC;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,KAAK,EACb,IAAI,EAAE,SAAS,EACf,aAAa,EAAE,SAAS,EAAE,EAC1B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,eAAe,GACvB,KAAK,EAAE,CAsET"}
package/cjs/utils/rect.js DELETED
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getRectPoints = getRectPoints;
7
- var _geometry = require("../geometry");
8
- var _grid = require("./grid");
9
- /**
10
- * Check if a point is on the edge of a rectangle
11
- */
12
- function isPointOnRectangleEdge(point, bbox, tolerance = 0.01) {
13
- const onLeft = Math.abs(point.x - bbox.x) < tolerance;
14
- const onRight = Math.abs(point.x - (bbox.x + bbox.width)) < tolerance;
15
- const onTop = Math.abs(point.y - bbox.y) < tolerance;
16
- const onBottom = Math.abs(point.y - (bbox.y + bbox.height)) < tolerance;
17
- const withinVerticalBounds = point.y >= bbox.y - tolerance && point.y <= bbox.y + bbox.height + tolerance;
18
- const withinHorizontalBounds = point.x >= bbox.x - tolerance && point.x <= bbox.x + bbox.width + tolerance;
19
- return (onLeft || onRight) && withinVerticalBounds || (onTop || onBottom) && withinHorizontalBounds;
20
- }
21
-
22
- /**
23
- * Check if a direction points outward from the rectangle edge where the anchor is located
24
- */
25
- function isDirectionOutward(anchor, bbox, direction, tolerance = 0.01) {
26
- const onLeft = Math.abs(anchor.x - bbox.x) < tolerance;
27
- const onRight = Math.abs(anchor.x - (bbox.x + bbox.width)) < tolerance;
28
- const onTop = Math.abs(anchor.y - bbox.y) < tolerance;
29
- const onBottom = Math.abs(anchor.y - (bbox.y + bbox.height)) < tolerance;
30
-
31
- // Only allow outward directions from the edge
32
- if (onLeft && direction.x < 0) return true;
33
- if (onRight && direction.x > 0) return true;
34
- if (onTop && direction.y < 0) return true;
35
- if (onBottom && direction.y > 0) return true;
36
-
37
- // For corners, allow both perpendicular directions
38
- if ((onLeft || onRight) && direction.x === 0) return true;
39
- if ((onTop || onBottom) && direction.y === 0) return true;
40
- return false;
41
- }
42
-
43
- /**
44
- * Get points around a rectangle taking given directions into account
45
- * Lines are drawn from anchor in given directions, intersections recorded
46
- */
47
- function getRectPoints(anchor, bbox, directionList, grid, options) {
48
- const precision = options.precision;
49
- const directionMap = options.directionMap;
50
- const centerVector = anchor.diff(bbox.getCenter());
51
- const rectPoints = [];
52
-
53
- // Check if anchor is on the edge of the bbox
54
- const isOnEdge = isPointOnRectangleEdge(anchor, bbox);
55
-
56
- // Check each allowed direction
57
- for (const key of directionList) {
58
- const direction = directionMap[key];
59
-
60
- // If anchor is on edge, only consider outward directions
61
- if (isOnEdge) {
62
- const isOutward = isDirectionOutward(anchor, bbox, direction);
63
- if (!isOutward) {
64
- continue; // Skip inward directions
65
- }
66
- }
67
-
68
- // Create a line that is guaranteed to intersect the bbox if bbox
69
- // is in the direction even if anchor lies outside of bbox
70
- const ending = new _geometry.Point(anchor.x + direction.x * (Math.abs(centerVector.x) + bbox.width), anchor.y + direction.y * (Math.abs(centerVector.y) + bbox.height));
71
- const intersectionLine = new _geometry.Line(anchor, ending);
72
-
73
- // Get the farther intersection, in case there are two
74
- const intersections = intersectionLine.intersect(bbox);
75
- let farthestIntersectionDistance;
76
- let farthestIntersection = null;
77
- for (const intersection of intersections) {
78
- const distance = anchor.squaredDistance(intersection);
79
- if (farthestIntersectionDistance === undefined || distance > farthestIntersectionDistance) {
80
- farthestIntersectionDistance = distance;
81
- farthestIntersection = intersection;
82
- }
83
- }
84
-
85
- // If an intersection was found in this direction, it is our rectPoint
86
- if (farthestIntersection) {
87
- let target = (0, _grid.align)(farthestIntersection, grid, precision);
88
-
89
- // If the rectPoint lies inside the bbox, offset it by one more step
90
- if (bbox.containsPoint(target)) {
91
- target = (0, _grid.align)(target.translate(direction.x * grid.x, direction.y * grid.y), grid, precision);
92
- }
93
- rectPoints.push(target);
94
- }
95
- }
96
-
97
- // If anchor lies outside of bbox, add it to the array of points
98
- // If anchor is on edge, don't add it - force path to start from extended points
99
- if (!bbox.containsPoint(anchor) && !isOnEdge) {
100
- rectPoints.push((0, _grid.align)(anchor, grid, precision));
101
- }
102
- return rectPoints;
103
- }
@@ -1,19 +0,0 @@
1
- import { Point } from '../geometry';
2
- /**
3
- * Normalize a point to a unit direction vector
4
- */
5
- export declare function normalizePoint(point: Point): Point;
6
- /**
7
- * Get string key for a point
8
- */
9
- export declare function getKey(point: Point): string;
10
- /**
11
- * Calculate minimum Manhattan distance from a point to multiple anchors
12
- */
13
- export declare function getCost(from: Point, anchors: Point[]): number;
14
- /**
15
- * Reconstruct route by concatenating points with their parents
16
- * Removes redundant points in the same direction
17
- */
18
- export declare function reconstructRoute(parents: Map<string, Point>, points: Map<string, Point>, tailPoint: Point, startPoint: Point, endPoint: Point): Point[];
19
- //# sourceMappingURL=route.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/utils/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAKlD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAE3C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,MAAM,CAW7D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,EAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,EAC1B,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,EACjB,QAAQ,EAAE,KAAK,GACd,KAAK,EAAE,CAsCT"}
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getCost = getCost;
7
- exports.getKey = getKey;
8
- exports.normalizePoint = normalizePoint;
9
- exports.reconstructRoute = reconstructRoute;
10
- var _geometry = require("../geometry");
11
- /**
12
- * Normalize a point to a unit direction vector
13
- */
14
- function normalizePoint(point) {
15
- return new _geometry.Point(point.x === 0 ? 0 : Math.abs(point.x) / point.x, point.y === 0 ? 0 : Math.abs(point.y) / point.y);
16
- }
17
-
18
- /**
19
- * Get string key for a point
20
- */
21
- function getKey(point) {
22
- return point.toString();
23
- }
24
-
25
- /**
26
- * Calculate minimum Manhattan distance from a point to multiple anchors
27
- */
28
- function getCost(from, anchors) {
29
- let min = Infinity;
30
- for (const anchor of anchors) {
31
- const dist = from.manhattanDistance(anchor);
32
- if (dist < min) {
33
- min = dist;
34
- }
35
- }
36
- return min;
37
- }
38
-
39
- /**
40
- * Reconstruct route by concatenating points with their parents
41
- * Removes redundant points in the same direction
42
- */
43
- function reconstructRoute(parents, points, tailPoint, startPoint, endPoint) {
44
- const route = [];
45
- let prevDiff = normalizePoint(endPoint.diff(tailPoint));
46
-
47
- // tailPoint is assumed to be aligned already
48
- let currentKey = getKey(tailPoint);
49
- let parent = parents.get(currentKey);
50
- let point;
51
- while (parent) {
52
- // point is assumed to be aligned already
53
- point = points.get(currentKey);
54
- if (point) {
55
- const diff = normalizePoint(point.diff(parent));
56
- if (!diff.equals(prevDiff)) {
57
- route.unshift(point);
58
- prevDiff = diff;
59
- }
60
- }
61
-
62
- // parent is assumed to be aligned already
63
- currentKey = getKey(parent);
64
- parent = parents.get(currentKey);
65
- }
66
-
67
- // leadPoint is assumed to be aligned already
68
- const leadPoint = points.get(currentKey);
69
- if (leadPoint) {
70
- const fromDiff = normalizePoint(leadPoint.diff(startPoint));
71
- if (!fromDiff.equals(prevDiff)) {
72
- route.unshift(leadPoint);
73
- }
74
- }
75
- return route;
76
- }
@@ -1,21 +0,0 @@
1
- import { Point } from './Point';
2
- import { Rectangle } from './Rectangle';
3
- /**
4
- * Line class representing a line segment
5
- */
6
- export declare class Line {
7
- start: Point;
8
- end: Point;
9
- constructor(start: Point, end: Point);
10
- /**
11
- * Calculate intersection points with a rectangle
12
- * Returns an array of intersection points
13
- */
14
- intersect(rect: Rectangle): Point[];
15
- /**
16
- * Calculate intersection point between two line segments
17
- * Returns null if lines don't intersect
18
- */
19
- private lineIntersection;
20
- }
21
- //# sourceMappingURL=Line.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Line.d.ts","sourceRoot":"","sources":["../../src/geometry/Line.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC;;GAEG;AACH,qBAAa,IAAI;IACf,KAAK,EAAE,KAAK,CAAA;IACZ,GAAG,EAAE,KAAK,CAAA;gBAEE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK;IAKpC;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK,EAAE;IA+BnC;;;OAGG;IACH,OAAO,CAAC,gBAAgB;CA+BzB"}
@@ -1,49 +0,0 @@
1
- /**
2
- * Point class representing a 2D coordinate
3
- */
4
- export declare class Point {
5
- x: number;
6
- y: number;
7
- constructor(x: number, y: number);
8
- /**
9
- * Create a copy of this point
10
- */
11
- clone(): Point;
12
- /**
13
- * Check if this point equals another point
14
- */
15
- equals(other: Point): boolean;
16
- /**
17
- * Translate this point by dx and dy
18
- */
19
- translate(dx: number, dy: number): Point;
20
- /**
21
- * Round coordinates to specified precision
22
- */
23
- round(precision: number): Point;
24
- /**
25
- * Calculate Manhattan distance to another point
26
- */
27
- manhattanDistance(other: Point): number;
28
- /**
29
- * Calculate angle (in degrees) from this point to another point
30
- */
31
- theta(other: Point): number;
32
- /**
33
- * Calculate the difference vector from this point to another
34
- */
35
- diff(other: Point): Point;
36
- /**
37
- * Convert point to string representation
38
- */
39
- toString(): string;
40
- /**
41
- * Snap point to grid
42
- */
43
- snapToGrid(gridSize: number): Point;
44
- /**
45
- * Calculate squared distance to another point (for performance)
46
- */
47
- squaredDistance(other: Point): number;
48
- }
49
- //# sourceMappingURL=Point.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Point.d.ts","sourceRoot":"","sources":["../../src/geometry/Point.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,KAAK;IAChB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;gBAEG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAKhC;;OAEG;IACH,KAAK,IAAI,KAAK;IAId;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAI7B;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,KAAK;IAIxC;;OAEG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK;IAQ/B;;OAEG;IACH,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAIvC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAO3B;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;IAIzB;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK;IAOnC;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;CAKtC"}
@@ -1,41 +0,0 @@
1
- import { Point } from './Point';
2
- /**
3
- * Rectangle class representing a bounding box
4
- */
5
- export declare class Rectangle {
6
- x: number;
7
- y: number;
8
- width: number;
9
- height: number;
10
- constructor(x: number, y: number, width: number, height: number);
11
- /**
12
- * Create a copy of this rectangle
13
- */
14
- clone(): Rectangle;
15
- /**
16
- * Get the center point of the rectangle
17
- */
18
- getCenter(): Point;
19
- /**
20
- * Get the origin (top-left) point of the rectangle
21
- */
22
- getOrigin(): Point;
23
- /**
24
- * Get the corner (bottom-right) point of the rectangle
25
- */
26
- getCorner(): Point;
27
- /**
28
- * Check if a point is contained within this rectangle (interior only, excluding edges)
29
- */
30
- containsPoint(point: Point): boolean;
31
- /**
32
- * Move and expand the rectangle by a box offset
33
- */
34
- moveAndExpand(box: {
35
- x: number;
36
- y: number;
37
- width: number;
38
- height: number;
39
- }): Rectangle;
40
- }
41
- //# sourceMappingURL=Rectangle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Rectangle.d.ts","sourceRoot":"","sources":["../../src/geometry/Rectangle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B;;GAEG;AACH,qBAAa,SAAS;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;gBAEF,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAO/D;;OAEG;IACH,KAAK,IAAI,SAAS;IAIlB;;OAEG;IACH,SAAS,IAAI,KAAK;IAOlB;;OAEG;IACH,SAAS,IAAI,KAAK;IAIlB;;OAEG;IACH,SAAS,IAAI,KAAK;IAIlB;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IASpC;;OAEG;IACH,aAAa,CAAC,GAAG,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;CAQvF"}
@@ -1,15 +0,0 @@
1
- import { Point } from './Point';
2
- import { Rectangle } from './Rectangle';
3
- /**
4
- * Check if a line segment intersects with a rectangle
5
- */
6
- export declare function lineSegmentIntersectsRect(p1: Point, p2: Point, rect: Rectangle): boolean;
7
- /**
8
- * Check if a line segment crosses through a rectangle (not just touching edges)
9
- */
10
- export declare function lineSegmentCrossesRect(p1: Point, p2: Point, rect: Rectangle): boolean;
11
- /**
12
- * Check if two line segments intersect
13
- */
14
- export declare function lineSegmentsIntersect(p1: Point, p2: Point, p3: Point, p4: Point): boolean;
15
- //# sourceMappingURL=collision.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collision.d.ts","sourceRoot":"","sources":["../../src/geometry/collision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAwBxF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAsBrF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAgBzF"}
@@ -1,5 +0,0 @@
1
- export { Point } from './Point';
2
- export { Rectangle } from './Rectangle';
3
- export { Line } from './Line';
4
- export { lineSegmentIntersectsRect, lineSegmentCrossesRect, lineSegmentsIntersect } from './collision';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/geometry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA"}
@@ -1,53 +0,0 @@
1
- import { Position } from '@xyflow/react';
2
- import type { ManhattanRouterOptions, NodeLookup } from './options';
3
- /**
4
- * Parameters for getManHattanPath function
5
- */
6
- export interface GetManHattanPathParams {
7
- /**
8
- * Source node ID
9
- */
10
- sourceNodeId: string;
11
- /**
12
- * Target node ID
13
- */
14
- targetNodeId: string;
15
- sourceX: number;
16
- sourceY: number;
17
- targetX: number;
18
- targetY: number;
19
- sourcePosition: Position;
20
- targetPosition: Position;
21
- /**
22
- * ReactFlow node lookup map
23
- */
24
- nodeLookup: NodeLookup;
25
- /**
26
- * Router options
27
- */
28
- options?: ManhattanRouterOptions;
29
- }
30
- /**
31
- * Generate Manhattan-routed path for ReactFlow edges
32
- *
33
- * @param params - Path generation parameters
34
- * @returns SVG path string that can be used with ReactFlow's BaseEdge
35
- *
36
- * @example
37
- * ```typescript
38
- * const path = getManHattanPath({
39
- * sourceNodeId: 'node1',
40
- * targetNodeId: 'node2',
41
- * sourcePosition: { x: 100, y: 100 },
42
- * targetPosition: { x: 300, y: 300 },
43
- * nodeLookup: nodes,
44
- * options: {
45
- * step: 10,
46
- * startDirections: ['bottom'],
47
- * endDirections: ['top']
48
- * }
49
- * })
50
- * ```
51
- */
52
- export declare function getManHattanPath(params: GetManHattanPathParams): string;
53
- //# sourceMappingURL=getManHattanPath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getManHattanPath.d.ts","sourceRoot":"","sources":["../src/getManHattanPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,MAAM,eAAe,CAAA;AAG3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAa,MAAM,WAAW,CAAA;AAM9E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAEhB,cAAc,EAAE,QAAQ,CAAC;IACzB,cAAc,EAAE,QAAQ,CAAC;IACzB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IAEtB;;OAEG;IACH,OAAO,CAAC,EAAE,sBAAsB,CAAA;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAgbvE"}
package/esm/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * ReactFlow Manhattan Router
3
- *
4
- * A Manhattan routing algorithm adapted for ReactFlow from AntV X6.
5
- * Generates orthogonal (right-angle) paths that intelligently avoid obstacles.
6
- *
7
- * @packageDocumentation
8
- */
9
- export { getManHattanPath } from './getManHattanPath';
10
- export type { GetManHattanPathParams } from './getManHattanPath';
11
- export type { Direction, InternalNode, NodeLookup, ManhattanRouterOptions, ResolvedOptions, } from './options';
12
- export { Point, Rectangle, Line } from './geometry';
13
- export { getGrid, align, snapToGrid, getDirectionAngle, getDirectionChange, getRectPoints, getCost, getKey, reconstructRoute, normalizePoint, getNodeDimensions, getNodePosition, } from './utils';
14
- export type { NodeDimensions } from './utils';
15
- export { pointsToPath, snapPathToGrid } from './svg';
16
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAGhE,YAAY,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,sBAAsB,EACtB,eAAe,GAChB,MAAM,WAAW,CAAA;AAGlB,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGnD,OAAO,EACL,OAAO,EACP,KAAK,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,SAAS,CAAA;AAGhB,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAG7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA"}
@@ -1,34 +0,0 @@
1
- import { Point } from '../geometry';
2
- import type { ResolvedOptions, NodeLookup } from '../options';
3
- /**
4
- * ObstacleMap class for managing obstacles in pathfinding
5
- * Uses a grid-based spatial partitioning for efficient queries
6
- */
7
- export declare class ObstacleMap {
8
- private options;
9
- private mapGridSize;
10
- private map;
11
- private sourceAnchor?;
12
- private targetAnchor?;
13
- constructor(options: ResolvedOptions);
14
- /**
15
- * Build obstacle map from node lookup
16
- */
17
- build(nodeLookup: NodeLookup, sourceNodeId: string, targetNodeId: string, sourceAnchor?: Point, targetAnchor?: Point): ObstacleMap;
18
- /**
19
- * Shrink bbox to exclude the area around the anchor point
20
- * This allows paths to start/end at the anchor but prevents crossing the node
21
- */
22
- private shrinkBBoxAroundAnchor;
23
- /**
24
- * Check if a point is accessible (not inside any obstacle)
25
- * Uses binary search optimization: step -> step/2 -> step/4 -> ... -> 1px
26
- */
27
- isAccessible(point: Point, checkRadius?: number): boolean;
28
- /**
29
- * Check accessibility using binary search optimization
30
- * Tries step -> step/2 -> step/4 -> ... -> 1px
31
- */
32
- private isAccessibleWithBinarySearch;
33
- }
34
- //# sourceMappingURL=ObstacleMap.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ObstacleMap.d.ts","sourceRoot":"","sources":["../../src/obstacle/ObstacleMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG7D;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,YAAY,CAAC,CAAO;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAO;gBAEhB,OAAO,EAAE,eAAe;IAMpC;;OAEG;IACH,KAAK,CACH,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,KAAK,EACpB,YAAY,CAAC,EAAE,KAAK,GACnB,WAAW;IAiEd;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA6D9B;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,GAAE,MAAU,GAAG,OAAO;IAiD5D;;;OAGG;IACH,OAAO,CAAC,4BAA4B;CAqCrC"}
@@ -1,2 +0,0 @@
1
- export { ObstacleMap } from './ObstacleMap';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/obstacle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
@@ -1,16 +0,0 @@
1
- import { Point } from '../geometry';
2
- import type { ManhattanRouterOptions } from './types';
3
- /**
4
- * Default configuration for Manhattan router
5
- */
6
- export declare const defaults: Required<Omit<ManhattanRouterOptions, 'fallbackRoute' | 'sourcePosition' | 'targetPosition'>>;
7
- /**
8
- * Direction map - maps direction names to unit vectors
9
- */
10
- export declare const directionMap: {
11
- top: Point;
12
- right: Point;
13
- bottom: Point;
14
- left: Point;
15
- };
16
- //# sourceMappingURL=defaults.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/options/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,EAAE,sBAAsB,EAAa,MAAM,SAAS,CAAA;AAEhE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,sBAAsB,EAAE,eAAe,GAAG,gBAAgB,GAAG,gBAAgB,CAAC,CAkBlH,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;CAKxB,CAAA"}
@@ -1,4 +0,0 @@
1
- export * from './types';
2
- export * from './defaults';
3
- export * from './resolver';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/options/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}