microboard-temp 0.5.95 → 0.5.96
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 +29 -96
- package/dist/cjs/index.js +29 -96
- package/dist/cjs/node.js +29 -96
- package/dist/esm/browser.js +29 -96
- package/dist/esm/index.js +29 -96
- package/dist/esm/node.js +29 -96
- package/package.json +1 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -36848,30 +36848,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
|
36848
36848
|
}
|
|
36849
36849
|
return;
|
|
36850
36850
|
}
|
|
36851
|
-
function findPathPoints(points, grid, obstacles, newStart, newEnd) {
|
|
36852
|
-
if (points.length < 2) {
|
|
36853
|
-
return points;
|
|
36854
|
-
}
|
|
36855
|
-
const finalPath = [points[0]];
|
|
36856
|
-
const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
|
|
36857
|
-
for (let i = 0;i < points.length - 1; i += 1) {
|
|
36858
|
-
const startSegment = points[i];
|
|
36859
|
-
const endSegment = points[i + 1];
|
|
36860
|
-
const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
36861
|
-
if (segmentPath && segmentPath.length > 0) {
|
|
36862
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
36863
|
-
const point5 = segmentPath[j];
|
|
36864
|
-
const key = `${point5.x},${point5.y}`;
|
|
36865
|
-
finalPath.push(point5);
|
|
36866
|
-
existingPathSegments.add(key);
|
|
36867
|
-
}
|
|
36868
|
-
} else {
|
|
36869
|
-
console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
|
|
36870
|
-
return [];
|
|
36871
|
-
}
|
|
36872
|
-
}
|
|
36873
|
-
return finalPath;
|
|
36874
|
-
}
|
|
36875
36851
|
function reducePoints(points) {
|
|
36876
36852
|
const uniquePoints = new Map;
|
|
36877
36853
|
const result = [];
|
|
@@ -36924,91 +36900,48 @@ function reconstructPath(node2) {
|
|
|
36924
36900
|
}
|
|
36925
36901
|
return path2.reverse();
|
|
36926
36902
|
}
|
|
36927
|
-
function
|
|
36928
|
-
|
|
36929
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36930
|
-
console.log("111");
|
|
36931
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
36932
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36933
|
-
}
|
|
36934
|
-
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36935
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36936
|
-
console.log("222");
|
|
36937
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
36938
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36939
|
-
}
|
|
36940
|
-
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36941
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36942
|
-
console.log("333");
|
|
36943
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
36944
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36945
|
-
}
|
|
36946
|
-
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36947
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36948
|
-
console.log("444");
|
|
36949
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
36950
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36951
|
-
}
|
|
36952
|
-
const dx = endPoint.x - startPoint.x;
|
|
36953
|
-
const dy = endPoint.y - startPoint.y;
|
|
36954
|
-
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36955
|
-
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36956
|
-
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36957
|
-
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
36958
|
-
if (startConflictX || endConflictY) {
|
|
36959
|
-
console.log("555");
|
|
36960
|
-
console.log([new Point(startPoint.x, endPoint.y)]);
|
|
36961
|
-
return [new Point(startPoint.x, endPoint.y)];
|
|
36962
|
-
}
|
|
36963
|
-
if (startConflictY || endConflictX) {
|
|
36964
|
-
console.log("666");
|
|
36965
|
-
console.log([new Point(endPoint.x, startPoint.y)]);
|
|
36966
|
-
return [new Point(endPoint.x, startPoint.y)];
|
|
36967
|
-
}
|
|
36968
|
-
return [];
|
|
36969
|
-
}
|
|
36970
|
-
function findClosestValidPointInGrid(point5, grid, obstacles) {
|
|
36971
|
-
let closestPoint = null;
|
|
36903
|
+
function findClosestPointInGrid(point5, grid) {
|
|
36904
|
+
let closestPoint = grid[0][0];
|
|
36972
36905
|
let minDistance = Infinity;
|
|
36973
36906
|
for (const row2 of grid) {
|
|
36974
36907
|
for (const gridPoint of row2) {
|
|
36975
|
-
const
|
|
36976
|
-
if (
|
|
36977
|
-
|
|
36978
|
-
|
|
36979
|
-
minDistance = distance;
|
|
36980
|
-
closestPoint = gridPoint;
|
|
36981
|
-
}
|
|
36908
|
+
const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
|
|
36909
|
+
if (distance < minDistance) {
|
|
36910
|
+
minDistance = distance;
|
|
36911
|
+
closestPoint = gridPoint;
|
|
36982
36912
|
}
|
|
36983
36913
|
}
|
|
36984
36914
|
}
|
|
36985
36915
|
return closestPoint;
|
|
36986
36916
|
}
|
|
36987
36917
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36988
|
-
const
|
|
36989
|
-
|
|
36990
|
-
const endPoint = tempGridInfo.newEnd || end;
|
|
36991
|
-
const startDir = getPointerDirection(start);
|
|
36992
|
-
const endDir = getPointerDirection(end);
|
|
36993
|
-
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36994
|
-
const allWaypoints = [...hookWaypoints, ...toVisitPoints];
|
|
36995
|
-
const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
|
|
36996
|
-
const finalStart = newStart || start;
|
|
36997
|
-
const finalEnd = newEnd || end;
|
|
36998
|
-
const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
|
|
36999
|
-
const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
|
|
37000
|
-
if (snappedAndValidatedPoints.length < 2) {
|
|
36918
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36919
|
+
if (grid.length === 0 || grid[0].length === 0) {
|
|
37001
36920
|
return { lines: [], newStart, newEnd };
|
|
37002
36921
|
}
|
|
37003
|
-
const
|
|
37004
|
-
|
|
37005
|
-
|
|
36922
|
+
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
36923
|
+
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
36924
|
+
const snappedWaypoints = toVisitPoints.map((p3) => findClosestPointInGrid(p3, grid));
|
|
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 };
|
|
37006
36941
|
}
|
|
37007
|
-
|
|
37008
|
-
}, []);
|
|
37009
|
-
const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
|
|
36942
|
+
}
|
|
37010
36943
|
return {
|
|
37011
|
-
lines: getLines(
|
|
36944
|
+
lines: getLines(finalPath),
|
|
37012
36945
|
newStart,
|
|
37013
36946
|
newEnd
|
|
37014
36947
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -36848,30 +36848,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
|
36848
36848
|
}
|
|
36849
36849
|
return;
|
|
36850
36850
|
}
|
|
36851
|
-
function findPathPoints(points, grid, obstacles, newStart, newEnd) {
|
|
36852
|
-
if (points.length < 2) {
|
|
36853
|
-
return points;
|
|
36854
|
-
}
|
|
36855
|
-
const finalPath = [points[0]];
|
|
36856
|
-
const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
|
|
36857
|
-
for (let i = 0;i < points.length - 1; i += 1) {
|
|
36858
|
-
const startSegment = points[i];
|
|
36859
|
-
const endSegment = points[i + 1];
|
|
36860
|
-
const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
36861
|
-
if (segmentPath && segmentPath.length > 0) {
|
|
36862
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
36863
|
-
const point5 = segmentPath[j];
|
|
36864
|
-
const key = `${point5.x},${point5.y}`;
|
|
36865
|
-
finalPath.push(point5);
|
|
36866
|
-
existingPathSegments.add(key);
|
|
36867
|
-
}
|
|
36868
|
-
} else {
|
|
36869
|
-
console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
|
|
36870
|
-
return [];
|
|
36871
|
-
}
|
|
36872
|
-
}
|
|
36873
|
-
return finalPath;
|
|
36874
|
-
}
|
|
36875
36851
|
function reducePoints(points) {
|
|
36876
36852
|
const uniquePoints = new Map;
|
|
36877
36853
|
const result = [];
|
|
@@ -36924,91 +36900,48 @@ function reconstructPath(node2) {
|
|
|
36924
36900
|
}
|
|
36925
36901
|
return path2.reverse();
|
|
36926
36902
|
}
|
|
36927
|
-
function
|
|
36928
|
-
|
|
36929
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36930
|
-
console.log("111");
|
|
36931
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
36932
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36933
|
-
}
|
|
36934
|
-
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36935
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36936
|
-
console.log("222");
|
|
36937
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
36938
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36939
|
-
}
|
|
36940
|
-
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36941
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36942
|
-
console.log("333");
|
|
36943
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
36944
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36945
|
-
}
|
|
36946
|
-
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36947
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36948
|
-
console.log("444");
|
|
36949
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
36950
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36951
|
-
}
|
|
36952
|
-
const dx = endPoint.x - startPoint.x;
|
|
36953
|
-
const dy = endPoint.y - startPoint.y;
|
|
36954
|
-
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36955
|
-
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36956
|
-
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36957
|
-
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
36958
|
-
if (startConflictX || endConflictY) {
|
|
36959
|
-
console.log("555");
|
|
36960
|
-
console.log([new Point(startPoint.x, endPoint.y)]);
|
|
36961
|
-
return [new Point(startPoint.x, endPoint.y)];
|
|
36962
|
-
}
|
|
36963
|
-
if (startConflictY || endConflictX) {
|
|
36964
|
-
console.log("666");
|
|
36965
|
-
console.log([new Point(endPoint.x, startPoint.y)]);
|
|
36966
|
-
return [new Point(endPoint.x, startPoint.y)];
|
|
36967
|
-
}
|
|
36968
|
-
return [];
|
|
36969
|
-
}
|
|
36970
|
-
function findClosestValidPointInGrid(point5, grid, obstacles) {
|
|
36971
|
-
let closestPoint = null;
|
|
36903
|
+
function findClosestPointInGrid(point5, grid) {
|
|
36904
|
+
let closestPoint = grid[0][0];
|
|
36972
36905
|
let minDistance = Infinity;
|
|
36973
36906
|
for (const row2 of grid) {
|
|
36974
36907
|
for (const gridPoint of row2) {
|
|
36975
|
-
const
|
|
36976
|
-
if (
|
|
36977
|
-
|
|
36978
|
-
|
|
36979
|
-
minDistance = distance;
|
|
36980
|
-
closestPoint = gridPoint;
|
|
36981
|
-
}
|
|
36908
|
+
const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
|
|
36909
|
+
if (distance < minDistance) {
|
|
36910
|
+
minDistance = distance;
|
|
36911
|
+
closestPoint = gridPoint;
|
|
36982
36912
|
}
|
|
36983
36913
|
}
|
|
36984
36914
|
}
|
|
36985
36915
|
return closestPoint;
|
|
36986
36916
|
}
|
|
36987
36917
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36988
|
-
const
|
|
36989
|
-
|
|
36990
|
-
const endPoint = tempGridInfo.newEnd || end;
|
|
36991
|
-
const startDir = getPointerDirection(start);
|
|
36992
|
-
const endDir = getPointerDirection(end);
|
|
36993
|
-
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36994
|
-
const allWaypoints = [...hookWaypoints, ...toVisitPoints];
|
|
36995
|
-
const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
|
|
36996
|
-
const finalStart = newStart || start;
|
|
36997
|
-
const finalEnd = newEnd || end;
|
|
36998
|
-
const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
|
|
36999
|
-
const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
|
|
37000
|
-
if (snappedAndValidatedPoints.length < 2) {
|
|
36918
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36919
|
+
if (grid.length === 0 || grid[0].length === 0) {
|
|
37001
36920
|
return { lines: [], newStart, newEnd };
|
|
37002
36921
|
}
|
|
37003
|
-
const
|
|
37004
|
-
|
|
37005
|
-
|
|
36922
|
+
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
36923
|
+
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
36924
|
+
const snappedWaypoints = toVisitPoints.map((p3) => findClosestPointInGrid(p3, grid));
|
|
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 };
|
|
37006
36941
|
}
|
|
37007
|
-
|
|
37008
|
-
}, []);
|
|
37009
|
-
const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
|
|
36942
|
+
}
|
|
37010
36943
|
return {
|
|
37011
|
-
lines: getLines(
|
|
36944
|
+
lines: getLines(finalPath),
|
|
37012
36945
|
newStart,
|
|
37013
36946
|
newEnd
|
|
37014
36947
|
};
|
package/dist/cjs/node.js
CHANGED
|
@@ -39321,30 +39321,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
|
39321
39321
|
}
|
|
39322
39322
|
return;
|
|
39323
39323
|
}
|
|
39324
|
-
function findPathPoints(points, grid, obstacles, newStart, newEnd) {
|
|
39325
|
-
if (points.length < 2) {
|
|
39326
|
-
return points;
|
|
39327
|
-
}
|
|
39328
|
-
const finalPath = [points[0]];
|
|
39329
|
-
const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
|
|
39330
|
-
for (let i = 0;i < points.length - 1; i += 1) {
|
|
39331
|
-
const startSegment = points[i];
|
|
39332
|
-
const endSegment = points[i + 1];
|
|
39333
|
-
const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
39334
|
-
if (segmentPath && segmentPath.length > 0) {
|
|
39335
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
39336
|
-
const point5 = segmentPath[j];
|
|
39337
|
-
const key = `${point5.x},${point5.y}`;
|
|
39338
|
-
finalPath.push(point5);
|
|
39339
|
-
existingPathSegments.add(key);
|
|
39340
|
-
}
|
|
39341
|
-
} else {
|
|
39342
|
-
console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
|
|
39343
|
-
return [];
|
|
39344
|
-
}
|
|
39345
|
-
}
|
|
39346
|
-
return finalPath;
|
|
39347
|
-
}
|
|
39348
39324
|
function reducePoints(points) {
|
|
39349
39325
|
const uniquePoints = new Map;
|
|
39350
39326
|
const result = [];
|
|
@@ -39397,91 +39373,48 @@ function reconstructPath(node2) {
|
|
|
39397
39373
|
}
|
|
39398
39374
|
return path2.reverse();
|
|
39399
39375
|
}
|
|
39400
|
-
function
|
|
39401
|
-
|
|
39402
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39403
|
-
console.log("111");
|
|
39404
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
39405
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39406
|
-
}
|
|
39407
|
-
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
39408
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39409
|
-
console.log("222");
|
|
39410
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
39411
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39412
|
-
}
|
|
39413
|
-
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
39414
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39415
|
-
console.log("333");
|
|
39416
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
39417
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39418
|
-
}
|
|
39419
|
-
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
39420
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39421
|
-
console.log("444");
|
|
39422
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
39423
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39424
|
-
}
|
|
39425
|
-
const dx = endPoint.x - startPoint.x;
|
|
39426
|
-
const dy = endPoint.y - startPoint.y;
|
|
39427
|
-
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
39428
|
-
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
39429
|
-
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
39430
|
-
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
39431
|
-
if (startConflictX || endConflictY) {
|
|
39432
|
-
console.log("555");
|
|
39433
|
-
console.log([new Point(startPoint.x, endPoint.y)]);
|
|
39434
|
-
return [new Point(startPoint.x, endPoint.y)];
|
|
39435
|
-
}
|
|
39436
|
-
if (startConflictY || endConflictX) {
|
|
39437
|
-
console.log("666");
|
|
39438
|
-
console.log([new Point(endPoint.x, startPoint.y)]);
|
|
39439
|
-
return [new Point(endPoint.x, startPoint.y)];
|
|
39440
|
-
}
|
|
39441
|
-
return [];
|
|
39442
|
-
}
|
|
39443
|
-
function findClosestValidPointInGrid(point5, grid, obstacles) {
|
|
39444
|
-
let closestPoint = null;
|
|
39376
|
+
function findClosestPointInGrid(point5, grid) {
|
|
39377
|
+
let closestPoint = grid[0][0];
|
|
39445
39378
|
let minDistance = Infinity;
|
|
39446
39379
|
for (const row2 of grid) {
|
|
39447
39380
|
for (const gridPoint of row2) {
|
|
39448
|
-
const
|
|
39449
|
-
if (
|
|
39450
|
-
|
|
39451
|
-
|
|
39452
|
-
minDistance = distance;
|
|
39453
|
-
closestPoint = gridPoint;
|
|
39454
|
-
}
|
|
39381
|
+
const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
|
|
39382
|
+
if (distance < minDistance) {
|
|
39383
|
+
minDistance = distance;
|
|
39384
|
+
closestPoint = gridPoint;
|
|
39455
39385
|
}
|
|
39456
39386
|
}
|
|
39457
39387
|
}
|
|
39458
39388
|
return closestPoint;
|
|
39459
39389
|
}
|
|
39460
39390
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
39461
|
-
const
|
|
39462
|
-
|
|
39463
|
-
const endPoint = tempGridInfo.newEnd || end;
|
|
39464
|
-
const startDir = getPointerDirection(start);
|
|
39465
|
-
const endDir = getPointerDirection(end);
|
|
39466
|
-
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
39467
|
-
const allWaypoints = [...hookWaypoints, ...toVisitPoints];
|
|
39468
|
-
const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
|
|
39469
|
-
const finalStart = newStart || start;
|
|
39470
|
-
const finalEnd = newEnd || end;
|
|
39471
|
-
const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
|
|
39472
|
-
const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
|
|
39473
|
-
if (snappedAndValidatedPoints.length < 2) {
|
|
39391
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
39392
|
+
if (grid.length === 0 || grid[0].length === 0) {
|
|
39474
39393
|
return { lines: [], newStart, newEnd };
|
|
39475
39394
|
}
|
|
39476
|
-
const
|
|
39477
|
-
|
|
39478
|
-
|
|
39395
|
+
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
39396
|
+
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
39397
|
+
const snappedWaypoints = toVisitPoints.map((p3) => findClosestPointInGrid(p3, grid));
|
|
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 };
|
|
39479
39414
|
}
|
|
39480
|
-
|
|
39481
|
-
}, []);
|
|
39482
|
-
const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
|
|
39415
|
+
}
|
|
39483
39416
|
return {
|
|
39484
|
-
lines: getLines(
|
|
39417
|
+
lines: getLines(finalPath),
|
|
39485
39418
|
newStart,
|
|
39486
39419
|
newEnd
|
|
39487
39420
|
};
|
package/dist/esm/browser.js
CHANGED
|
@@ -36693,30 +36693,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
|
36693
36693
|
}
|
|
36694
36694
|
return;
|
|
36695
36695
|
}
|
|
36696
|
-
function findPathPoints(points, grid, obstacles, newStart, newEnd) {
|
|
36697
|
-
if (points.length < 2) {
|
|
36698
|
-
return points;
|
|
36699
|
-
}
|
|
36700
|
-
const finalPath = [points[0]];
|
|
36701
|
-
const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
|
|
36702
|
-
for (let i = 0;i < points.length - 1; i += 1) {
|
|
36703
|
-
const startSegment = points[i];
|
|
36704
|
-
const endSegment = points[i + 1];
|
|
36705
|
-
const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
36706
|
-
if (segmentPath && segmentPath.length > 0) {
|
|
36707
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
36708
|
-
const point5 = segmentPath[j];
|
|
36709
|
-
const key = `${point5.x},${point5.y}`;
|
|
36710
|
-
finalPath.push(point5);
|
|
36711
|
-
existingPathSegments.add(key);
|
|
36712
|
-
}
|
|
36713
|
-
} else {
|
|
36714
|
-
console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
|
|
36715
|
-
return [];
|
|
36716
|
-
}
|
|
36717
|
-
}
|
|
36718
|
-
return finalPath;
|
|
36719
|
-
}
|
|
36720
36696
|
function reducePoints(points) {
|
|
36721
36697
|
const uniquePoints = new Map;
|
|
36722
36698
|
const result = [];
|
|
@@ -36769,91 +36745,48 @@ function reconstructPath(node2) {
|
|
|
36769
36745
|
}
|
|
36770
36746
|
return path2.reverse();
|
|
36771
36747
|
}
|
|
36772
|
-
function
|
|
36773
|
-
|
|
36774
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36775
|
-
console.log("111");
|
|
36776
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
36777
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36778
|
-
}
|
|
36779
|
-
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36780
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36781
|
-
console.log("222");
|
|
36782
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
36783
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36784
|
-
}
|
|
36785
|
-
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36786
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36787
|
-
console.log("333");
|
|
36788
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
36789
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36790
|
-
}
|
|
36791
|
-
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36792
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36793
|
-
console.log("444");
|
|
36794
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
36795
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36796
|
-
}
|
|
36797
|
-
const dx = endPoint.x - startPoint.x;
|
|
36798
|
-
const dy = endPoint.y - startPoint.y;
|
|
36799
|
-
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36800
|
-
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36801
|
-
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36802
|
-
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
36803
|
-
if (startConflictX || endConflictY) {
|
|
36804
|
-
console.log("555");
|
|
36805
|
-
console.log([new Point(startPoint.x, endPoint.y)]);
|
|
36806
|
-
return [new Point(startPoint.x, endPoint.y)];
|
|
36807
|
-
}
|
|
36808
|
-
if (startConflictY || endConflictX) {
|
|
36809
|
-
console.log("666");
|
|
36810
|
-
console.log([new Point(endPoint.x, startPoint.y)]);
|
|
36811
|
-
return [new Point(endPoint.x, startPoint.y)];
|
|
36812
|
-
}
|
|
36813
|
-
return [];
|
|
36814
|
-
}
|
|
36815
|
-
function findClosestValidPointInGrid(point5, grid, obstacles) {
|
|
36816
|
-
let closestPoint = null;
|
|
36748
|
+
function findClosestPointInGrid(point5, grid) {
|
|
36749
|
+
let closestPoint = grid[0][0];
|
|
36817
36750
|
let minDistance = Infinity;
|
|
36818
36751
|
for (const row2 of grid) {
|
|
36819
36752
|
for (const gridPoint of row2) {
|
|
36820
|
-
const
|
|
36821
|
-
if (
|
|
36822
|
-
|
|
36823
|
-
|
|
36824
|
-
minDistance = distance;
|
|
36825
|
-
closestPoint = gridPoint;
|
|
36826
|
-
}
|
|
36753
|
+
const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
|
|
36754
|
+
if (distance < minDistance) {
|
|
36755
|
+
minDistance = distance;
|
|
36756
|
+
closestPoint = gridPoint;
|
|
36827
36757
|
}
|
|
36828
36758
|
}
|
|
36829
36759
|
}
|
|
36830
36760
|
return closestPoint;
|
|
36831
36761
|
}
|
|
36832
36762
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36833
|
-
const
|
|
36834
|
-
|
|
36835
|
-
const endPoint = tempGridInfo.newEnd || end;
|
|
36836
|
-
const startDir = getPointerDirection(start);
|
|
36837
|
-
const endDir = getPointerDirection(end);
|
|
36838
|
-
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36839
|
-
const allWaypoints = [...hookWaypoints, ...toVisitPoints];
|
|
36840
|
-
const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
|
|
36841
|
-
const finalStart = newStart || start;
|
|
36842
|
-
const finalEnd = newEnd || end;
|
|
36843
|
-
const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
|
|
36844
|
-
const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
|
|
36845
|
-
if (snappedAndValidatedPoints.length < 2) {
|
|
36763
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36764
|
+
if (grid.length === 0 || grid[0].length === 0) {
|
|
36846
36765
|
return { lines: [], newStart, newEnd };
|
|
36847
36766
|
}
|
|
36848
|
-
const
|
|
36849
|
-
|
|
36850
|
-
|
|
36767
|
+
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
36768
|
+
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
36769
|
+
const snappedWaypoints = toVisitPoints.map((p3) => findClosestPointInGrid(p3, grid));
|
|
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 };
|
|
36851
36786
|
}
|
|
36852
|
-
|
|
36853
|
-
}, []);
|
|
36854
|
-
const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
|
|
36787
|
+
}
|
|
36855
36788
|
return {
|
|
36856
|
-
lines: getLines(
|
|
36789
|
+
lines: getLines(finalPath),
|
|
36857
36790
|
newStart,
|
|
36858
36791
|
newEnd
|
|
36859
36792
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -36686,30 +36686,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
|
36686
36686
|
}
|
|
36687
36687
|
return;
|
|
36688
36688
|
}
|
|
36689
|
-
function findPathPoints(points, grid, obstacles, newStart, newEnd) {
|
|
36690
|
-
if (points.length < 2) {
|
|
36691
|
-
return points;
|
|
36692
|
-
}
|
|
36693
|
-
const finalPath = [points[0]];
|
|
36694
|
-
const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
|
|
36695
|
-
for (let i = 0;i < points.length - 1; i += 1) {
|
|
36696
|
-
const startSegment = points[i];
|
|
36697
|
-
const endSegment = points[i + 1];
|
|
36698
|
-
const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
36699
|
-
if (segmentPath && segmentPath.length > 0) {
|
|
36700
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
36701
|
-
const point5 = segmentPath[j];
|
|
36702
|
-
const key = `${point5.x},${point5.y}`;
|
|
36703
|
-
finalPath.push(point5);
|
|
36704
|
-
existingPathSegments.add(key);
|
|
36705
|
-
}
|
|
36706
|
-
} else {
|
|
36707
|
-
console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
|
|
36708
|
-
return [];
|
|
36709
|
-
}
|
|
36710
|
-
}
|
|
36711
|
-
return finalPath;
|
|
36712
|
-
}
|
|
36713
36689
|
function reducePoints(points) {
|
|
36714
36690
|
const uniquePoints = new Map;
|
|
36715
36691
|
const result = [];
|
|
@@ -36762,91 +36738,48 @@ function reconstructPath(node2) {
|
|
|
36762
36738
|
}
|
|
36763
36739
|
return path2.reverse();
|
|
36764
36740
|
}
|
|
36765
|
-
function
|
|
36766
|
-
|
|
36767
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36768
|
-
console.log("111");
|
|
36769
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
36770
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36771
|
-
}
|
|
36772
|
-
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36773
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36774
|
-
console.log("222");
|
|
36775
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
36776
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36777
|
-
}
|
|
36778
|
-
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36779
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36780
|
-
console.log("333");
|
|
36781
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
36782
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36783
|
-
}
|
|
36784
|
-
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36785
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36786
|
-
console.log("444");
|
|
36787
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
36788
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36789
|
-
}
|
|
36790
|
-
const dx = endPoint.x - startPoint.x;
|
|
36791
|
-
const dy = endPoint.y - startPoint.y;
|
|
36792
|
-
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36793
|
-
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36794
|
-
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36795
|
-
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
36796
|
-
if (startConflictX || endConflictY) {
|
|
36797
|
-
console.log("555");
|
|
36798
|
-
console.log([new Point(startPoint.x, endPoint.y)]);
|
|
36799
|
-
return [new Point(startPoint.x, endPoint.y)];
|
|
36800
|
-
}
|
|
36801
|
-
if (startConflictY || endConflictX) {
|
|
36802
|
-
console.log("666");
|
|
36803
|
-
console.log([new Point(endPoint.x, startPoint.y)]);
|
|
36804
|
-
return [new Point(endPoint.x, startPoint.y)];
|
|
36805
|
-
}
|
|
36806
|
-
return [];
|
|
36807
|
-
}
|
|
36808
|
-
function findClosestValidPointInGrid(point5, grid, obstacles) {
|
|
36809
|
-
let closestPoint = null;
|
|
36741
|
+
function findClosestPointInGrid(point5, grid) {
|
|
36742
|
+
let closestPoint = grid[0][0];
|
|
36810
36743
|
let minDistance = Infinity;
|
|
36811
36744
|
for (const row2 of grid) {
|
|
36812
36745
|
for (const gridPoint of row2) {
|
|
36813
|
-
const
|
|
36814
|
-
if (
|
|
36815
|
-
|
|
36816
|
-
|
|
36817
|
-
minDistance = distance;
|
|
36818
|
-
closestPoint = gridPoint;
|
|
36819
|
-
}
|
|
36746
|
+
const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
|
|
36747
|
+
if (distance < minDistance) {
|
|
36748
|
+
minDistance = distance;
|
|
36749
|
+
closestPoint = gridPoint;
|
|
36820
36750
|
}
|
|
36821
36751
|
}
|
|
36822
36752
|
}
|
|
36823
36753
|
return closestPoint;
|
|
36824
36754
|
}
|
|
36825
36755
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36826
|
-
const
|
|
36827
|
-
|
|
36828
|
-
const endPoint = tempGridInfo.newEnd || end;
|
|
36829
|
-
const startDir = getPointerDirection(start);
|
|
36830
|
-
const endDir = getPointerDirection(end);
|
|
36831
|
-
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36832
|
-
const allWaypoints = [...hookWaypoints, ...toVisitPoints];
|
|
36833
|
-
const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
|
|
36834
|
-
const finalStart = newStart || start;
|
|
36835
|
-
const finalEnd = newEnd || end;
|
|
36836
|
-
const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
|
|
36837
|
-
const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
|
|
36838
|
-
if (snappedAndValidatedPoints.length < 2) {
|
|
36756
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36757
|
+
if (grid.length === 0 || grid[0].length === 0) {
|
|
36839
36758
|
return { lines: [], newStart, newEnd };
|
|
36840
36759
|
}
|
|
36841
|
-
const
|
|
36842
|
-
|
|
36843
|
-
|
|
36760
|
+
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
36761
|
+
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
36762
|
+
const snappedWaypoints = toVisitPoints.map((p3) => findClosestPointInGrid(p3, grid));
|
|
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 };
|
|
36844
36779
|
}
|
|
36845
|
-
|
|
36846
|
-
}, []);
|
|
36847
|
-
const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
|
|
36780
|
+
}
|
|
36848
36781
|
return {
|
|
36849
|
-
lines: getLines(
|
|
36782
|
+
lines: getLines(finalPath),
|
|
36850
36783
|
newStart,
|
|
36851
36784
|
newEnd
|
|
36852
36785
|
};
|
package/dist/esm/node.js
CHANGED
|
@@ -39154,30 +39154,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
|
39154
39154
|
}
|
|
39155
39155
|
return;
|
|
39156
39156
|
}
|
|
39157
|
-
function findPathPoints(points, grid, obstacles, newStart, newEnd) {
|
|
39158
|
-
if (points.length < 2) {
|
|
39159
|
-
return points;
|
|
39160
|
-
}
|
|
39161
|
-
const finalPath = [points[0]];
|
|
39162
|
-
const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
|
|
39163
|
-
for (let i = 0;i < points.length - 1; i += 1) {
|
|
39164
|
-
const startSegment = points[i];
|
|
39165
|
-
const endSegment = points[i + 1];
|
|
39166
|
-
const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
|
|
39167
|
-
if (segmentPath && segmentPath.length > 0) {
|
|
39168
|
-
for (let j = 1;j < segmentPath.length; j++) {
|
|
39169
|
-
const point5 = segmentPath[j];
|
|
39170
|
-
const key = `${point5.x},${point5.y}`;
|
|
39171
|
-
finalPath.push(point5);
|
|
39172
|
-
existingPathSegments.add(key);
|
|
39173
|
-
}
|
|
39174
|
-
} else {
|
|
39175
|
-
console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
|
|
39176
|
-
return [];
|
|
39177
|
-
}
|
|
39178
|
-
}
|
|
39179
|
-
return finalPath;
|
|
39180
|
-
}
|
|
39181
39157
|
function reducePoints(points) {
|
|
39182
39158
|
const uniquePoints = new Map;
|
|
39183
39159
|
const result = [];
|
|
@@ -39230,91 +39206,48 @@ function reconstructPath(node2) {
|
|
|
39230
39206
|
}
|
|
39231
39207
|
return path2.reverse();
|
|
39232
39208
|
}
|
|
39233
|
-
function
|
|
39234
|
-
|
|
39235
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39236
|
-
console.log("111");
|
|
39237
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
39238
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39239
|
-
}
|
|
39240
|
-
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
39241
|
-
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39242
|
-
console.log("222");
|
|
39243
|
-
console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
|
|
39244
|
-
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39245
|
-
}
|
|
39246
|
-
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
39247
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39248
|
-
console.log("333");
|
|
39249
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
39250
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39251
|
-
}
|
|
39252
|
-
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
39253
|
-
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39254
|
-
console.log("444");
|
|
39255
|
-
console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
|
|
39256
|
-
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39257
|
-
}
|
|
39258
|
-
const dx = endPoint.x - startPoint.x;
|
|
39259
|
-
const dy = endPoint.y - startPoint.y;
|
|
39260
|
-
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
39261
|
-
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
39262
|
-
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
39263
|
-
const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
|
|
39264
|
-
if (startConflictX || endConflictY) {
|
|
39265
|
-
console.log("555");
|
|
39266
|
-
console.log([new Point(startPoint.x, endPoint.y)]);
|
|
39267
|
-
return [new Point(startPoint.x, endPoint.y)];
|
|
39268
|
-
}
|
|
39269
|
-
if (startConflictY || endConflictX) {
|
|
39270
|
-
console.log("666");
|
|
39271
|
-
console.log([new Point(endPoint.x, startPoint.y)]);
|
|
39272
|
-
return [new Point(endPoint.x, startPoint.y)];
|
|
39273
|
-
}
|
|
39274
|
-
return [];
|
|
39275
|
-
}
|
|
39276
|
-
function findClosestValidPointInGrid(point5, grid, obstacles) {
|
|
39277
|
-
let closestPoint = null;
|
|
39209
|
+
function findClosestPointInGrid(point5, grid) {
|
|
39210
|
+
let closestPoint = grid[0][0];
|
|
39278
39211
|
let minDistance = Infinity;
|
|
39279
39212
|
for (const row2 of grid) {
|
|
39280
39213
|
for (const gridPoint of row2) {
|
|
39281
|
-
const
|
|
39282
|
-
if (
|
|
39283
|
-
|
|
39284
|
-
|
|
39285
|
-
minDistance = distance;
|
|
39286
|
-
closestPoint = gridPoint;
|
|
39287
|
-
}
|
|
39214
|
+
const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
|
|
39215
|
+
if (distance < minDistance) {
|
|
39216
|
+
minDistance = distance;
|
|
39217
|
+
closestPoint = gridPoint;
|
|
39288
39218
|
}
|
|
39289
39219
|
}
|
|
39290
39220
|
}
|
|
39291
39221
|
return closestPoint;
|
|
39292
39222
|
}
|
|
39293
39223
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
39294
|
-
const
|
|
39295
|
-
|
|
39296
|
-
const endPoint = tempGridInfo.newEnd || end;
|
|
39297
|
-
const startDir = getPointerDirection(start);
|
|
39298
|
-
const endDir = getPointerDirection(end);
|
|
39299
|
-
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
39300
|
-
const allWaypoints = [...hookWaypoints, ...toVisitPoints];
|
|
39301
|
-
const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
|
|
39302
|
-
const finalStart = newStart || start;
|
|
39303
|
-
const finalEnd = newEnd || end;
|
|
39304
|
-
const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
|
|
39305
|
-
const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
|
|
39306
|
-
if (snappedAndValidatedPoints.length < 2) {
|
|
39224
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
39225
|
+
if (grid.length === 0 || grid[0].length === 0) {
|
|
39307
39226
|
return { lines: [], newStart, newEnd };
|
|
39308
39227
|
}
|
|
39309
|
-
const
|
|
39310
|
-
|
|
39311
|
-
|
|
39228
|
+
const searchStart = findClosestPointInGrid(newStart || start, grid);
|
|
39229
|
+
const searchEnd = findClosestPointInGrid(newEnd || end, grid);
|
|
39230
|
+
const snappedWaypoints = toVisitPoints.map((p3) => findClosestPointInGrid(p3, grid));
|
|
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 };
|
|
39312
39247
|
}
|
|
39313
|
-
|
|
39314
|
-
}, []);
|
|
39315
|
-
const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
|
|
39248
|
+
}
|
|
39316
39249
|
return {
|
|
39317
|
-
lines: getLines(
|
|
39250
|
+
lines: getLines(finalPath),
|
|
39318
39251
|
newStart,
|
|
39319
39252
|
newEnd
|
|
39320
39253
|
};
|