microboard-temp 0.5.96 → 0.5.97
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 +41 -21
- package/dist/cjs/index.js +41 -21
- package/dist/cjs/node.js +41 -21
- package/dist/esm/browser.js +41 -21
- package/dist/esm/index.js +41 -21
- package/dist/esm/node.js +41 -21
- package/package.json +1 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -36900,6 +36900,37 @@ function reconstructPath(node2) {
|
|
|
36900
36900
|
}
|
|
36901
36901
|
return path2.reverse();
|
|
36902
36902
|
}
|
|
36903
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36904
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36905
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36906
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36907
|
+
}
|
|
36908
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36909
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36910
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36911
|
+
}
|
|
36912
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36913
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36914
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36915
|
+
}
|
|
36916
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36917
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36918
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36919
|
+
}
|
|
36920
|
+
const dx = endPoint.x - startPoint.x;
|
|
36921
|
+
const dy = endPoint.y - startPoint.y;
|
|
36922
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36923
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36924
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36925
|
+
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
36926
|
+
if (startConflictX || endConflictY) {
|
|
36927
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
36928
|
+
}
|
|
36929
|
+
if (startConflictY || endConflictX) {
|
|
36930
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
36931
|
+
}
|
|
36932
|
+
return [];
|
|
36933
|
+
}
|
|
36903
36934
|
function findClosestPointInGrid(point5, grid) {
|
|
36904
36935
|
let closestPoint = grid[0][0];
|
|
36905
36936
|
let minDistance = Infinity;
|
|
@@ -36915,33 +36946,22 @@ function findClosestPointInGrid(point5, grid) {
|
|
|
36915
36946
|
return closestPoint;
|
|
36916
36947
|
}
|
|
36917
36948
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36918
|
-
const
|
|
36949
|
+
const tempGridInfo = createGrid(start, end);
|
|
36950
|
+
const startPoint = tempGridInfo.newStart || start;
|
|
36951
|
+
const endPoint = tempGridInfo.newEnd || end;
|
|
36952
|
+
const startDir = getPointerDirection(start);
|
|
36953
|
+
const endDir = getPointerDirection(end);
|
|
36954
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36955
|
+
const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
|
|
36956
|
+
const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
|
|
36919
36957
|
if (grid.length === 0 || grid[0].length === 0) {
|
|
36920
36958
|
return { lines: [], newStart, newEnd };
|
|
36921
36959
|
}
|
|
36922
36960
|
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
36923
36961
|
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
36924
|
-
const
|
|
36925
|
-
const pointsToConnect = [searchStart, ...snappedWaypoints, searchEnd];
|
|
36926
|
-
const finalPath = [pointsToConnect[0]];
|
|
36927
|
-
const existingPathSegments = new Set([`${pointsToConnect[0].x},${pointsToConnect[0].y}`]);
|
|
36928
|
-
for (let i = 0;i < pointsToConnect.length - 1; i++) {
|
|
36929
|
-
const segmentStart = pointsToConnect[i];
|
|
36930
|
-
const segmentEnd = pointsToConnect[i + 1];
|
|
36931
|
-
const segmentPath = findPath(segmentStart, segmentEnd, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
36932
|
-
if (segmentPath && segmentPath.length > 1) {
|
|
36933
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
36934
|
-
const point5 = segmentPath[j];
|
|
36935
|
-
finalPath.push(point5);
|
|
36936
|
-
existingPathSegments.add(`${point5.x},${point5.y}`);
|
|
36937
|
-
}
|
|
36938
|
-
} else {
|
|
36939
|
-
console.error(`Could not route segment from ${segmentStart.x},${segmentStart.y} to ${segmentEnd.x},${segmentEnd.y}`);
|
|
36940
|
-
return { lines: [], newStart, newEnd };
|
|
36941
|
-
}
|
|
36942
|
-
}
|
|
36962
|
+
const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
|
|
36943
36963
|
return {
|
|
36944
|
-
lines: getLines(
|
|
36964
|
+
lines: pathPoints ? getLines(pathPoints) : [],
|
|
36945
36965
|
newStart,
|
|
36946
36966
|
newEnd
|
|
36947
36967
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -36900,6 +36900,37 @@ function reconstructPath(node2) {
|
|
|
36900
36900
|
}
|
|
36901
36901
|
return path2.reverse();
|
|
36902
36902
|
}
|
|
36903
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36904
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36905
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36906
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36907
|
+
}
|
|
36908
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36909
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36910
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36911
|
+
}
|
|
36912
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36913
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36914
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36915
|
+
}
|
|
36916
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36917
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36918
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36919
|
+
}
|
|
36920
|
+
const dx = endPoint.x - startPoint.x;
|
|
36921
|
+
const dy = endPoint.y - startPoint.y;
|
|
36922
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36923
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36924
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36925
|
+
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
36926
|
+
if (startConflictX || endConflictY) {
|
|
36927
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
36928
|
+
}
|
|
36929
|
+
if (startConflictY || endConflictX) {
|
|
36930
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
36931
|
+
}
|
|
36932
|
+
return [];
|
|
36933
|
+
}
|
|
36903
36934
|
function findClosestPointInGrid(point5, grid) {
|
|
36904
36935
|
let closestPoint = grid[0][0];
|
|
36905
36936
|
let minDistance = Infinity;
|
|
@@ -36915,33 +36946,22 @@ function findClosestPointInGrid(point5, grid) {
|
|
|
36915
36946
|
return closestPoint;
|
|
36916
36947
|
}
|
|
36917
36948
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36918
|
-
const
|
|
36949
|
+
const tempGridInfo = createGrid(start, end);
|
|
36950
|
+
const startPoint = tempGridInfo.newStart || start;
|
|
36951
|
+
const endPoint = tempGridInfo.newEnd || end;
|
|
36952
|
+
const startDir = getPointerDirection(start);
|
|
36953
|
+
const endDir = getPointerDirection(end);
|
|
36954
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36955
|
+
const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
|
|
36956
|
+
const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
|
|
36919
36957
|
if (grid.length === 0 || grid[0].length === 0) {
|
|
36920
36958
|
return { lines: [], newStart, newEnd };
|
|
36921
36959
|
}
|
|
36922
36960
|
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
36923
36961
|
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
36924
|
-
const
|
|
36925
|
-
const pointsToConnect = [searchStart, ...snappedWaypoints, searchEnd];
|
|
36926
|
-
const finalPath = [pointsToConnect[0]];
|
|
36927
|
-
const existingPathSegments = new Set([`${pointsToConnect[0].x},${pointsToConnect[0].y}`]);
|
|
36928
|
-
for (let i = 0;i < pointsToConnect.length - 1; i++) {
|
|
36929
|
-
const segmentStart = pointsToConnect[i];
|
|
36930
|
-
const segmentEnd = pointsToConnect[i + 1];
|
|
36931
|
-
const segmentPath = findPath(segmentStart, segmentEnd, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
36932
|
-
if (segmentPath && segmentPath.length > 1) {
|
|
36933
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
36934
|
-
const point5 = segmentPath[j];
|
|
36935
|
-
finalPath.push(point5);
|
|
36936
|
-
existingPathSegments.add(`${point5.x},${point5.y}`);
|
|
36937
|
-
}
|
|
36938
|
-
} else {
|
|
36939
|
-
console.error(`Could not route segment from ${segmentStart.x},${segmentStart.y} to ${segmentEnd.x},${segmentEnd.y}`);
|
|
36940
|
-
return { lines: [], newStart, newEnd };
|
|
36941
|
-
}
|
|
36942
|
-
}
|
|
36962
|
+
const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
|
|
36943
36963
|
return {
|
|
36944
|
-
lines: getLines(
|
|
36964
|
+
lines: pathPoints ? getLines(pathPoints) : [],
|
|
36945
36965
|
newStart,
|
|
36946
36966
|
newEnd
|
|
36947
36967
|
};
|
package/dist/cjs/node.js
CHANGED
|
@@ -39373,6 +39373,37 @@ function reconstructPath(node2) {
|
|
|
39373
39373
|
}
|
|
39374
39374
|
return path2.reverse();
|
|
39375
39375
|
}
|
|
39376
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
39377
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
39378
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39379
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39380
|
+
}
|
|
39381
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
39382
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39383
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39384
|
+
}
|
|
39385
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
39386
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39387
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39388
|
+
}
|
|
39389
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
39390
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39391
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39392
|
+
}
|
|
39393
|
+
const dx = endPoint.x - startPoint.x;
|
|
39394
|
+
const dy = endPoint.y - startPoint.y;
|
|
39395
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
39396
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
39397
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
39398
|
+
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
39399
|
+
if (startConflictX || endConflictY) {
|
|
39400
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
39401
|
+
}
|
|
39402
|
+
if (startConflictY || endConflictX) {
|
|
39403
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
39404
|
+
}
|
|
39405
|
+
return [];
|
|
39406
|
+
}
|
|
39376
39407
|
function findClosestPointInGrid(point5, grid) {
|
|
39377
39408
|
let closestPoint = grid[0][0];
|
|
39378
39409
|
let minDistance = Infinity;
|
|
@@ -39388,33 +39419,22 @@ function findClosestPointInGrid(point5, grid) {
|
|
|
39388
39419
|
return closestPoint;
|
|
39389
39420
|
}
|
|
39390
39421
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
39391
|
-
const
|
|
39422
|
+
const tempGridInfo = createGrid(start, end);
|
|
39423
|
+
const startPoint = tempGridInfo.newStart || start;
|
|
39424
|
+
const endPoint = tempGridInfo.newEnd || end;
|
|
39425
|
+
const startDir = getPointerDirection(start);
|
|
39426
|
+
const endDir = getPointerDirection(end);
|
|
39427
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
39428
|
+
const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
|
|
39429
|
+
const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
|
|
39392
39430
|
if (grid.length === 0 || grid[0].length === 0) {
|
|
39393
39431
|
return { lines: [], newStart, newEnd };
|
|
39394
39432
|
}
|
|
39395
39433
|
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
39396
39434
|
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
39397
|
-
const
|
|
39398
|
-
const pointsToConnect = [searchStart, ...snappedWaypoints, searchEnd];
|
|
39399
|
-
const finalPath = [pointsToConnect[0]];
|
|
39400
|
-
const existingPathSegments = new Set([`${pointsToConnect[0].x},${pointsToConnect[0].y}`]);
|
|
39401
|
-
for (let i = 0;i < pointsToConnect.length - 1; i++) {
|
|
39402
|
-
const segmentStart = pointsToConnect[i];
|
|
39403
|
-
const segmentEnd = pointsToConnect[i + 1];
|
|
39404
|
-
const segmentPath = findPath(segmentStart, segmentEnd, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
39405
|
-
if (segmentPath && segmentPath.length > 1) {
|
|
39406
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
39407
|
-
const point5 = segmentPath[j];
|
|
39408
|
-
finalPath.push(point5);
|
|
39409
|
-
existingPathSegments.add(`${point5.x},${point5.y}`);
|
|
39410
|
-
}
|
|
39411
|
-
} else {
|
|
39412
|
-
console.error(`Could not route segment from ${segmentStart.x},${segmentStart.y} to ${segmentEnd.x},${segmentEnd.y}`);
|
|
39413
|
-
return { lines: [], newStart, newEnd };
|
|
39414
|
-
}
|
|
39415
|
-
}
|
|
39435
|
+
const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
|
|
39416
39436
|
return {
|
|
39417
|
-
lines: getLines(
|
|
39437
|
+
lines: pathPoints ? getLines(pathPoints) : [],
|
|
39418
39438
|
newStart,
|
|
39419
39439
|
newEnd
|
|
39420
39440
|
};
|
package/dist/esm/browser.js
CHANGED
|
@@ -36745,6 +36745,37 @@ function reconstructPath(node2) {
|
|
|
36745
36745
|
}
|
|
36746
36746
|
return path2.reverse();
|
|
36747
36747
|
}
|
|
36748
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36749
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36750
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36751
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36752
|
+
}
|
|
36753
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36754
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36755
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36756
|
+
}
|
|
36757
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36758
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36759
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36760
|
+
}
|
|
36761
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36762
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36763
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36764
|
+
}
|
|
36765
|
+
const dx = endPoint.x - startPoint.x;
|
|
36766
|
+
const dy = endPoint.y - startPoint.y;
|
|
36767
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36768
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36769
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36770
|
+
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
36771
|
+
if (startConflictX || endConflictY) {
|
|
36772
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
36773
|
+
}
|
|
36774
|
+
if (startConflictY || endConflictX) {
|
|
36775
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
36776
|
+
}
|
|
36777
|
+
return [];
|
|
36778
|
+
}
|
|
36748
36779
|
function findClosestPointInGrid(point5, grid) {
|
|
36749
36780
|
let closestPoint = grid[0][0];
|
|
36750
36781
|
let minDistance = Infinity;
|
|
@@ -36760,33 +36791,22 @@ function findClosestPointInGrid(point5, grid) {
|
|
|
36760
36791
|
return closestPoint;
|
|
36761
36792
|
}
|
|
36762
36793
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36763
|
-
const
|
|
36794
|
+
const tempGridInfo = createGrid(start, end);
|
|
36795
|
+
const startPoint = tempGridInfo.newStart || start;
|
|
36796
|
+
const endPoint = tempGridInfo.newEnd || end;
|
|
36797
|
+
const startDir = getPointerDirection(start);
|
|
36798
|
+
const endDir = getPointerDirection(end);
|
|
36799
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36800
|
+
const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
|
|
36801
|
+
const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
|
|
36764
36802
|
if (grid.length === 0 || grid[0].length === 0) {
|
|
36765
36803
|
return { lines: [], newStart, newEnd };
|
|
36766
36804
|
}
|
|
36767
36805
|
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
36768
36806
|
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
36769
|
-
const
|
|
36770
|
-
const pointsToConnect = [searchStart, ...snappedWaypoints, searchEnd];
|
|
36771
|
-
const finalPath = [pointsToConnect[0]];
|
|
36772
|
-
const existingPathSegments = new Set([`${pointsToConnect[0].x},${pointsToConnect[0].y}`]);
|
|
36773
|
-
for (let i = 0;i < pointsToConnect.length - 1; i++) {
|
|
36774
|
-
const segmentStart = pointsToConnect[i];
|
|
36775
|
-
const segmentEnd = pointsToConnect[i + 1];
|
|
36776
|
-
const segmentPath = findPath(segmentStart, segmentEnd, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
36777
|
-
if (segmentPath && segmentPath.length > 1) {
|
|
36778
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
36779
|
-
const point5 = segmentPath[j];
|
|
36780
|
-
finalPath.push(point5);
|
|
36781
|
-
existingPathSegments.add(`${point5.x},${point5.y}`);
|
|
36782
|
-
}
|
|
36783
|
-
} else {
|
|
36784
|
-
console.error(`Could not route segment from ${segmentStart.x},${segmentStart.y} to ${segmentEnd.x},${segmentEnd.y}`);
|
|
36785
|
-
return { lines: [], newStart, newEnd };
|
|
36786
|
-
}
|
|
36787
|
-
}
|
|
36807
|
+
const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
|
|
36788
36808
|
return {
|
|
36789
|
-
lines: getLines(
|
|
36809
|
+
lines: pathPoints ? getLines(pathPoints) : [],
|
|
36790
36810
|
newStart,
|
|
36791
36811
|
newEnd
|
|
36792
36812
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -36738,6 +36738,37 @@ function reconstructPath(node2) {
|
|
|
36738
36738
|
}
|
|
36739
36739
|
return path2.reverse();
|
|
36740
36740
|
}
|
|
36741
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36742
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36743
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36744
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36745
|
+
}
|
|
36746
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36747
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36748
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36749
|
+
}
|
|
36750
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36751
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36752
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36753
|
+
}
|
|
36754
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36755
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36756
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36757
|
+
}
|
|
36758
|
+
const dx = endPoint.x - startPoint.x;
|
|
36759
|
+
const dy = endPoint.y - startPoint.y;
|
|
36760
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36761
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36762
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36763
|
+
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
36764
|
+
if (startConflictX || endConflictY) {
|
|
36765
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
36766
|
+
}
|
|
36767
|
+
if (startConflictY || endConflictX) {
|
|
36768
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
36769
|
+
}
|
|
36770
|
+
return [];
|
|
36771
|
+
}
|
|
36741
36772
|
function findClosestPointInGrid(point5, grid) {
|
|
36742
36773
|
let closestPoint = grid[0][0];
|
|
36743
36774
|
let minDistance = Infinity;
|
|
@@ -36753,33 +36784,22 @@ function findClosestPointInGrid(point5, grid) {
|
|
|
36753
36784
|
return closestPoint;
|
|
36754
36785
|
}
|
|
36755
36786
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36756
|
-
const
|
|
36787
|
+
const tempGridInfo = createGrid(start, end);
|
|
36788
|
+
const startPoint = tempGridInfo.newStart || start;
|
|
36789
|
+
const endPoint = tempGridInfo.newEnd || end;
|
|
36790
|
+
const startDir = getPointerDirection(start);
|
|
36791
|
+
const endDir = getPointerDirection(end);
|
|
36792
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36793
|
+
const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
|
|
36794
|
+
const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
|
|
36757
36795
|
if (grid.length === 0 || grid[0].length === 0) {
|
|
36758
36796
|
return { lines: [], newStart, newEnd };
|
|
36759
36797
|
}
|
|
36760
36798
|
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
36761
36799
|
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
36762
|
-
const
|
|
36763
|
-
const pointsToConnect = [searchStart, ...snappedWaypoints, searchEnd];
|
|
36764
|
-
const finalPath = [pointsToConnect[0]];
|
|
36765
|
-
const existingPathSegments = new Set([`${pointsToConnect[0].x},${pointsToConnect[0].y}`]);
|
|
36766
|
-
for (let i = 0;i < pointsToConnect.length - 1; i++) {
|
|
36767
|
-
const segmentStart = pointsToConnect[i];
|
|
36768
|
-
const segmentEnd = pointsToConnect[i + 1];
|
|
36769
|
-
const segmentPath = findPath(segmentStart, segmentEnd, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
36770
|
-
if (segmentPath && segmentPath.length > 1) {
|
|
36771
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
36772
|
-
const point5 = segmentPath[j];
|
|
36773
|
-
finalPath.push(point5);
|
|
36774
|
-
existingPathSegments.add(`${point5.x},${point5.y}`);
|
|
36775
|
-
}
|
|
36776
|
-
} else {
|
|
36777
|
-
console.error(`Could not route segment from ${segmentStart.x},${segmentStart.y} to ${segmentEnd.x},${segmentEnd.y}`);
|
|
36778
|
-
return { lines: [], newStart, newEnd };
|
|
36779
|
-
}
|
|
36780
|
-
}
|
|
36800
|
+
const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
|
|
36781
36801
|
return {
|
|
36782
|
-
lines: getLines(
|
|
36802
|
+
lines: pathPoints ? getLines(pathPoints) : [],
|
|
36783
36803
|
newStart,
|
|
36784
36804
|
newEnd
|
|
36785
36805
|
};
|
package/dist/esm/node.js
CHANGED
|
@@ -39206,6 +39206,37 @@ function reconstructPath(node2) {
|
|
|
39206
39206
|
}
|
|
39207
39207
|
return path2.reverse();
|
|
39208
39208
|
}
|
|
39209
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
39210
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
39211
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39212
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39213
|
+
}
|
|
39214
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
39215
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39216
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39217
|
+
}
|
|
39218
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
39219
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39220
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39221
|
+
}
|
|
39222
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
39223
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39224
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39225
|
+
}
|
|
39226
|
+
const dx = endPoint.x - startPoint.x;
|
|
39227
|
+
const dy = endPoint.y - startPoint.y;
|
|
39228
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
39229
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
39230
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
39231
|
+
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
39232
|
+
if (startConflictX || endConflictY) {
|
|
39233
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
39234
|
+
}
|
|
39235
|
+
if (startConflictY || endConflictX) {
|
|
39236
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
39237
|
+
}
|
|
39238
|
+
return [];
|
|
39239
|
+
}
|
|
39209
39240
|
function findClosestPointInGrid(point5, grid) {
|
|
39210
39241
|
let closestPoint = grid[0][0];
|
|
39211
39242
|
let minDistance = Infinity;
|
|
@@ -39221,33 +39252,22 @@ function findClosestPointInGrid(point5, grid) {
|
|
|
39221
39252
|
return closestPoint;
|
|
39222
39253
|
}
|
|
39223
39254
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
39224
|
-
const
|
|
39255
|
+
const tempGridInfo = createGrid(start, end);
|
|
39256
|
+
const startPoint = tempGridInfo.newStart || start;
|
|
39257
|
+
const endPoint = tempGridInfo.newEnd || end;
|
|
39258
|
+
const startDir = getPointerDirection(start);
|
|
39259
|
+
const endDir = getPointerDirection(end);
|
|
39260
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
39261
|
+
const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
|
|
39262
|
+
const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
|
|
39225
39263
|
if (grid.length === 0 || grid[0].length === 0) {
|
|
39226
39264
|
return { lines: [], newStart, newEnd };
|
|
39227
39265
|
}
|
|
39228
39266
|
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
39229
39267
|
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
39230
|
-
const
|
|
39231
|
-
const pointsToConnect = [searchStart, ...snappedWaypoints, searchEnd];
|
|
39232
|
-
const finalPath = [pointsToConnect[0]];
|
|
39233
|
-
const existingPathSegments = new Set([`${pointsToConnect[0].x},${pointsToConnect[0].y}`]);
|
|
39234
|
-
for (let i = 0;i < pointsToConnect.length - 1; i++) {
|
|
39235
|
-
const segmentStart = pointsToConnect[i];
|
|
39236
|
-
const segmentEnd = pointsToConnect[i + 1];
|
|
39237
|
-
const segmentPath = findPath(segmentStart, segmentEnd, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
39238
|
-
if (segmentPath && segmentPath.length > 1) {
|
|
39239
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
39240
|
-
const point5 = segmentPath[j];
|
|
39241
|
-
finalPath.push(point5);
|
|
39242
|
-
existingPathSegments.add(`${point5.x},${point5.y}`);
|
|
39243
|
-
}
|
|
39244
|
-
} else {
|
|
39245
|
-
console.error(`Could not route segment from ${segmentStart.x},${segmentStart.y} to ${segmentEnd.x},${segmentEnd.y}`);
|
|
39246
|
-
return { lines: [], newStart, newEnd };
|
|
39247
|
-
}
|
|
39248
|
-
}
|
|
39268
|
+
const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
|
|
39249
39269
|
return {
|
|
39250
|
-
lines: getLines(
|
|
39270
|
+
lines: pathPoints ? getLines(pathPoints) : [],
|
|
39251
39271
|
newStart,
|
|
39252
39272
|
newEnd
|
|
39253
39273
|
};
|