@rxflow/manhattan 0.0.1-alpha.0

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 (140) hide show
  1. package/README.md +35 -0
  2. package/cjs/geometry/Line.d.ts +21 -0
  3. package/cjs/geometry/Line.d.ts.map +1 -0
  4. package/cjs/geometry/Line.js +88 -0
  5. package/cjs/geometry/Point.d.ts +49 -0
  6. package/cjs/geometry/Point.d.ts.map +1 -0
  7. package/cjs/geometry/Point.js +94 -0
  8. package/cjs/geometry/Rectangle.d.ts +41 -0
  9. package/cjs/geometry/Rectangle.d.ts.map +1 -0
  10. package/cjs/geometry/Rectangle.js +65 -0
  11. package/cjs/geometry/index.d.ts +4 -0
  12. package/cjs/geometry/index.d.ts.map +1 -0
  13. package/cjs/geometry/index.js +26 -0
  14. package/cjs/getManHattanPath.d.ts +60 -0
  15. package/cjs/getManHattanPath.d.ts.map +1 -0
  16. package/cjs/getManHattanPath.js +285 -0
  17. package/cjs/index.d.ts +16 -0
  18. package/cjs/index.d.ts.map +1 -0
  19. package/cjs/index.js +117 -0
  20. package/cjs/obstacle/ObstacleMap.d.ts +28 -0
  21. package/cjs/obstacle/ObstacleMap.d.ts.map +1 -0
  22. package/cjs/obstacle/ObstacleMap.js +171 -0
  23. package/cjs/obstacle/index.d.ts +2 -0
  24. package/cjs/obstacle/index.d.ts.map +1 -0
  25. package/cjs/obstacle/index.js +12 -0
  26. package/cjs/options/defaults.d.ts +16 -0
  27. package/cjs/options/defaults.d.ts.map +1 -0
  28. package/cjs/options/defaults.js +39 -0
  29. package/cjs/options/index.d.ts +4 -0
  30. package/cjs/options/index.d.ts.map +1 -0
  31. package/cjs/options/index.js +38 -0
  32. package/cjs/options/resolver.d.ts +10 -0
  33. package/cjs/options/resolver.d.ts.map +1 -0
  34. package/cjs/options/resolver.js +118 -0
  35. package/cjs/options/types.d.ts +156 -0
  36. package/cjs/options/types.d.ts.map +1 -0
  37. package/cjs/options/types.js +5 -0
  38. package/cjs/pathfinder/SortedSet.d.ts +35 -0
  39. package/cjs/pathfinder/SortedSet.d.ts.map +1 -0
  40. package/cjs/pathfinder/SortedSet.js +95 -0
  41. package/cjs/pathfinder/findRoute.d.ts +8 -0
  42. package/cjs/pathfinder/findRoute.d.ts.map +1 -0
  43. package/cjs/pathfinder/findRoute.js +156 -0
  44. package/cjs/pathfinder/index.d.ts +3 -0
  45. package/cjs/pathfinder/index.d.ts.map +1 -0
  46. package/cjs/pathfinder/index.js +19 -0
  47. package/cjs/svg/index.d.ts +2 -0
  48. package/cjs/svg/index.d.ts.map +1 -0
  49. package/cjs/svg/index.js +18 -0
  50. package/cjs/svg/pathConverter.d.ts +10 -0
  51. package/cjs/svg/pathConverter.d.ts.map +1 -0
  52. package/cjs/svg/pathConverter.js +105 -0
  53. package/cjs/utils/direction.d.ts +24 -0
  54. package/cjs/utils/direction.d.ts.map +1 -0
  55. package/cjs/utils/direction.js +54 -0
  56. package/cjs/utils/grid.d.ts +26 -0
  57. package/cjs/utils/grid.d.ts.map +1 -0
  58. package/cjs/utils/grid.js +78 -0
  59. package/cjs/utils/index.d.ts +6 -0
  60. package/cjs/utils/index.d.ts.map +1 -0
  61. package/cjs/utils/index.js +60 -0
  62. package/cjs/utils/node.d.ts +27 -0
  63. package/cjs/utils/node.d.ts.map +1 -0
  64. package/cjs/utils/node.js +36 -0
  65. package/cjs/utils/rect.d.ts +9 -0
  66. package/cjs/utils/rect.d.ts.map +1 -0
  67. package/cjs/utils/rect.js +103 -0
  68. package/cjs/utils/route.d.ts +19 -0
  69. package/cjs/utils/route.d.ts.map +1 -0
  70. package/cjs/utils/route.js +76 -0
  71. package/esm/geometry/Line.d.ts +21 -0
  72. package/esm/geometry/Line.d.ts.map +1 -0
  73. package/esm/geometry/Line.js +96 -0
  74. package/esm/geometry/Point.d.ts +49 -0
  75. package/esm/geometry/Point.d.ts.map +1 -0
  76. package/esm/geometry/Point.js +117 -0
  77. package/esm/geometry/Rectangle.d.ts +41 -0
  78. package/esm/geometry/Rectangle.d.ts.map +1 -0
  79. package/esm/geometry/Rectangle.js +81 -0
  80. package/esm/geometry/index.d.ts +4 -0
  81. package/esm/geometry/index.d.ts.map +1 -0
  82. package/esm/geometry/index.js +3 -0
  83. package/esm/getManHattanPath.d.ts +60 -0
  84. package/esm/getManHattanPath.d.ts.map +1 -0
  85. package/esm/getManHattanPath.js +291 -0
  86. package/esm/index.d.ts +16 -0
  87. package/esm/index.d.ts.map +1 -0
  88. package/esm/index.js +24 -0
  89. package/esm/obstacle/ObstacleMap.d.ts +28 -0
  90. package/esm/obstacle/ObstacleMap.d.ts.map +1 -0
  91. package/esm/obstacle/ObstacleMap.js +183 -0
  92. package/esm/obstacle/index.d.ts +2 -0
  93. package/esm/obstacle/index.d.ts.map +1 -0
  94. package/esm/obstacle/index.js +1 -0
  95. package/esm/options/defaults.d.ts +16 -0
  96. package/esm/options/defaults.d.ts.map +1 -0
  97. package/esm/options/defaults.js +33 -0
  98. package/esm/options/index.d.ts +4 -0
  99. package/esm/options/index.d.ts.map +1 -0
  100. package/esm/options/index.js +3 -0
  101. package/esm/options/resolver.d.ts +10 -0
  102. package/esm/options/resolver.d.ts.map +1 -0
  103. package/esm/options/resolver.js +114 -0
  104. package/esm/options/types.d.ts +156 -0
  105. package/esm/options/types.d.ts.map +1 -0
  106. package/esm/options/types.js +1 -0
  107. package/esm/pathfinder/SortedSet.d.ts +35 -0
  108. package/esm/pathfinder/SortedSet.d.ts.map +1 -0
  109. package/esm/pathfinder/SortedSet.js +110 -0
  110. package/esm/pathfinder/findRoute.d.ts +8 -0
  111. package/esm/pathfinder/findRoute.d.ts.map +1 -0
  112. package/esm/pathfinder/findRoute.js +189 -0
  113. package/esm/pathfinder/index.d.ts +3 -0
  114. package/esm/pathfinder/index.d.ts.map +1 -0
  115. package/esm/pathfinder/index.js +2 -0
  116. package/esm/svg/index.d.ts +2 -0
  117. package/esm/svg/index.d.ts.map +1 -0
  118. package/esm/svg/index.js +1 -0
  119. package/esm/svg/pathConverter.d.ts +10 -0
  120. package/esm/svg/pathConverter.d.ts.map +1 -0
  121. package/esm/svg/pathConverter.js +107 -0
  122. package/esm/utils/direction.d.ts +24 -0
  123. package/esm/utils/direction.d.ts.map +1 -0
  124. package/esm/utils/direction.js +46 -0
  125. package/esm/utils/grid.d.ts +26 -0
  126. package/esm/utils/grid.d.ts.map +1 -0
  127. package/esm/utils/grid.js +70 -0
  128. package/esm/utils/index.d.ts +6 -0
  129. package/esm/utils/index.d.ts.map +1 -0
  130. package/esm/utils/index.js +5 -0
  131. package/esm/utils/node.d.ts +27 -0
  132. package/esm/utils/node.d.ts.map +1 -0
  133. package/esm/utils/node.js +30 -0
  134. package/esm/utils/rect.d.ts +9 -0
  135. package/esm/utils/rect.d.ts.map +1 -0
  136. package/esm/utils/rect.js +121 -0
  137. package/esm/utils/route.d.ts +19 -0
  138. package/esm/utils/route.d.ts.map +1 -0
  139. package/esm/utils/route.js +80 -0
  140. package/package.json +43 -0
@@ -0,0 +1,121 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
+ import { Point, Line } from "../geometry";
5
+ import { align } from "./grid";
6
+
7
+ /**
8
+ * Check if a point is on the edge of a rectangle
9
+ */
10
+ function isPointOnRectangleEdge(point, bbox) {
11
+ var tolerance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.01;
12
+ var onLeft = Math.abs(point.x - bbox.x) < tolerance;
13
+ var onRight = Math.abs(point.x - (bbox.x + bbox.width)) < tolerance;
14
+ var onTop = Math.abs(point.y - bbox.y) < tolerance;
15
+ var onBottom = Math.abs(point.y - (bbox.y + bbox.height)) < tolerance;
16
+ var withinVerticalBounds = point.y >= bbox.y - tolerance && point.y <= bbox.y + bbox.height + tolerance;
17
+ var withinHorizontalBounds = point.x >= bbox.x - tolerance && point.x <= bbox.x + bbox.width + tolerance;
18
+ return (onLeft || onRight) && withinVerticalBounds || (onTop || onBottom) && withinHorizontalBounds;
19
+ }
20
+
21
+ /**
22
+ * Check if a direction points outward from the rectangle edge where the anchor is located
23
+ */
24
+ function isDirectionOutward(anchor, bbox, direction) {
25
+ var tolerance = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.01;
26
+ var onLeft = Math.abs(anchor.x - bbox.x) < tolerance;
27
+ var onRight = Math.abs(anchor.x - (bbox.x + bbox.width)) < tolerance;
28
+ var onTop = Math.abs(anchor.y - bbox.y) < tolerance;
29
+ var 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
+ export function getRectPoints(anchor, bbox, directionList, grid, options) {
48
+ var precision = options.precision;
49
+ var directionMap = options.directionMap;
50
+ var centerVector = anchor.diff(bbox.getCenter());
51
+ var rectPoints = [];
52
+
53
+ // Check if anchor is on the edge of the bbox
54
+ var isOnEdge = isPointOnRectangleEdge(anchor, bbox);
55
+
56
+ // Check each allowed direction
57
+ var _iterator = _createForOfIteratorHelper(directionList),
58
+ _step;
59
+ try {
60
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
61
+ var key = _step.value;
62
+ var direction = directionMap[key];
63
+
64
+ // If anchor is on edge, only consider outward directions
65
+ if (isOnEdge) {
66
+ var isOutward = isDirectionOutward(anchor, bbox, direction);
67
+ if (!isOutward) {
68
+ continue; // Skip inward directions
69
+ }
70
+ }
71
+
72
+ // Create a line that is guaranteed to intersect the bbox if bbox
73
+ // is in the direction even if anchor lies outside of bbox
74
+ var ending = new Point(anchor.x + direction.x * (Math.abs(centerVector.x) + bbox.width), anchor.y + direction.y * (Math.abs(centerVector.y) + bbox.height));
75
+ var intersectionLine = new Line(anchor, ending);
76
+
77
+ // Get the farther intersection, in case there are two
78
+ var intersections = intersectionLine.intersect(bbox);
79
+ var farthestIntersectionDistance = void 0;
80
+ var farthestIntersection = null;
81
+ var _iterator2 = _createForOfIteratorHelper(intersections),
82
+ _step2;
83
+ try {
84
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
85
+ var intersection = _step2.value;
86
+ var distance = anchor.squaredDistance(intersection);
87
+ if (farthestIntersectionDistance === undefined || distance > farthestIntersectionDistance) {
88
+ farthestIntersectionDistance = distance;
89
+ farthestIntersection = intersection;
90
+ }
91
+ }
92
+
93
+ // If an intersection was found in this direction, it is our rectPoint
94
+ } catch (err) {
95
+ _iterator2.e(err);
96
+ } finally {
97
+ _iterator2.f();
98
+ }
99
+ if (farthestIntersection) {
100
+ var target = align(farthestIntersection, grid, precision);
101
+
102
+ // If the rectPoint lies inside the bbox, offset it by one more step
103
+ if (bbox.containsPoint(target)) {
104
+ target = align(target.translate(direction.x * grid.x, direction.y * grid.y), grid, precision);
105
+ }
106
+ rectPoints.push(target);
107
+ }
108
+ }
109
+
110
+ // If anchor lies outside of bbox, add it to the array of points
111
+ // If anchor is on edge, don't add it - force path to start from extended points
112
+ } catch (err) {
113
+ _iterator.e(err);
114
+ } finally {
115
+ _iterator.f();
116
+ }
117
+ if (!bbox.containsPoint(anchor) && !isOnEdge) {
118
+ rectPoints.push(align(anchor, grid, precision));
119
+ }
120
+ return rectPoints;
121
+ }
@@ -0,0 +1,19 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,80 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
+ import { Point } from "../geometry";
5
+
6
+ /**
7
+ * Normalize a point to a unit direction vector
8
+ */
9
+ export function normalizePoint(point) {
10
+ return new Point(point.x === 0 ? 0 : Math.abs(point.x) / point.x, point.y === 0 ? 0 : Math.abs(point.y) / point.y);
11
+ }
12
+
13
+ /**
14
+ * Get string key for a point
15
+ */
16
+ export function getKey(point) {
17
+ return point.toString();
18
+ }
19
+
20
+ /**
21
+ * Calculate minimum Manhattan distance from a point to multiple anchors
22
+ */
23
+ export function getCost(from, anchors) {
24
+ var min = Infinity;
25
+ var _iterator = _createForOfIteratorHelper(anchors),
26
+ _step;
27
+ try {
28
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
29
+ var anchor = _step.value;
30
+ var dist = from.manhattanDistance(anchor);
31
+ if (dist < min) {
32
+ min = dist;
33
+ }
34
+ }
35
+ } catch (err) {
36
+ _iterator.e(err);
37
+ } finally {
38
+ _iterator.f();
39
+ }
40
+ return min;
41
+ }
42
+
43
+ /**
44
+ * Reconstruct route by concatenating points with their parents
45
+ * Removes redundant points in the same direction
46
+ */
47
+ export function reconstructRoute(parents, points, tailPoint, startPoint, endPoint) {
48
+ var route = [];
49
+ var prevDiff = normalizePoint(endPoint.diff(tailPoint));
50
+
51
+ // tailPoint is assumed to be aligned already
52
+ var currentKey = getKey(tailPoint);
53
+ var parent = parents.get(currentKey);
54
+ var point;
55
+ while (parent) {
56
+ // point is assumed to be aligned already
57
+ point = points.get(currentKey);
58
+ if (point) {
59
+ var diff = normalizePoint(point.diff(parent));
60
+ if (!diff.equals(prevDiff)) {
61
+ route.unshift(point);
62
+ prevDiff = diff;
63
+ }
64
+ }
65
+
66
+ // parent is assumed to be aligned already
67
+ currentKey = getKey(parent);
68
+ parent = parents.get(currentKey);
69
+ }
70
+
71
+ // leadPoint is assumed to be aligned already
72
+ var leadPoint = points.get(currentKey);
73
+ if (leadPoint) {
74
+ var fromDiff = normalizePoint(leadPoint.diff(startPoint));
75
+ if (!fromDiff.equals(prevDiff)) {
76
+ route.unshift(leadPoint);
77
+ }
78
+ }
79
+ return route;
80
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@rxflow/manhattan",
3
+ "version": "0.0.1-alpha.0",
4
+ "description": "Manhattan routing algorithm for ReactFlow - generates orthogonal paths with obstacle avoidance",
5
+ "keywords": [
6
+ "reactflow",
7
+ "manhattan",
8
+ "router",
9
+ "pathfinding",
10
+ "a-star",
11
+ "orthogonal",
12
+ "edge-routing"
13
+ ],
14
+ "homepage": "https://tree-graph.publib.cn/",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git@gitlab.caijj.net:yanfaerbu/qianduan/tree-graph.git"
18
+ },
19
+ "license": "MIT",
20
+ "author": "yanxianliang@outlook.com",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "types": "./esm/index.d.ts",
25
+ "import": "./esm/index.js",
26
+ "require": "./cjs/index.js"
27
+ }
28
+ },
29
+ "main": "./cjs/index.js",
30
+ "module": "./esm/index.js",
31
+ "types": "./esm/index.d.ts",
32
+ "files": [
33
+ "esm",
34
+ "cjs"
35
+ ],
36
+ "scripts": {
37
+ "build": "father build"
38
+ },
39
+ "peerDependencies": {
40
+ "@xyflow/react": ">=12.8.6"
41
+ },
42
+ "gitHead": "dcdc06b5032aac044fa2094877d28c509c30d9eb"
43
+ }