@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,223 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ObstacleMap = void 0;
7
- var _geometry = require("../geometry");
8
- var _utils = require("../utils");
9
- /**
10
- * ObstacleMap class for managing obstacles in pathfinding
11
- * Uses a grid-based spatial partitioning for efficient queries
12
- */
13
- class ObstacleMap {
14
- options;
15
- mapGridSize;
16
- map;
17
- sourceAnchor;
18
- targetAnchor;
19
- constructor(options) {
20
- this.options = options;
21
- this.mapGridSize = 100;
22
- this.map = new Map();
23
- }
24
-
25
- /**
26
- * Build obstacle map from node lookup
27
- */
28
- build(nodeLookup, sourceNodeId, targetNodeId, sourceAnchor, targetAnchor) {
29
- const {
30
- excludeNodes,
31
- excludeShapes,
32
- excludeTerminals,
33
- paddingBox
34
- } = this.options;
35
-
36
- // Store anchors for later use in isAccessible
37
- this.sourceAnchor = sourceAnchor;
38
- this.targetAnchor = targetAnchor;
39
-
40
- // Iterate through all nodes
41
- nodeLookup.forEach(node => {
42
- // Check if node should be excluded
43
- const isExcludedNode = excludeNodes.includes(node.id);
44
- const isExcludedShape = node.type ? excludeShapes.includes(node.type) : false;
45
- const isSourceTerminal = excludeTerminals.includes('source') && node.id === sourceNodeId;
46
- const isTargetTerminal = excludeTerminals.includes('target') && node.id === targetNodeId;
47
- const isSource = node.id === sourceNodeId;
48
- const isTarget = node.id === targetNodeId;
49
-
50
- // Skip if node should be excluded (but not source/target - we handle them specially)
51
- if (isExcludedNode || isExcludedShape || isSourceTerminal || isTargetTerminal) {
52
- return;
53
- }
54
-
55
- // Calculate node bounding box with padding
56
- const position = (0, _utils.getNodePosition)(node);
57
- const dimensions = (0, _utils.getNodeDimensions)(node);
58
- let bbox = new _geometry.Rectangle(position.x, position.y, dimensions.width, dimensions.height).moveAndExpand(paddingBox);
59
-
60
- // For source and target nodes, add them as full obstacles
61
- // We'll handle anchor accessibility in isAccessible() method
62
- if (isSource) {
63
- console.log('[ObstacleMap] Adding source node as obstacle:');
64
- console.log(' Node ID:', node.id);
65
- console.log(' BBox:', `(${bbox.x}, ${bbox.y}, ${bbox.width}, ${bbox.height})`);
66
- console.log(' Anchor:', sourceAnchor ? `(${sourceAnchor.x}, ${sourceAnchor.y})` : 'none');
67
- } else if (isTarget) {
68
- console.log('[ObstacleMap] Adding target node as obstacle:');
69
- console.log(' Node ID:', node.id);
70
- console.log(' BBox:', `(${bbox.x}, ${bbox.y}, ${bbox.width}, ${bbox.height})`);
71
- console.log(' Anchor:', targetAnchor ? `(${targetAnchor.x}, ${targetAnchor.y})` : 'none');
72
- }
73
-
74
- // Map bbox to grid cells
75
- const origin = bbox.getOrigin().snapToGrid(this.mapGridSize);
76
- const corner = bbox.getCorner().snapToGrid(this.mapGridSize);
77
- for (let x = origin.x; x <= corner.x; x += this.mapGridSize) {
78
- for (let y = origin.y; y <= corner.y; y += this.mapGridSize) {
79
- const key = new _geometry.Point(x, y).toString();
80
- if (!this.map.has(key)) {
81
- this.map.set(key, []);
82
- }
83
- this.map.get(key).push(bbox);
84
- }
85
- }
86
- });
87
- return this;
88
- }
89
-
90
- /**
91
- * Shrink bbox to exclude the area around the anchor point
92
- * This allows paths to start/end at the anchor but prevents crossing the node
93
- */
94
- shrinkBBoxAroundAnchor(bbox, anchor, nodePosition, nodeDimensions) {
95
- const tolerance = 1;
96
- const step = this.options.step || 10;
97
- const margin = step * 3; // Increased margin for better clearance
98
-
99
- // Determine which edge the anchor is on (relative to original node position)
100
- const onLeft = Math.abs(anchor.x - nodePosition.x) < tolerance;
101
- const onRight = Math.abs(anchor.x - (nodePosition.x + nodeDimensions.width)) < tolerance;
102
- const onTop = Math.abs(anchor.y - nodePosition.y) < tolerance;
103
- const onBottom = Math.abs(anchor.y - (nodePosition.y + nodeDimensions.height)) < tolerance;
104
- console.log('[shrinkBBoxAroundAnchor] Edge detection:');
105
- console.log(' anchor.x:', anchor.x, 'nodePosition.x:', nodePosition.x, 'diff:', Math.abs(anchor.x - nodePosition.x));
106
- console.log(' anchor.x:', anchor.x, 'nodeRight:', nodePosition.x + nodeDimensions.width, 'diff:', Math.abs(anchor.x - (nodePosition.x + nodeDimensions.width)));
107
- console.log(' onLeft:', onLeft, 'onRight:', onRight, 'onTop:', onTop, 'onBottom:', onBottom);
108
- console.log(' margin:', margin);
109
-
110
- // Shrink bbox based on anchor position
111
- if (onLeft) {
112
- // Anchor on left edge - exclude left portion
113
- return new _geometry.Rectangle(bbox.x + margin, bbox.y, Math.max(0, bbox.width - margin), bbox.height);
114
- } else if (onRight) {
115
- // Anchor on right edge - exclude right portion
116
- return new _geometry.Rectangle(bbox.x, bbox.y, Math.max(0, bbox.width - margin), bbox.height);
117
- } else if (onTop) {
118
- // Anchor on top edge - exclude top portion
119
- return new _geometry.Rectangle(bbox.x, bbox.y + margin, bbox.width, Math.max(0, bbox.height - margin));
120
- } else if (onBottom) {
121
- // Anchor on bottom edge - exclude bottom portion
122
- return new _geometry.Rectangle(bbox.x, bbox.y, bbox.width, Math.max(0, bbox.height - margin));
123
- }
124
-
125
- // If anchor is not on an edge, return original bbox
126
- return bbox;
127
- }
128
-
129
- /**
130
- * Check if a point is accessible (not inside any obstacle)
131
- * Uses binary search optimization: step -> step/2 -> step/4 -> ... -> 1px
132
- */
133
- isAccessible(point, checkRadius = 0) {
134
- const key = point.clone().snapToGrid(this.mapGridSize).toString();
135
- const rects = this.map.get(key);
136
- if (!rects) {
137
- return true;
138
- }
139
-
140
- // Check if point is near an anchor - if so, allow it
141
- const margin = (this.options.step || 10) * 3;
142
- if (this.sourceAnchor) {
143
- const distToSource = Math.abs(point.x - this.sourceAnchor.x) + Math.abs(point.y - this.sourceAnchor.y);
144
- if (distToSource < margin) {
145
- console.log(`[isAccessible] Point (${point.x}, ${point.y}): accessible (near source anchor)`);
146
- return true;
147
- }
148
- }
149
- if (this.targetAnchor) {
150
- const distToTarget = Math.abs(point.x - this.targetAnchor.x) + Math.abs(point.y - this.targetAnchor.y);
151
- if (distToTarget < margin) {
152
- console.log(`[isAccessible] Point (${point.x}, ${point.y}): accessible (near target anchor)`);
153
- return true;
154
- }
155
- }
156
-
157
- // If checkRadius is specified, use binary search to find accessible points
158
- if (checkRadius > 0) {
159
- return this.isAccessibleWithBinarySearch(point, checkRadius, rects);
160
- }
161
- const accessible = rects.every(rect => !rect.containsPoint(point));
162
-
163
- // Debug: log points on the direct path
164
- if (point.y === 40 && point.x >= 0 && point.x <= 545) {
165
- console.log(`[isAccessible] Point (${point.x}, ${point.y}): ${accessible ? 'accessible' : 'BLOCKED'}`);
166
- if (!accessible) {
167
- rects.forEach((rect, i) => {
168
- if (rect.containsPoint(point)) {
169
- console.log(` Blocked by rect ${i}: (${rect.x}, ${rect.y}, ${rect.width}, ${rect.height})`);
170
- }
171
- });
172
- }
173
- }
174
- return accessible;
175
- }
176
-
177
- /**
178
- * Check accessibility using binary search optimization
179
- * Tries step -> step/2 -> step/4 -> ... -> 1px
180
- */
181
- isAccessibleWithBinarySearch(point, maxRadius, rects) {
182
- // First check the point itself
183
- if (rects.every(rect => !rect.containsPoint(point))) {
184
- return true;
185
- }
186
-
187
- // Binary search: start with step, then halve until we reach 1px
188
- let radius = maxRadius;
189
- const offsets = [{
190
- dx: 1,
191
- dy: 0
192
- },
193
- // right
194
- {
195
- dx: -1,
196
- dy: 0
197
- },
198
- // left
199
- {
200
- dx: 0,
201
- dy: 1
202
- },
203
- // down
204
- {
205
- dx: 0,
206
- dy: -1
207
- } // up
208
- ];
209
- while (radius >= 1) {
210
- for (const offset of offsets) {
211
- const testPoint = new _geometry.Point(point.x + offset.dx * radius, point.y + offset.dy * radius);
212
- if (rects.every(rect => !rect.containsPoint(testPoint))) {
213
- return true;
214
- }
215
- }
216
-
217
- // Halve the radius for next iteration
218
- radius = Math.floor(radius / 2);
219
- }
220
- return false;
221
- }
222
- }
223
- exports.ObstacleMap = ObstacleMap;
@@ -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,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "ObstacleMap", {
7
- enumerable: true,
8
- get: function () {
9
- return _ObstacleMap.ObstacleMap;
10
- }
11
- });
12
- var _ObstacleMap = require("./ObstacleMap");
@@ -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,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.directionMap = exports.defaults = void 0;
7
- var _geometry = require("../geometry");
8
- /**
9
- * Default configuration for Manhattan router
10
- */
11
- const defaults = exports.defaults = {
12
- step: 10,
13
- maxLoopCount: 2000,
14
- precision: 1,
15
- maxDirectionChange: 90,
16
- startDirections: ['top', 'right', 'bottom', 'left'],
17
- endDirections: ['top', 'right', 'bottom', 'left'],
18
- excludeNodes: [],
19
- excludeShapes: [],
20
- excludeTerminals: [],
21
- padding: 15,
22
- borderRadius: 5,
23
- extensionDistance: 20,
24
- penalties: {
25
- 0: 0,
26
- 45: 5,
27
- 90: 5
28
- }
29
- };
30
-
31
- /**
32
- * Direction map - maps direction names to unit vectors
33
- */
34
- const directionMap = exports.directionMap = {
35
- top: new _geometry.Point(0, -1),
36
- right: new _geometry.Point(1, 0),
37
- bottom: new _geometry.Point(0, 1),
38
- left: new _geometry.Point(-1, 0)
39
- };
@@ -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"}
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _types = require("./types");
7
- Object.keys(_types).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _types[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _types[key];
14
- }
15
- });
16
- });
17
- var _defaults = require("./defaults");
18
- Object.keys(_defaults).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _defaults[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _defaults[key];
25
- }
26
- });
27
- });
28
- var _resolver = require("./resolver");
29
- Object.keys(_resolver).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _resolver[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _resolver[key];
36
- }
37
- });
38
- });
@@ -1,10 +0,0 @@
1
- import type { ManhattanRouterOptions, ResolvedOptions } from './types';
2
- /**
3
- * Normalize angle to 0-360 range
4
- */
5
- export declare function normalizeAngle(angle: number): number;
6
- /**
7
- * Resolve options by merging user options with defaults
8
- */
9
- export declare function resolveOptions(options?: ManhattanRouterOptions): ResolvedOptions;
10
- //# sourceMappingURL=resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/options/resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAetE;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQpD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,CAiEpF"}
@@ -1,120 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.normalizeAngle = normalizeAngle;
7
- exports.resolveOptions = resolveOptions;
8
- var _geometry = require("../geometry");
9
- var _defaults = require("./defaults");
10
- /**
11
- * Normalize padding value to box format
12
- */
13
- function normalizePadding(padding) {
14
- if (typeof padding === 'number') {
15
- return {
16
- top: padding,
17
- right: padding,
18
- bottom: padding,
19
- left: padding
20
- };
21
- }
22
- return padding;
23
- }
24
-
25
- /**
26
- * Normalize angle to 0-360 range
27
- */
28
- function normalizeAngle(angle) {
29
- while (angle < 0) {
30
- angle += 360;
31
- }
32
- while (angle >= 360) {
33
- angle -= 360;
34
- }
35
- return angle;
36
- }
37
-
38
- /**
39
- * Resolve options by merging user options with defaults
40
- */
41
- function resolveOptions(options = {}) {
42
- const step = options.step ?? _defaults.defaults.step;
43
- const maxLoopCount = options.maxLoopCount ?? _defaults.defaults.maxLoopCount;
44
- const precision = options.precision ?? _defaults.defaults.precision;
45
- const maxDirectionChange = options.maxDirectionChange ?? _defaults.defaults.maxDirectionChange;
46
- const startDirections = options.startDirections ?? _defaults.defaults.startDirections;
47
- const endDirections = options.endDirections ?? _defaults.defaults.endDirections;
48
- const excludeNodes = options.excludeNodes ?? _defaults.defaults.excludeNodes;
49
- const excludeShapes = options.excludeShapes ?? _defaults.defaults.excludeShapes;
50
- const excludeTerminals = options.excludeTerminals ?? _defaults.defaults.excludeTerminals;
51
- const borderRadius = options.borderRadius ?? _defaults.defaults.borderRadius;
52
- const extensionDistance = options.extensionDistance ?? _defaults.defaults.extensionDistance;
53
- const penalties = options.penalties ?? _defaults.defaults.penalties;
54
- const fallbackRoute = options.fallbackRoute;
55
-
56
- // Convert padding to paddingBox
57
- const padding = options.padding ?? _defaults.defaults.padding;
58
- const sides = normalizePadding(padding);
59
- const paddingBox = {
60
- x: -sides.left,
61
- y: -sides.top,
62
- width: sides.left + sides.right,
63
- height: sides.top + sides.bottom
64
- };
65
-
66
- // Calculate cost (same as step)
67
- const cost = step;
68
-
69
- // Calculate directions array with offsets and costs
70
- const directions = [{
71
- cost,
72
- offsetX: step,
73
- offsetY: 0,
74
- angle: 0
75
- }, {
76
- cost,
77
- offsetX: -step,
78
- offsetY: 0,
79
- angle: 0
80
- }, {
81
- cost,
82
- offsetX: 0,
83
- offsetY: step,
84
- angle: 0
85
- }, {
86
- cost,
87
- offsetX: 0,
88
- offsetY: -step,
89
- angle: 0
90
- }];
91
-
92
- // Calculate angle for each direction
93
- directions.forEach(direction => {
94
- const point1 = new _geometry.Point(0, 0);
95
- const point2 = new _geometry.Point(direction.offsetX, direction.offsetY);
96
- direction.angle = normalizeAngle(point1.theta(point2));
97
- });
98
- return {
99
- step,
100
- maxLoopCount,
101
- precision,
102
- maxDirectionChange,
103
- startDirections,
104
- endDirections,
105
- excludeNodes,
106
- excludeShapes,
107
- excludeTerminals,
108
- paddingBox,
109
- borderRadius,
110
- extensionDistance,
111
- sourcePosition: options.sourcePosition,
112
- targetPosition: options.targetPosition,
113
- directionMap: _defaults.directionMap,
114
- directions,
115
- penalties,
116
- cost,
117
- fallbackRoute,
118
- previousDirectionAngle: undefined
119
- };
120
- }
@@ -1,169 +0,0 @@
1
- import { Point } from '../geometry';
2
- /**
3
- * Direction type for routing
4
- */
5
- export type Direction = 'top' | 'right' | 'bottom' | 'left';
6
- /**
7
- * ReactFlow internal node structure
8
- * Based on ReactFlow's InternalNodeBase type
9
- */
10
- export interface InternalNode {
11
- id: string;
12
- position: {
13
- x: number;
14
- y: number;
15
- };
16
- internals: {
17
- positionAbsolute: {
18
- x: number;
19
- y: number;
20
- };
21
- };
22
- measured?: {
23
- width?: number;
24
- height?: number;
25
- };
26
- width?: number;
27
- height?: number;
28
- initialWidth?: number;
29
- initialHeight?: number;
30
- type?: string;
31
- [key: string]: any;
32
- }
33
- /**
34
- * Node lookup map type (ReactFlow's internal structure)
35
- */
36
- export type NodeLookup = Map<string, InternalNode>;
37
- /**
38
- * Manhattan router configuration options
39
- */
40
- export interface ManhattanRouterOptions {
41
- /**
42
- * The size of step to find a route (the grid of the manhattan pathfinder)
43
- * @default 10
44
- */
45
- step?: number;
46
- /**
47
- * The number of route finding loops that cause the router to abort and return fallback route instead
48
- * @default 2000
49
- */
50
- maxLoopCount?: number;
51
- /**
52
- * The number of decimal places to round floating point coordinates
53
- * @default 1
54
- */
55
- precision?: number;
56
- /**
57
- * The maximum change of direction (in degrees)
58
- * @default 90
59
- */
60
- maxDirectionChange?: number;
61
- /**
62
- * Possible starting directions from a node
63
- * @default ['top', 'right', 'bottom', 'left']
64
- */
65
- startDirections?: Direction[];
66
- /**
67
- * Possible ending directions to a node
68
- * @default ['top', 'right', 'bottom', 'left']
69
- */
70
- endDirections?: Direction[];
71
- /**
72
- * Should certain nodes not be considered as obstacles?
73
- */
74
- excludeNodes?: string[];
75
- /**
76
- * Should certain types of nodes not be considered as obstacles?
77
- */
78
- excludeShapes?: string[];
79
- /**
80
- * Should the source and/or target not be considered as obstacles?
81
- */
82
- excludeTerminals?: ('source' | 'target')[];
83
- /**
84
- * The padding applied on the element bounding boxes
85
- */
86
- padding?: number | {
87
- top: number;
88
- right: number;
89
- bottom: number;
90
- left: number;
91
- };
92
- /**
93
- * Border radius for rounded corners at path turns (in pixels)
94
- * Set to 0 for sharp corners
95
- * @default 5
96
- */
97
- borderRadius?: number;
98
- /**
99
- * Extension distance from node edge for path start/end points (in pixels)
100
- * This controls how far the path extends away from the node before turning
101
- * @default 20
102
- */
103
- extensionDistance?: number;
104
- /**
105
- * Source position (from ReactFlow)
106
- * Used for smart point generation
107
- */
108
- sourcePosition?: string;
109
- /**
110
- * Target position (from ReactFlow)
111
- * Used for smart point generation
112
- */
113
- targetPosition?: string;
114
- /**
115
- * A penalty received for direction change
116
- */
117
- penalties?: {
118
- [angle: number]: number;
119
- };
120
- /**
121
- * Fallback route function when pathfinding fails
122
- */
123
- fallbackRoute?: (from: Point, to: Point) => Point[];
124
- }
125
- /**
126
- * Resolved options with all defaults applied
127
- */
128
- export interface ResolvedOptions {
129
- step: number;
130
- maxLoopCount: number;
131
- precision: number;
132
- maxDirectionChange: number;
133
- startDirections: Direction[];
134
- endDirections: Direction[];
135
- excludeNodes: string[];
136
- excludeShapes: string[];
137
- excludeTerminals: ('source' | 'target')[];
138
- paddingBox: {
139
- x: number;
140
- y: number;
141
- width: number;
142
- height: number;
143
- };
144
- borderRadius: number;
145
- extensionDistance: number;
146
- sourcePosition?: string;
147
- targetPosition?: string;
148
- directionMap: {
149
- top: Point;
150
- right: Point;
151
- bottom: Point;
152
- left: Point;
153
- };
154
- directions: Array<{
155
- cost: number;
156
- offsetX: number;
157
- offsetY: number;
158
- angle?: number;
159
- gridOffsetX?: number;
160
- gridOffsetY?: number;
161
- }>;
162
- penalties: {
163
- [angle: number]: number;
164
- };
165
- cost: number;
166
- fallbackRoute?: (from: Point, to: Point) => Point[];
167
- previousDirectionAngle?: number | null;
168
- }
169
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/options/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAClC,SAAS,EAAE;QACT,gBAAgB,EAAE;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAC3C,CAAA;IACD,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;AAElD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;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