microboard-temp 0.5.77 → 0.5.79
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.
- package/dist/cjs/browser.js +35 -42
- package/dist/cjs/index.js +35 -42
- package/dist/cjs/node.js +35 -42
- package/dist/esm/browser.js +35 -42
- package/dist/esm/index.js +35 -42
- package/dist/esm/node.js +35 -42
- package/package.json +1 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -36727,38 +36727,6 @@ function getNeighbors(node2, grid, obstacles) {
|
|
|
36727
36727
|
}
|
|
36728
36728
|
return neighbors;
|
|
36729
36729
|
}
|
|
36730
|
-
function findCenterLine(grid, start, end, middle) {
|
|
36731
|
-
const centerLine = [];
|
|
36732
|
-
const middlePoint = middle ? middle : new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
36733
|
-
const min2 = new Point(Math.min(start.x, end.x), Math.min(start.y, end.y));
|
|
36734
|
-
const max2 = new Point(Math.max(start.x, end.x), Math.max(start.y, end.y));
|
|
36735
|
-
const width = max2.x - min2.x;
|
|
36736
|
-
const height = max2.y - min2.y;
|
|
36737
|
-
if (start.pointType !== "Board" && end.pointType !== "Board") {
|
|
36738
|
-
const isInGrid = grid.some((row2) => row2.some((point5) => point5.barelyEqual(middlePoint)));
|
|
36739
|
-
return isInGrid ? [middlePoint] : [];
|
|
36740
|
-
}
|
|
36741
|
-
if (width > height) {
|
|
36742
|
-
const centerIdx = grid.findIndex((row2) => row2[0].x === middlePoint.x || Math.abs(row2[0].x - middlePoint.x) < 0.01);
|
|
36743
|
-
if (centerIdx !== -1) {
|
|
36744
|
-
for (let y = 0;y < grid[0].length; y++) {
|
|
36745
|
-
if (grid[centerIdx][y] && grid[centerIdx][y].x >= min2.x - 0.01 && grid[centerIdx][y].x <= max2.x + 0.01 && grid[centerIdx][y].y >= min2.y - 0.01 && grid[centerIdx][y].y <= max2.y + 0.01) {
|
|
36746
|
-
centerLine.push(grid[centerIdx][y]);
|
|
36747
|
-
}
|
|
36748
|
-
}
|
|
36749
|
-
}
|
|
36750
|
-
} else {
|
|
36751
|
-
const centerIdx = grid[0].findIndex((point5) => point5.y === middlePoint.y || Math.abs(point5.y - middlePoint.y) < 0.01);
|
|
36752
|
-
if (centerIdx !== -1) {
|
|
36753
|
-
for (let x = 0;x < grid.length; x++) {
|
|
36754
|
-
if (grid[x][centerIdx] && grid[x][centerIdx].x >= min2.x - 0.01 && grid[x][centerIdx].x <= max2.x + 0.01 && grid[x][centerIdx].y >= min2.y - 0.01 && grid[x][centerIdx].y <= max2.y + 0.01) {
|
|
36755
|
-
centerLine.push(grid[x][centerIdx]);
|
|
36756
|
-
}
|
|
36757
|
-
}
|
|
36758
|
-
}
|
|
36759
|
-
}
|
|
36760
|
-
return centerLine;
|
|
36761
|
-
}
|
|
36762
36730
|
function createGrid(start, end, toVisitPoints = []) {
|
|
36763
36731
|
const startDir = getPointerDirection(start);
|
|
36764
36732
|
const endDir = getPointerDirection(end);
|
|
@@ -36966,17 +36934,42 @@ function reconstructPath(node2) {
|
|
|
36966
36934
|
}
|
|
36967
36935
|
return path2.reverse();
|
|
36968
36936
|
}
|
|
36937
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36938
|
+
const hookPoints = [];
|
|
36939
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36940
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36941
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
36942
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
36943
|
+
return hookPoints;
|
|
36944
|
+
}
|
|
36945
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36946
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36947
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
36948
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
36949
|
+
return hookPoints;
|
|
36950
|
+
}
|
|
36951
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36952
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36953
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
36954
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
36955
|
+
return hookPoints;
|
|
36956
|
+
}
|
|
36957
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36958
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36959
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
36960
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
36961
|
+
return hookPoints;
|
|
36962
|
+
}
|
|
36963
|
+
return hookPoints;
|
|
36964
|
+
}
|
|
36969
36965
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36970
|
-
const { grid, newStart, newEnd
|
|
36971
|
-
const startPoint = newStart
|
|
36972
|
-
const endPoint = newEnd
|
|
36973
|
-
const
|
|
36974
|
-
const
|
|
36975
|
-
const
|
|
36976
|
-
|
|
36977
|
-
...toVisitPoints.length > 0 ? toVisitPoints : adjustedCenterLine,
|
|
36978
|
-
endPoint
|
|
36979
|
-
];
|
|
36966
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36967
|
+
const startPoint = newStart || start;
|
|
36968
|
+
const endPoint = newEnd || end;
|
|
36969
|
+
const startDir = getPointerDirection(start);
|
|
36970
|
+
const endDir = getPointerDirection(end);
|
|
36971
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36972
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
36980
36973
|
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
36981
36974
|
return {
|
|
36982
36975
|
lines: getLines(pathPoints),
|
package/dist/cjs/index.js
CHANGED
|
@@ -36727,38 +36727,6 @@ function getNeighbors(node2, grid, obstacles) {
|
|
|
36727
36727
|
}
|
|
36728
36728
|
return neighbors;
|
|
36729
36729
|
}
|
|
36730
|
-
function findCenterLine(grid, start, end, middle) {
|
|
36731
|
-
const centerLine = [];
|
|
36732
|
-
const middlePoint = middle ? middle : new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
36733
|
-
const min2 = new Point(Math.min(start.x, end.x), Math.min(start.y, end.y));
|
|
36734
|
-
const max2 = new Point(Math.max(start.x, end.x), Math.max(start.y, end.y));
|
|
36735
|
-
const width = max2.x - min2.x;
|
|
36736
|
-
const height = max2.y - min2.y;
|
|
36737
|
-
if (start.pointType !== "Board" && end.pointType !== "Board") {
|
|
36738
|
-
const isInGrid = grid.some((row2) => row2.some((point5) => point5.barelyEqual(middlePoint)));
|
|
36739
|
-
return isInGrid ? [middlePoint] : [];
|
|
36740
|
-
}
|
|
36741
|
-
if (width > height) {
|
|
36742
|
-
const centerIdx = grid.findIndex((row2) => row2[0].x === middlePoint.x || Math.abs(row2[0].x - middlePoint.x) < 0.01);
|
|
36743
|
-
if (centerIdx !== -1) {
|
|
36744
|
-
for (let y = 0;y < grid[0].length; y++) {
|
|
36745
|
-
if (grid[centerIdx][y] && grid[centerIdx][y].x >= min2.x - 0.01 && grid[centerIdx][y].x <= max2.x + 0.01 && grid[centerIdx][y].y >= min2.y - 0.01 && grid[centerIdx][y].y <= max2.y + 0.01) {
|
|
36746
|
-
centerLine.push(grid[centerIdx][y]);
|
|
36747
|
-
}
|
|
36748
|
-
}
|
|
36749
|
-
}
|
|
36750
|
-
} else {
|
|
36751
|
-
const centerIdx = grid[0].findIndex((point5) => point5.y === middlePoint.y || Math.abs(point5.y - middlePoint.y) < 0.01);
|
|
36752
|
-
if (centerIdx !== -1) {
|
|
36753
|
-
for (let x = 0;x < grid.length; x++) {
|
|
36754
|
-
if (grid[x][centerIdx] && grid[x][centerIdx].x >= min2.x - 0.01 && grid[x][centerIdx].x <= max2.x + 0.01 && grid[x][centerIdx].y >= min2.y - 0.01 && grid[x][centerIdx].y <= max2.y + 0.01) {
|
|
36755
|
-
centerLine.push(grid[x][centerIdx]);
|
|
36756
|
-
}
|
|
36757
|
-
}
|
|
36758
|
-
}
|
|
36759
|
-
}
|
|
36760
|
-
return centerLine;
|
|
36761
|
-
}
|
|
36762
36730
|
function createGrid(start, end, toVisitPoints = []) {
|
|
36763
36731
|
const startDir = getPointerDirection(start);
|
|
36764
36732
|
const endDir = getPointerDirection(end);
|
|
@@ -36966,17 +36934,42 @@ function reconstructPath(node2) {
|
|
|
36966
36934
|
}
|
|
36967
36935
|
return path2.reverse();
|
|
36968
36936
|
}
|
|
36937
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36938
|
+
const hookPoints = [];
|
|
36939
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36940
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36941
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
36942
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
36943
|
+
return hookPoints;
|
|
36944
|
+
}
|
|
36945
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36946
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36947
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
36948
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
36949
|
+
return hookPoints;
|
|
36950
|
+
}
|
|
36951
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36952
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36953
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
36954
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
36955
|
+
return hookPoints;
|
|
36956
|
+
}
|
|
36957
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36958
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36959
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
36960
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
36961
|
+
return hookPoints;
|
|
36962
|
+
}
|
|
36963
|
+
return hookPoints;
|
|
36964
|
+
}
|
|
36969
36965
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36970
|
-
const { grid, newStart, newEnd
|
|
36971
|
-
const startPoint = newStart
|
|
36972
|
-
const endPoint = newEnd
|
|
36973
|
-
const
|
|
36974
|
-
const
|
|
36975
|
-
const
|
|
36976
|
-
|
|
36977
|
-
...toVisitPoints.length > 0 ? toVisitPoints : adjustedCenterLine,
|
|
36978
|
-
endPoint
|
|
36979
|
-
];
|
|
36966
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36967
|
+
const startPoint = newStart || start;
|
|
36968
|
+
const endPoint = newEnd || end;
|
|
36969
|
+
const startDir = getPointerDirection(start);
|
|
36970
|
+
const endDir = getPointerDirection(end);
|
|
36971
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36972
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
36980
36973
|
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
36981
36974
|
return {
|
|
36982
36975
|
lines: getLines(pathPoints),
|
package/dist/cjs/node.js
CHANGED
|
@@ -39200,38 +39200,6 @@ function getNeighbors(node2, grid, obstacles) {
|
|
|
39200
39200
|
}
|
|
39201
39201
|
return neighbors;
|
|
39202
39202
|
}
|
|
39203
|
-
function findCenterLine(grid, start, end, middle) {
|
|
39204
|
-
const centerLine = [];
|
|
39205
|
-
const middlePoint = middle ? middle : new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
39206
|
-
const min2 = new Point(Math.min(start.x, end.x), Math.min(start.y, end.y));
|
|
39207
|
-
const max2 = new Point(Math.max(start.x, end.x), Math.max(start.y, end.y));
|
|
39208
|
-
const width = max2.x - min2.x;
|
|
39209
|
-
const height = max2.y - min2.y;
|
|
39210
|
-
if (start.pointType !== "Board" && end.pointType !== "Board") {
|
|
39211
|
-
const isInGrid = grid.some((row2) => row2.some((point5) => point5.barelyEqual(middlePoint)));
|
|
39212
|
-
return isInGrid ? [middlePoint] : [];
|
|
39213
|
-
}
|
|
39214
|
-
if (width > height) {
|
|
39215
|
-
const centerIdx = grid.findIndex((row2) => row2[0].x === middlePoint.x || Math.abs(row2[0].x - middlePoint.x) < 0.01);
|
|
39216
|
-
if (centerIdx !== -1) {
|
|
39217
|
-
for (let y = 0;y < grid[0].length; y++) {
|
|
39218
|
-
if (grid[centerIdx][y] && grid[centerIdx][y].x >= min2.x - 0.01 && grid[centerIdx][y].x <= max2.x + 0.01 && grid[centerIdx][y].y >= min2.y - 0.01 && grid[centerIdx][y].y <= max2.y + 0.01) {
|
|
39219
|
-
centerLine.push(grid[centerIdx][y]);
|
|
39220
|
-
}
|
|
39221
|
-
}
|
|
39222
|
-
}
|
|
39223
|
-
} else {
|
|
39224
|
-
const centerIdx = grid[0].findIndex((point5) => point5.y === middlePoint.y || Math.abs(point5.y - middlePoint.y) < 0.01);
|
|
39225
|
-
if (centerIdx !== -1) {
|
|
39226
|
-
for (let x = 0;x < grid.length; x++) {
|
|
39227
|
-
if (grid[x][centerIdx] && grid[x][centerIdx].x >= min2.x - 0.01 && grid[x][centerIdx].x <= max2.x + 0.01 && grid[x][centerIdx].y >= min2.y - 0.01 && grid[x][centerIdx].y <= max2.y + 0.01) {
|
|
39228
|
-
centerLine.push(grid[x][centerIdx]);
|
|
39229
|
-
}
|
|
39230
|
-
}
|
|
39231
|
-
}
|
|
39232
|
-
}
|
|
39233
|
-
return centerLine;
|
|
39234
|
-
}
|
|
39235
39203
|
function createGrid(start, end, toVisitPoints = []) {
|
|
39236
39204
|
const startDir = getPointerDirection(start);
|
|
39237
39205
|
const endDir = getPointerDirection(end);
|
|
@@ -39439,17 +39407,42 @@ function reconstructPath(node2) {
|
|
|
39439
39407
|
}
|
|
39440
39408
|
return path2.reverse();
|
|
39441
39409
|
}
|
|
39410
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
39411
|
+
const hookPoints = [];
|
|
39412
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
39413
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39414
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
39415
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
39416
|
+
return hookPoints;
|
|
39417
|
+
}
|
|
39418
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
39419
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39420
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
39421
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
39422
|
+
return hookPoints;
|
|
39423
|
+
}
|
|
39424
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
39425
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39426
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
39427
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
39428
|
+
return hookPoints;
|
|
39429
|
+
}
|
|
39430
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
39431
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39432
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
39433
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
39434
|
+
return hookPoints;
|
|
39435
|
+
}
|
|
39436
|
+
return hookPoints;
|
|
39437
|
+
}
|
|
39442
39438
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
39443
|
-
const { grid, newStart, newEnd
|
|
39444
|
-
const startPoint = newStart
|
|
39445
|
-
const endPoint = newEnd
|
|
39446
|
-
const
|
|
39447
|
-
const
|
|
39448
|
-
const
|
|
39449
|
-
|
|
39450
|
-
...toVisitPoints.length > 0 ? toVisitPoints : adjustedCenterLine,
|
|
39451
|
-
endPoint
|
|
39452
|
-
];
|
|
39439
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
39440
|
+
const startPoint = newStart || start;
|
|
39441
|
+
const endPoint = newEnd || end;
|
|
39442
|
+
const startDir = getPointerDirection(start);
|
|
39443
|
+
const endDir = getPointerDirection(end);
|
|
39444
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
39445
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
39453
39446
|
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
39454
39447
|
return {
|
|
39455
39448
|
lines: getLines(pathPoints),
|
package/dist/esm/browser.js
CHANGED
|
@@ -36572,38 +36572,6 @@ function getNeighbors(node2, grid, obstacles) {
|
|
|
36572
36572
|
}
|
|
36573
36573
|
return neighbors;
|
|
36574
36574
|
}
|
|
36575
|
-
function findCenterLine(grid, start, end, middle) {
|
|
36576
|
-
const centerLine = [];
|
|
36577
|
-
const middlePoint = middle ? middle : new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
36578
|
-
const min2 = new Point(Math.min(start.x, end.x), Math.min(start.y, end.y));
|
|
36579
|
-
const max2 = new Point(Math.max(start.x, end.x), Math.max(start.y, end.y));
|
|
36580
|
-
const width = max2.x - min2.x;
|
|
36581
|
-
const height = max2.y - min2.y;
|
|
36582
|
-
if (start.pointType !== "Board" && end.pointType !== "Board") {
|
|
36583
|
-
const isInGrid = grid.some((row2) => row2.some((point5) => point5.barelyEqual(middlePoint)));
|
|
36584
|
-
return isInGrid ? [middlePoint] : [];
|
|
36585
|
-
}
|
|
36586
|
-
if (width > height) {
|
|
36587
|
-
const centerIdx = grid.findIndex((row2) => row2[0].x === middlePoint.x || Math.abs(row2[0].x - middlePoint.x) < 0.01);
|
|
36588
|
-
if (centerIdx !== -1) {
|
|
36589
|
-
for (let y = 0;y < grid[0].length; y++) {
|
|
36590
|
-
if (grid[centerIdx][y] && grid[centerIdx][y].x >= min2.x - 0.01 && grid[centerIdx][y].x <= max2.x + 0.01 && grid[centerIdx][y].y >= min2.y - 0.01 && grid[centerIdx][y].y <= max2.y + 0.01) {
|
|
36591
|
-
centerLine.push(grid[centerIdx][y]);
|
|
36592
|
-
}
|
|
36593
|
-
}
|
|
36594
|
-
}
|
|
36595
|
-
} else {
|
|
36596
|
-
const centerIdx = grid[0].findIndex((point5) => point5.y === middlePoint.y || Math.abs(point5.y - middlePoint.y) < 0.01);
|
|
36597
|
-
if (centerIdx !== -1) {
|
|
36598
|
-
for (let x = 0;x < grid.length; x++) {
|
|
36599
|
-
if (grid[x][centerIdx] && grid[x][centerIdx].x >= min2.x - 0.01 && grid[x][centerIdx].x <= max2.x + 0.01 && grid[x][centerIdx].y >= min2.y - 0.01 && grid[x][centerIdx].y <= max2.y + 0.01) {
|
|
36600
|
-
centerLine.push(grid[x][centerIdx]);
|
|
36601
|
-
}
|
|
36602
|
-
}
|
|
36603
|
-
}
|
|
36604
|
-
}
|
|
36605
|
-
return centerLine;
|
|
36606
|
-
}
|
|
36607
36575
|
function createGrid(start, end, toVisitPoints = []) {
|
|
36608
36576
|
const startDir = getPointerDirection(start);
|
|
36609
36577
|
const endDir = getPointerDirection(end);
|
|
@@ -36811,17 +36779,42 @@ function reconstructPath(node2) {
|
|
|
36811
36779
|
}
|
|
36812
36780
|
return path2.reverse();
|
|
36813
36781
|
}
|
|
36782
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36783
|
+
const hookPoints = [];
|
|
36784
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36785
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36786
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
36787
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
36788
|
+
return hookPoints;
|
|
36789
|
+
}
|
|
36790
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36791
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36792
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
36793
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
36794
|
+
return hookPoints;
|
|
36795
|
+
}
|
|
36796
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36797
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36798
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
36799
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
36800
|
+
return hookPoints;
|
|
36801
|
+
}
|
|
36802
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36803
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36804
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
36805
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
36806
|
+
return hookPoints;
|
|
36807
|
+
}
|
|
36808
|
+
return hookPoints;
|
|
36809
|
+
}
|
|
36814
36810
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36815
|
-
const { grid, newStart, newEnd
|
|
36816
|
-
const startPoint = newStart
|
|
36817
|
-
const endPoint = newEnd
|
|
36818
|
-
const
|
|
36819
|
-
const
|
|
36820
|
-
const
|
|
36821
|
-
|
|
36822
|
-
...toVisitPoints.length > 0 ? toVisitPoints : adjustedCenterLine,
|
|
36823
|
-
endPoint
|
|
36824
|
-
];
|
|
36811
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36812
|
+
const startPoint = newStart || start;
|
|
36813
|
+
const endPoint = newEnd || end;
|
|
36814
|
+
const startDir = getPointerDirection(start);
|
|
36815
|
+
const endDir = getPointerDirection(end);
|
|
36816
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36817
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
36825
36818
|
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
36826
36819
|
return {
|
|
36827
36820
|
lines: getLines(pathPoints),
|
package/dist/esm/index.js
CHANGED
|
@@ -36565,38 +36565,6 @@ function getNeighbors(node2, grid, obstacles) {
|
|
|
36565
36565
|
}
|
|
36566
36566
|
return neighbors;
|
|
36567
36567
|
}
|
|
36568
|
-
function findCenterLine(grid, start, end, middle) {
|
|
36569
|
-
const centerLine = [];
|
|
36570
|
-
const middlePoint = middle ? middle : new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
36571
|
-
const min2 = new Point(Math.min(start.x, end.x), Math.min(start.y, end.y));
|
|
36572
|
-
const max2 = new Point(Math.max(start.x, end.x), Math.max(start.y, end.y));
|
|
36573
|
-
const width = max2.x - min2.x;
|
|
36574
|
-
const height = max2.y - min2.y;
|
|
36575
|
-
if (start.pointType !== "Board" && end.pointType !== "Board") {
|
|
36576
|
-
const isInGrid = grid.some((row2) => row2.some((point5) => point5.barelyEqual(middlePoint)));
|
|
36577
|
-
return isInGrid ? [middlePoint] : [];
|
|
36578
|
-
}
|
|
36579
|
-
if (width > height) {
|
|
36580
|
-
const centerIdx = grid.findIndex((row2) => row2[0].x === middlePoint.x || Math.abs(row2[0].x - middlePoint.x) < 0.01);
|
|
36581
|
-
if (centerIdx !== -1) {
|
|
36582
|
-
for (let y = 0;y < grid[0].length; y++) {
|
|
36583
|
-
if (grid[centerIdx][y] && grid[centerIdx][y].x >= min2.x - 0.01 && grid[centerIdx][y].x <= max2.x + 0.01 && grid[centerIdx][y].y >= min2.y - 0.01 && grid[centerIdx][y].y <= max2.y + 0.01) {
|
|
36584
|
-
centerLine.push(grid[centerIdx][y]);
|
|
36585
|
-
}
|
|
36586
|
-
}
|
|
36587
|
-
}
|
|
36588
|
-
} else {
|
|
36589
|
-
const centerIdx = grid[0].findIndex((point5) => point5.y === middlePoint.y || Math.abs(point5.y - middlePoint.y) < 0.01);
|
|
36590
|
-
if (centerIdx !== -1) {
|
|
36591
|
-
for (let x = 0;x < grid.length; x++) {
|
|
36592
|
-
if (grid[x][centerIdx] && grid[x][centerIdx].x >= min2.x - 0.01 && grid[x][centerIdx].x <= max2.x + 0.01 && grid[x][centerIdx].y >= min2.y - 0.01 && grid[x][centerIdx].y <= max2.y + 0.01) {
|
|
36593
|
-
centerLine.push(grid[x][centerIdx]);
|
|
36594
|
-
}
|
|
36595
|
-
}
|
|
36596
|
-
}
|
|
36597
|
-
}
|
|
36598
|
-
return centerLine;
|
|
36599
|
-
}
|
|
36600
36568
|
function createGrid(start, end, toVisitPoints = []) {
|
|
36601
36569
|
const startDir = getPointerDirection(start);
|
|
36602
36570
|
const endDir = getPointerDirection(end);
|
|
@@ -36804,17 +36772,42 @@ function reconstructPath(node2) {
|
|
|
36804
36772
|
}
|
|
36805
36773
|
return path2.reverse();
|
|
36806
36774
|
}
|
|
36775
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36776
|
+
const hookPoints = [];
|
|
36777
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36778
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36779
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
36780
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
36781
|
+
return hookPoints;
|
|
36782
|
+
}
|
|
36783
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36784
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36785
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
36786
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
36787
|
+
return hookPoints;
|
|
36788
|
+
}
|
|
36789
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36790
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36791
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
36792
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
36793
|
+
return hookPoints;
|
|
36794
|
+
}
|
|
36795
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36796
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36797
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
36798
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
36799
|
+
return hookPoints;
|
|
36800
|
+
}
|
|
36801
|
+
return hookPoints;
|
|
36802
|
+
}
|
|
36807
36803
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36808
|
-
const { grid, newStart, newEnd
|
|
36809
|
-
const startPoint = newStart
|
|
36810
|
-
const endPoint = newEnd
|
|
36811
|
-
const
|
|
36812
|
-
const
|
|
36813
|
-
const
|
|
36814
|
-
|
|
36815
|
-
...toVisitPoints.length > 0 ? toVisitPoints : adjustedCenterLine,
|
|
36816
|
-
endPoint
|
|
36817
|
-
];
|
|
36804
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36805
|
+
const startPoint = newStart || start;
|
|
36806
|
+
const endPoint = newEnd || end;
|
|
36807
|
+
const startDir = getPointerDirection(start);
|
|
36808
|
+
const endDir = getPointerDirection(end);
|
|
36809
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36810
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
36818
36811
|
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
36819
36812
|
return {
|
|
36820
36813
|
lines: getLines(pathPoints),
|
package/dist/esm/node.js
CHANGED
|
@@ -39033,38 +39033,6 @@ function getNeighbors(node2, grid, obstacles) {
|
|
|
39033
39033
|
}
|
|
39034
39034
|
return neighbors;
|
|
39035
39035
|
}
|
|
39036
|
-
function findCenterLine(grid, start, end, middle) {
|
|
39037
|
-
const centerLine = [];
|
|
39038
|
-
const middlePoint = middle ? middle : new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
39039
|
-
const min2 = new Point(Math.min(start.x, end.x), Math.min(start.y, end.y));
|
|
39040
|
-
const max2 = new Point(Math.max(start.x, end.x), Math.max(start.y, end.y));
|
|
39041
|
-
const width = max2.x - min2.x;
|
|
39042
|
-
const height = max2.y - min2.y;
|
|
39043
|
-
if (start.pointType !== "Board" && end.pointType !== "Board") {
|
|
39044
|
-
const isInGrid = grid.some((row2) => row2.some((point5) => point5.barelyEqual(middlePoint)));
|
|
39045
|
-
return isInGrid ? [middlePoint] : [];
|
|
39046
|
-
}
|
|
39047
|
-
if (width > height) {
|
|
39048
|
-
const centerIdx = grid.findIndex((row2) => row2[0].x === middlePoint.x || Math.abs(row2[0].x - middlePoint.x) < 0.01);
|
|
39049
|
-
if (centerIdx !== -1) {
|
|
39050
|
-
for (let y = 0;y < grid[0].length; y++) {
|
|
39051
|
-
if (grid[centerIdx][y] && grid[centerIdx][y].x >= min2.x - 0.01 && grid[centerIdx][y].x <= max2.x + 0.01 && grid[centerIdx][y].y >= min2.y - 0.01 && grid[centerIdx][y].y <= max2.y + 0.01) {
|
|
39052
|
-
centerLine.push(grid[centerIdx][y]);
|
|
39053
|
-
}
|
|
39054
|
-
}
|
|
39055
|
-
}
|
|
39056
|
-
} else {
|
|
39057
|
-
const centerIdx = grid[0].findIndex((point5) => point5.y === middlePoint.y || Math.abs(point5.y - middlePoint.y) < 0.01);
|
|
39058
|
-
if (centerIdx !== -1) {
|
|
39059
|
-
for (let x = 0;x < grid.length; x++) {
|
|
39060
|
-
if (grid[x][centerIdx] && grid[x][centerIdx].x >= min2.x - 0.01 && grid[x][centerIdx].x <= max2.x + 0.01 && grid[x][centerIdx].y >= min2.y - 0.01 && grid[x][centerIdx].y <= max2.y + 0.01) {
|
|
39061
|
-
centerLine.push(grid[x][centerIdx]);
|
|
39062
|
-
}
|
|
39063
|
-
}
|
|
39064
|
-
}
|
|
39065
|
-
}
|
|
39066
|
-
return centerLine;
|
|
39067
|
-
}
|
|
39068
39036
|
function createGrid(start, end, toVisitPoints = []) {
|
|
39069
39037
|
const startDir = getPointerDirection(start);
|
|
39070
39038
|
const endDir = getPointerDirection(end);
|
|
@@ -39272,17 +39240,42 @@ function reconstructPath(node2) {
|
|
|
39272
39240
|
}
|
|
39273
39241
|
return path2.reverse();
|
|
39274
39242
|
}
|
|
39243
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
39244
|
+
const hookPoints = [];
|
|
39245
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
39246
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39247
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
39248
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
39249
|
+
return hookPoints;
|
|
39250
|
+
}
|
|
39251
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
39252
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39253
|
+
hookPoints.push(new Point(startPoint.x, midY));
|
|
39254
|
+
hookPoints.push(new Point(endPoint.x, midY));
|
|
39255
|
+
return hookPoints;
|
|
39256
|
+
}
|
|
39257
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
39258
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39259
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
39260
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
39261
|
+
return hookPoints;
|
|
39262
|
+
}
|
|
39263
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
39264
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39265
|
+
hookPoints.push(new Point(midX, startPoint.y));
|
|
39266
|
+
hookPoints.push(new Point(midX, endPoint.y));
|
|
39267
|
+
return hookPoints;
|
|
39268
|
+
}
|
|
39269
|
+
return hookPoints;
|
|
39270
|
+
}
|
|
39275
39271
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
39276
|
-
const { grid, newStart, newEnd
|
|
39277
|
-
const startPoint = newStart
|
|
39278
|
-
const endPoint = newEnd
|
|
39279
|
-
const
|
|
39280
|
-
const
|
|
39281
|
-
const
|
|
39282
|
-
|
|
39283
|
-
...toVisitPoints.length > 0 ? toVisitPoints : adjustedCenterLine,
|
|
39284
|
-
endPoint
|
|
39285
|
-
];
|
|
39272
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
39273
|
+
const startPoint = newStart || start;
|
|
39274
|
+
const endPoint = newEnd || end;
|
|
39275
|
+
const startDir = getPointerDirection(start);
|
|
39276
|
+
const endDir = getPointerDirection(end);
|
|
39277
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
39278
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
39286
39279
|
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
39287
39280
|
return {
|
|
39288
39281
|
lines: getLines(pathPoints),
|