microboard-temp 0.5.83 → 0.5.85
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 +65 -87
- package/dist/cjs/index.js +65 -87
- package/dist/cjs/node.js +65 -87
- package/dist/esm/browser.js +65 -87
- package/dist/esm/index.js +65 -87
- package/dist/esm/node.js +65 -87
- package/package.json +1 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -36731,45 +36731,50 @@ function createGrid(start, end, toVisitPoints = []) {
|
|
|
36731
36731
|
const startDir = getPointerDirection(start);
|
|
36732
36732
|
const endDir = getPointerDirection(end);
|
|
36733
36733
|
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
36734
|
-
const offset = conf.CONNECTOR_ITEM_OFFSET;
|
|
36735
36734
|
const offsetMap = {
|
|
36736
|
-
top: { x: 0, y: -
|
|
36737
|
-
bottom: { x: 0, y:
|
|
36738
|
-
right: { x:
|
|
36739
|
-
left: { x: -
|
|
36735
|
+
top: { x: 0, y: -conf.CONNECTOR_ITEM_OFFSET },
|
|
36736
|
+
bottom: { x: 0, y: conf.CONNECTOR_ITEM_OFFSET },
|
|
36737
|
+
right: { x: conf.CONNECTOR_ITEM_OFFSET, y: 0 },
|
|
36738
|
+
left: { x: -conf.CONNECTOR_ITEM_OFFSET, y: 0 }
|
|
36740
36739
|
};
|
|
36741
36740
|
const horizontalLines = [];
|
|
36742
36741
|
const verticalLines = [];
|
|
36742
|
+
let newStart;
|
|
36743
|
+
let newEnd;
|
|
36743
36744
|
const processPoint = (point5, dir2) => {
|
|
36744
|
-
if (point5.pointType === "Board")
|
|
36745
|
-
return;
|
|
36746
36745
|
const itemMbr = point5.item.getMbr();
|
|
36747
|
-
const
|
|
36748
|
-
const
|
|
36749
|
-
|
|
36750
|
-
|
|
36746
|
+
const mbrFloored = new Mbr(Math.floor(itemMbr.left), Math.floor(itemMbr.top), Math.floor(itemMbr.right), Math.floor(itemMbr.bottom));
|
|
36747
|
+
const pointOnMbr = mbrFloored.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
36748
|
+
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
36749
|
+
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
36750
|
+
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
36751
|
+
verticalLines.push(mbrFloored.left - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.left, pointOnMbr.x, mbrFloored.right, mbrFloored.right + conf.CONNECTOR_ITEM_OFFSET);
|
|
36752
|
+
horizontalLines.push(mbrFloored.top - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.top, pointOnMbr.y, mbrFloored.bottom, mbrFloored.bottom + conf.CONNECTOR_ITEM_OFFSET);
|
|
36753
|
+
return newPoint;
|
|
36751
36754
|
};
|
|
36752
36755
|
if (start.pointType !== "Board" && startDir) {
|
|
36753
|
-
processPoint(start, startDir);
|
|
36756
|
+
newStart = processPoint(start, startDir);
|
|
36754
36757
|
}
|
|
36755
36758
|
if (end.pointType !== "Board" && endDir) {
|
|
36756
|
-
processPoint(end, endDir);
|
|
36757
|
-
}
|
|
36758
|
-
const
|
|
36759
|
-
|
|
36759
|
+
newEnd = processPoint(end, endDir);
|
|
36760
|
+
}
|
|
36761
|
+
const finalStart = newStart || start;
|
|
36762
|
+
const finalEnd = newEnd || end;
|
|
36763
|
+
const middle = new Point((finalStart.x + finalEnd.x) / 2, (finalStart.y + finalEnd.y) / 2);
|
|
36764
|
+
horizontalLines.push(middle.y, finalStart.y, finalEnd.y);
|
|
36765
|
+
verticalLines.push(middle.x, finalStart.x, finalEnd.x);
|
|
36766
|
+
toVisitPoints.forEach((p3) => {
|
|
36760
36767
|
horizontalLines.push(p3.y);
|
|
36761
36768
|
verticalLines.push(p3.x);
|
|
36762
36769
|
});
|
|
36763
|
-
const middle = new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
36764
|
-
horizontalLines.push(middle.y);
|
|
36765
|
-
verticalLines.push(middle.x);
|
|
36766
36770
|
const uniqueHorizontalLines = Array.from(new Set(horizontalLines)).sort((a2, b) => a2 - b);
|
|
36767
36771
|
const uniqueVerticalLines = Array.from(new Set(verticalLines)).sort((a2, b) => a2 - b);
|
|
36768
36772
|
const grid = uniqueVerticalLines.map((x) => uniqueHorizontalLines.map((y) => new Point(x, y)));
|
|
36769
36773
|
return {
|
|
36770
36774
|
grid,
|
|
36771
|
-
newStart
|
|
36772
|
-
newEnd
|
|
36775
|
+
newStart,
|
|
36776
|
+
newEnd,
|
|
36777
|
+
middlePoint: middle
|
|
36773
36778
|
};
|
|
36774
36779
|
}
|
|
36775
36780
|
function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
@@ -36929,77 +36934,50 @@ function reconstructPath(node2) {
|
|
|
36929
36934
|
}
|
|
36930
36935
|
return path2.reverse();
|
|
36931
36936
|
}
|
|
36937
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36938
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36939
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36940
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36941
|
+
}
|
|
36942
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36943
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36944
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36945
|
+
}
|
|
36946
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36947
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36948
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36949
|
+
}
|
|
36950
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36951
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36952
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36953
|
+
}
|
|
36954
|
+
const dx = endPoint.x - startPoint.x;
|
|
36955
|
+
const dy = endPoint.y - startPoint.y;
|
|
36956
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36957
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36958
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36959
|
+
const endConflictY = endDir === "bottom" && dy > 0 || endDir === "top" && dy < 0;
|
|
36960
|
+
if (startConflictX || endConflictY) {
|
|
36961
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
36962
|
+
}
|
|
36963
|
+
if (startConflictY || endConflictX) {
|
|
36964
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
36965
|
+
}
|
|
36966
|
+
return [];
|
|
36967
|
+
}
|
|
36932
36968
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36969
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36970
|
+
const startPoint = newStart || start;
|
|
36971
|
+
const endPoint = newEnd || end;
|
|
36933
36972
|
const startDir = getPointerDirection(start);
|
|
36934
36973
|
const endDir = getPointerDirection(end);
|
|
36935
|
-
const
|
|
36936
|
-
|
|
36937
|
-
|
|
36938
|
-
const processPoint = (point5, dir2) => {
|
|
36939
|
-
if (point5.pointType === "Board")
|
|
36940
|
-
return point5;
|
|
36941
|
-
const offsetMap = {
|
|
36942
|
-
top: { x: 0, y: -offset },
|
|
36943
|
-
bottom: { x: 0, y: offset },
|
|
36944
|
-
right: { x: offset, y: 0 },
|
|
36945
|
-
left: { x: -offset, y: 0 }
|
|
36946
|
-
};
|
|
36947
|
-
const itemMbr = point5.item.getMbr();
|
|
36948
|
-
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
36949
|
-
const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
36950
|
-
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
36951
|
-
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
36952
|
-
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
36953
|
-
return newPoint;
|
|
36954
|
-
};
|
|
36955
|
-
if (start.pointType !== "Board" && startDir) {
|
|
36956
|
-
startPoint = processPoint(start, startDir);
|
|
36957
|
-
}
|
|
36958
|
-
if (end.pointType !== "Board" && endDir) {
|
|
36959
|
-
endPoint = processPoint(end, endDir);
|
|
36960
|
-
}
|
|
36961
|
-
const stemWaypoints = [];
|
|
36962
|
-
if (startDir) {
|
|
36963
|
-
let stem;
|
|
36964
|
-
if (startDir === "right")
|
|
36965
|
-
stem = new Point(startPoint.x + offset, startPoint.y);
|
|
36966
|
-
else if (startDir === "left")
|
|
36967
|
-
stem = new Point(startPoint.x - offset, startPoint.y);
|
|
36968
|
-
else if (startDir === "bottom")
|
|
36969
|
-
stem = new Point(startPoint.x, startPoint.y + offset);
|
|
36970
|
-
else
|
|
36971
|
-
stem = new Point(startPoint.x, startPoint.y - offset);
|
|
36972
|
-
stemWaypoints.push(stem);
|
|
36973
|
-
}
|
|
36974
|
-
if (endDir) {
|
|
36975
|
-
let stem;
|
|
36976
|
-
if (endDir === "right")
|
|
36977
|
-
stem = new Point(endPoint.x + offset, endPoint.y);
|
|
36978
|
-
else if (endDir === "left")
|
|
36979
|
-
stem = new Point(endPoint.x - offset, endPoint.y);
|
|
36980
|
-
else if (endDir === "bottom")
|
|
36981
|
-
stem = new Point(endPoint.x, endPoint.y + offset);
|
|
36982
|
-
else
|
|
36983
|
-
stem = new Point(endPoint.x, endPoint.y - offset);
|
|
36984
|
-
stemWaypoints.push(stem);
|
|
36985
|
-
}
|
|
36986
|
-
const allGridPoints = [startPoint, endPoint, ...stemWaypoints, ...toVisitPoints];
|
|
36987
|
-
const { grid } = createGrid(startPoint, endPoint, allGridPoints);
|
|
36988
|
-
let finalWaypoints = [startPoint];
|
|
36989
|
-
if (stemWaypoints.length > 0) {
|
|
36990
|
-
finalWaypoints.push(stemWaypoints[0]);
|
|
36991
|
-
}
|
|
36992
|
-
finalWaypoints.push(...toVisitPoints);
|
|
36993
|
-
if (stemWaypoints.length > 1) {
|
|
36994
|
-
finalWaypoints.push(stemWaypoints[1]);
|
|
36995
|
-
}
|
|
36996
|
-
finalWaypoints.push(endPoint);
|
|
36997
|
-
const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
|
|
36998
|
-
const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, startPoint, endPoint);
|
|
36974
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36975
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
36976
|
+
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
36999
36977
|
return {
|
|
37000
36978
|
lines: getLines(pathPoints),
|
|
37001
|
-
newStart
|
|
37002
|
-
newEnd
|
|
36979
|
+
newStart,
|
|
36980
|
+
newEnd
|
|
37003
36981
|
};
|
|
37004
36982
|
}
|
|
37005
36983
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -36731,45 +36731,50 @@ function createGrid(start, end, toVisitPoints = []) {
|
|
|
36731
36731
|
const startDir = getPointerDirection(start);
|
|
36732
36732
|
const endDir = getPointerDirection(end);
|
|
36733
36733
|
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
36734
|
-
const offset = conf.CONNECTOR_ITEM_OFFSET;
|
|
36735
36734
|
const offsetMap = {
|
|
36736
|
-
top: { x: 0, y: -
|
|
36737
|
-
bottom: { x: 0, y:
|
|
36738
|
-
right: { x:
|
|
36739
|
-
left: { x: -
|
|
36735
|
+
top: { x: 0, y: -conf.CONNECTOR_ITEM_OFFSET },
|
|
36736
|
+
bottom: { x: 0, y: conf.CONNECTOR_ITEM_OFFSET },
|
|
36737
|
+
right: { x: conf.CONNECTOR_ITEM_OFFSET, y: 0 },
|
|
36738
|
+
left: { x: -conf.CONNECTOR_ITEM_OFFSET, y: 0 }
|
|
36740
36739
|
};
|
|
36741
36740
|
const horizontalLines = [];
|
|
36742
36741
|
const verticalLines = [];
|
|
36742
|
+
let newStart;
|
|
36743
|
+
let newEnd;
|
|
36743
36744
|
const processPoint = (point5, dir2) => {
|
|
36744
|
-
if (point5.pointType === "Board")
|
|
36745
|
-
return;
|
|
36746
36745
|
const itemMbr = point5.item.getMbr();
|
|
36747
|
-
const
|
|
36748
|
-
const
|
|
36749
|
-
|
|
36750
|
-
|
|
36746
|
+
const mbrFloored = new Mbr(Math.floor(itemMbr.left), Math.floor(itemMbr.top), Math.floor(itemMbr.right), Math.floor(itemMbr.bottom));
|
|
36747
|
+
const pointOnMbr = mbrFloored.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
36748
|
+
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
36749
|
+
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
36750
|
+
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
36751
|
+
verticalLines.push(mbrFloored.left - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.left, pointOnMbr.x, mbrFloored.right, mbrFloored.right + conf.CONNECTOR_ITEM_OFFSET);
|
|
36752
|
+
horizontalLines.push(mbrFloored.top - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.top, pointOnMbr.y, mbrFloored.bottom, mbrFloored.bottom + conf.CONNECTOR_ITEM_OFFSET);
|
|
36753
|
+
return newPoint;
|
|
36751
36754
|
};
|
|
36752
36755
|
if (start.pointType !== "Board" && startDir) {
|
|
36753
|
-
processPoint(start, startDir);
|
|
36756
|
+
newStart = processPoint(start, startDir);
|
|
36754
36757
|
}
|
|
36755
36758
|
if (end.pointType !== "Board" && endDir) {
|
|
36756
|
-
processPoint(end, endDir);
|
|
36757
|
-
}
|
|
36758
|
-
const
|
|
36759
|
-
|
|
36759
|
+
newEnd = processPoint(end, endDir);
|
|
36760
|
+
}
|
|
36761
|
+
const finalStart = newStart || start;
|
|
36762
|
+
const finalEnd = newEnd || end;
|
|
36763
|
+
const middle = new Point((finalStart.x + finalEnd.x) / 2, (finalStart.y + finalEnd.y) / 2);
|
|
36764
|
+
horizontalLines.push(middle.y, finalStart.y, finalEnd.y);
|
|
36765
|
+
verticalLines.push(middle.x, finalStart.x, finalEnd.x);
|
|
36766
|
+
toVisitPoints.forEach((p3) => {
|
|
36760
36767
|
horizontalLines.push(p3.y);
|
|
36761
36768
|
verticalLines.push(p3.x);
|
|
36762
36769
|
});
|
|
36763
|
-
const middle = new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
36764
|
-
horizontalLines.push(middle.y);
|
|
36765
|
-
verticalLines.push(middle.x);
|
|
36766
36770
|
const uniqueHorizontalLines = Array.from(new Set(horizontalLines)).sort((a2, b) => a2 - b);
|
|
36767
36771
|
const uniqueVerticalLines = Array.from(new Set(verticalLines)).sort((a2, b) => a2 - b);
|
|
36768
36772
|
const grid = uniqueVerticalLines.map((x) => uniqueHorizontalLines.map((y) => new Point(x, y)));
|
|
36769
36773
|
return {
|
|
36770
36774
|
grid,
|
|
36771
|
-
newStart
|
|
36772
|
-
newEnd
|
|
36775
|
+
newStart,
|
|
36776
|
+
newEnd,
|
|
36777
|
+
middlePoint: middle
|
|
36773
36778
|
};
|
|
36774
36779
|
}
|
|
36775
36780
|
function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
@@ -36929,77 +36934,50 @@ function reconstructPath(node2) {
|
|
|
36929
36934
|
}
|
|
36930
36935
|
return path2.reverse();
|
|
36931
36936
|
}
|
|
36937
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36938
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36939
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36940
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36941
|
+
}
|
|
36942
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36943
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36944
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36945
|
+
}
|
|
36946
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36947
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36948
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36949
|
+
}
|
|
36950
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36951
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36952
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36953
|
+
}
|
|
36954
|
+
const dx = endPoint.x - startPoint.x;
|
|
36955
|
+
const dy = endPoint.y - startPoint.y;
|
|
36956
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36957
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36958
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36959
|
+
const endConflictY = endDir === "bottom" && dy > 0 || endDir === "top" && dy < 0;
|
|
36960
|
+
if (startConflictX || endConflictY) {
|
|
36961
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
36962
|
+
}
|
|
36963
|
+
if (startConflictY || endConflictX) {
|
|
36964
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
36965
|
+
}
|
|
36966
|
+
return [];
|
|
36967
|
+
}
|
|
36932
36968
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36969
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36970
|
+
const startPoint = newStart || start;
|
|
36971
|
+
const endPoint = newEnd || end;
|
|
36933
36972
|
const startDir = getPointerDirection(start);
|
|
36934
36973
|
const endDir = getPointerDirection(end);
|
|
36935
|
-
const
|
|
36936
|
-
|
|
36937
|
-
|
|
36938
|
-
const processPoint = (point5, dir2) => {
|
|
36939
|
-
if (point5.pointType === "Board")
|
|
36940
|
-
return point5;
|
|
36941
|
-
const offsetMap = {
|
|
36942
|
-
top: { x: 0, y: -offset },
|
|
36943
|
-
bottom: { x: 0, y: offset },
|
|
36944
|
-
right: { x: offset, y: 0 },
|
|
36945
|
-
left: { x: -offset, y: 0 }
|
|
36946
|
-
};
|
|
36947
|
-
const itemMbr = point5.item.getMbr();
|
|
36948
|
-
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
36949
|
-
const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
36950
|
-
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
36951
|
-
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
36952
|
-
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
36953
|
-
return newPoint;
|
|
36954
|
-
};
|
|
36955
|
-
if (start.pointType !== "Board" && startDir) {
|
|
36956
|
-
startPoint = processPoint(start, startDir);
|
|
36957
|
-
}
|
|
36958
|
-
if (end.pointType !== "Board" && endDir) {
|
|
36959
|
-
endPoint = processPoint(end, endDir);
|
|
36960
|
-
}
|
|
36961
|
-
const stemWaypoints = [];
|
|
36962
|
-
if (startDir) {
|
|
36963
|
-
let stem;
|
|
36964
|
-
if (startDir === "right")
|
|
36965
|
-
stem = new Point(startPoint.x + offset, startPoint.y);
|
|
36966
|
-
else if (startDir === "left")
|
|
36967
|
-
stem = new Point(startPoint.x - offset, startPoint.y);
|
|
36968
|
-
else if (startDir === "bottom")
|
|
36969
|
-
stem = new Point(startPoint.x, startPoint.y + offset);
|
|
36970
|
-
else
|
|
36971
|
-
stem = new Point(startPoint.x, startPoint.y - offset);
|
|
36972
|
-
stemWaypoints.push(stem);
|
|
36973
|
-
}
|
|
36974
|
-
if (endDir) {
|
|
36975
|
-
let stem;
|
|
36976
|
-
if (endDir === "right")
|
|
36977
|
-
stem = new Point(endPoint.x + offset, endPoint.y);
|
|
36978
|
-
else if (endDir === "left")
|
|
36979
|
-
stem = new Point(endPoint.x - offset, endPoint.y);
|
|
36980
|
-
else if (endDir === "bottom")
|
|
36981
|
-
stem = new Point(endPoint.x, endPoint.y + offset);
|
|
36982
|
-
else
|
|
36983
|
-
stem = new Point(endPoint.x, endPoint.y - offset);
|
|
36984
|
-
stemWaypoints.push(stem);
|
|
36985
|
-
}
|
|
36986
|
-
const allGridPoints = [startPoint, endPoint, ...stemWaypoints, ...toVisitPoints];
|
|
36987
|
-
const { grid } = createGrid(startPoint, endPoint, allGridPoints);
|
|
36988
|
-
let finalWaypoints = [startPoint];
|
|
36989
|
-
if (stemWaypoints.length > 0) {
|
|
36990
|
-
finalWaypoints.push(stemWaypoints[0]);
|
|
36991
|
-
}
|
|
36992
|
-
finalWaypoints.push(...toVisitPoints);
|
|
36993
|
-
if (stemWaypoints.length > 1) {
|
|
36994
|
-
finalWaypoints.push(stemWaypoints[1]);
|
|
36995
|
-
}
|
|
36996
|
-
finalWaypoints.push(endPoint);
|
|
36997
|
-
const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
|
|
36998
|
-
const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, startPoint, endPoint);
|
|
36974
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36975
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
36976
|
+
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
36999
36977
|
return {
|
|
37000
36978
|
lines: getLines(pathPoints),
|
|
37001
|
-
newStart
|
|
37002
|
-
newEnd
|
|
36979
|
+
newStart,
|
|
36980
|
+
newEnd
|
|
37003
36981
|
};
|
|
37004
36982
|
}
|
|
37005
36983
|
|
package/dist/cjs/node.js
CHANGED
|
@@ -39204,45 +39204,50 @@ function createGrid(start, end, toVisitPoints = []) {
|
|
|
39204
39204
|
const startDir = getPointerDirection(start);
|
|
39205
39205
|
const endDir = getPointerDirection(end);
|
|
39206
39206
|
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
39207
|
-
const offset = conf.CONNECTOR_ITEM_OFFSET;
|
|
39208
39207
|
const offsetMap = {
|
|
39209
|
-
top: { x: 0, y: -
|
|
39210
|
-
bottom: { x: 0, y:
|
|
39211
|
-
right: { x:
|
|
39212
|
-
left: { x: -
|
|
39208
|
+
top: { x: 0, y: -conf.CONNECTOR_ITEM_OFFSET },
|
|
39209
|
+
bottom: { x: 0, y: conf.CONNECTOR_ITEM_OFFSET },
|
|
39210
|
+
right: { x: conf.CONNECTOR_ITEM_OFFSET, y: 0 },
|
|
39211
|
+
left: { x: -conf.CONNECTOR_ITEM_OFFSET, y: 0 }
|
|
39213
39212
|
};
|
|
39214
39213
|
const horizontalLines = [];
|
|
39215
39214
|
const verticalLines = [];
|
|
39215
|
+
let newStart;
|
|
39216
|
+
let newEnd;
|
|
39216
39217
|
const processPoint = (point5, dir2) => {
|
|
39217
|
-
if (point5.pointType === "Board")
|
|
39218
|
-
return;
|
|
39219
39218
|
const itemMbr = point5.item.getMbr();
|
|
39220
|
-
const
|
|
39221
|
-
const
|
|
39222
|
-
|
|
39223
|
-
|
|
39219
|
+
const mbrFloored = new Mbr(Math.floor(itemMbr.left), Math.floor(itemMbr.top), Math.floor(itemMbr.right), Math.floor(itemMbr.bottom));
|
|
39220
|
+
const pointOnMbr = mbrFloored.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
39221
|
+
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
39222
|
+
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
39223
|
+
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
39224
|
+
verticalLines.push(mbrFloored.left - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.left, pointOnMbr.x, mbrFloored.right, mbrFloored.right + conf.CONNECTOR_ITEM_OFFSET);
|
|
39225
|
+
horizontalLines.push(mbrFloored.top - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.top, pointOnMbr.y, mbrFloored.bottom, mbrFloored.bottom + conf.CONNECTOR_ITEM_OFFSET);
|
|
39226
|
+
return newPoint;
|
|
39224
39227
|
};
|
|
39225
39228
|
if (start.pointType !== "Board" && startDir) {
|
|
39226
|
-
processPoint(start, startDir);
|
|
39229
|
+
newStart = processPoint(start, startDir);
|
|
39227
39230
|
}
|
|
39228
39231
|
if (end.pointType !== "Board" && endDir) {
|
|
39229
|
-
processPoint(end, endDir);
|
|
39230
|
-
}
|
|
39231
|
-
const
|
|
39232
|
-
|
|
39232
|
+
newEnd = processPoint(end, endDir);
|
|
39233
|
+
}
|
|
39234
|
+
const finalStart = newStart || start;
|
|
39235
|
+
const finalEnd = newEnd || end;
|
|
39236
|
+
const middle = new Point((finalStart.x + finalEnd.x) / 2, (finalStart.y + finalEnd.y) / 2);
|
|
39237
|
+
horizontalLines.push(middle.y, finalStart.y, finalEnd.y);
|
|
39238
|
+
verticalLines.push(middle.x, finalStart.x, finalEnd.x);
|
|
39239
|
+
toVisitPoints.forEach((p3) => {
|
|
39233
39240
|
horizontalLines.push(p3.y);
|
|
39234
39241
|
verticalLines.push(p3.x);
|
|
39235
39242
|
});
|
|
39236
|
-
const middle = new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
39237
|
-
horizontalLines.push(middle.y);
|
|
39238
|
-
verticalLines.push(middle.x);
|
|
39239
39243
|
const uniqueHorizontalLines = Array.from(new Set(horizontalLines)).sort((a2, b) => a2 - b);
|
|
39240
39244
|
const uniqueVerticalLines = Array.from(new Set(verticalLines)).sort((a2, b) => a2 - b);
|
|
39241
39245
|
const grid = uniqueVerticalLines.map((x) => uniqueHorizontalLines.map((y) => new Point(x, y)));
|
|
39242
39246
|
return {
|
|
39243
39247
|
grid,
|
|
39244
|
-
newStart
|
|
39245
|
-
newEnd
|
|
39248
|
+
newStart,
|
|
39249
|
+
newEnd,
|
|
39250
|
+
middlePoint: middle
|
|
39246
39251
|
};
|
|
39247
39252
|
}
|
|
39248
39253
|
function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
@@ -39402,77 +39407,50 @@ function reconstructPath(node2) {
|
|
|
39402
39407
|
}
|
|
39403
39408
|
return path2.reverse();
|
|
39404
39409
|
}
|
|
39410
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
39411
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
39412
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39413
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39414
|
+
}
|
|
39415
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
39416
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39417
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39418
|
+
}
|
|
39419
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
39420
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39421
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39422
|
+
}
|
|
39423
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
39424
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39425
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39426
|
+
}
|
|
39427
|
+
const dx = endPoint.x - startPoint.x;
|
|
39428
|
+
const dy = endPoint.y - startPoint.y;
|
|
39429
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
39430
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
39431
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
39432
|
+
const endConflictY = endDir === "bottom" && dy > 0 || endDir === "top" && dy < 0;
|
|
39433
|
+
if (startConflictX || endConflictY) {
|
|
39434
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
39435
|
+
}
|
|
39436
|
+
if (startConflictY || endConflictX) {
|
|
39437
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
39438
|
+
}
|
|
39439
|
+
return [];
|
|
39440
|
+
}
|
|
39405
39441
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
39442
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
39443
|
+
const startPoint = newStart || start;
|
|
39444
|
+
const endPoint = newEnd || end;
|
|
39406
39445
|
const startDir = getPointerDirection(start);
|
|
39407
39446
|
const endDir = getPointerDirection(end);
|
|
39408
|
-
const
|
|
39409
|
-
|
|
39410
|
-
|
|
39411
|
-
const processPoint = (point5, dir2) => {
|
|
39412
|
-
if (point5.pointType === "Board")
|
|
39413
|
-
return point5;
|
|
39414
|
-
const offsetMap = {
|
|
39415
|
-
top: { x: 0, y: -offset },
|
|
39416
|
-
bottom: { x: 0, y: offset },
|
|
39417
|
-
right: { x: offset, y: 0 },
|
|
39418
|
-
left: { x: -offset, y: 0 }
|
|
39419
|
-
};
|
|
39420
|
-
const itemMbr = point5.item.getMbr();
|
|
39421
|
-
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
39422
|
-
const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
39423
|
-
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
39424
|
-
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
39425
|
-
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
39426
|
-
return newPoint;
|
|
39427
|
-
};
|
|
39428
|
-
if (start.pointType !== "Board" && startDir) {
|
|
39429
|
-
startPoint = processPoint(start, startDir);
|
|
39430
|
-
}
|
|
39431
|
-
if (end.pointType !== "Board" && endDir) {
|
|
39432
|
-
endPoint = processPoint(end, endDir);
|
|
39433
|
-
}
|
|
39434
|
-
const stemWaypoints = [];
|
|
39435
|
-
if (startDir) {
|
|
39436
|
-
let stem;
|
|
39437
|
-
if (startDir === "right")
|
|
39438
|
-
stem = new Point(startPoint.x + offset, startPoint.y);
|
|
39439
|
-
else if (startDir === "left")
|
|
39440
|
-
stem = new Point(startPoint.x - offset, startPoint.y);
|
|
39441
|
-
else if (startDir === "bottom")
|
|
39442
|
-
stem = new Point(startPoint.x, startPoint.y + offset);
|
|
39443
|
-
else
|
|
39444
|
-
stem = new Point(startPoint.x, startPoint.y - offset);
|
|
39445
|
-
stemWaypoints.push(stem);
|
|
39446
|
-
}
|
|
39447
|
-
if (endDir) {
|
|
39448
|
-
let stem;
|
|
39449
|
-
if (endDir === "right")
|
|
39450
|
-
stem = new Point(endPoint.x + offset, endPoint.y);
|
|
39451
|
-
else if (endDir === "left")
|
|
39452
|
-
stem = new Point(endPoint.x - offset, endPoint.y);
|
|
39453
|
-
else if (endDir === "bottom")
|
|
39454
|
-
stem = new Point(endPoint.x, endPoint.y + offset);
|
|
39455
|
-
else
|
|
39456
|
-
stem = new Point(endPoint.x, endPoint.y - offset);
|
|
39457
|
-
stemWaypoints.push(stem);
|
|
39458
|
-
}
|
|
39459
|
-
const allGridPoints = [startPoint, endPoint, ...stemWaypoints, ...toVisitPoints];
|
|
39460
|
-
const { grid } = createGrid(startPoint, endPoint, allGridPoints);
|
|
39461
|
-
let finalWaypoints = [startPoint];
|
|
39462
|
-
if (stemWaypoints.length > 0) {
|
|
39463
|
-
finalWaypoints.push(stemWaypoints[0]);
|
|
39464
|
-
}
|
|
39465
|
-
finalWaypoints.push(...toVisitPoints);
|
|
39466
|
-
if (stemWaypoints.length > 1) {
|
|
39467
|
-
finalWaypoints.push(stemWaypoints[1]);
|
|
39468
|
-
}
|
|
39469
|
-
finalWaypoints.push(endPoint);
|
|
39470
|
-
const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
|
|
39471
|
-
const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, startPoint, endPoint);
|
|
39447
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
39448
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
39449
|
+
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
39472
39450
|
return {
|
|
39473
39451
|
lines: getLines(pathPoints),
|
|
39474
|
-
newStart
|
|
39475
|
-
newEnd
|
|
39452
|
+
newStart,
|
|
39453
|
+
newEnd
|
|
39476
39454
|
};
|
|
39477
39455
|
}
|
|
39478
39456
|
|
package/dist/esm/browser.js
CHANGED
|
@@ -36576,45 +36576,50 @@ function createGrid(start, end, toVisitPoints = []) {
|
|
|
36576
36576
|
const startDir = getPointerDirection(start);
|
|
36577
36577
|
const endDir = getPointerDirection(end);
|
|
36578
36578
|
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
36579
|
-
const offset = conf.CONNECTOR_ITEM_OFFSET;
|
|
36580
36579
|
const offsetMap = {
|
|
36581
|
-
top: { x: 0, y: -
|
|
36582
|
-
bottom: { x: 0, y:
|
|
36583
|
-
right: { x:
|
|
36584
|
-
left: { x: -
|
|
36580
|
+
top: { x: 0, y: -conf.CONNECTOR_ITEM_OFFSET },
|
|
36581
|
+
bottom: { x: 0, y: conf.CONNECTOR_ITEM_OFFSET },
|
|
36582
|
+
right: { x: conf.CONNECTOR_ITEM_OFFSET, y: 0 },
|
|
36583
|
+
left: { x: -conf.CONNECTOR_ITEM_OFFSET, y: 0 }
|
|
36585
36584
|
};
|
|
36586
36585
|
const horizontalLines = [];
|
|
36587
36586
|
const verticalLines = [];
|
|
36587
|
+
let newStart;
|
|
36588
|
+
let newEnd;
|
|
36588
36589
|
const processPoint = (point5, dir2) => {
|
|
36589
|
-
if (point5.pointType === "Board")
|
|
36590
|
-
return;
|
|
36591
36590
|
const itemMbr = point5.item.getMbr();
|
|
36592
|
-
const
|
|
36593
|
-
const
|
|
36594
|
-
|
|
36595
|
-
|
|
36591
|
+
const mbrFloored = new Mbr(Math.floor(itemMbr.left), Math.floor(itemMbr.top), Math.floor(itemMbr.right), Math.floor(itemMbr.bottom));
|
|
36592
|
+
const pointOnMbr = mbrFloored.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
36593
|
+
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
36594
|
+
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
36595
|
+
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
36596
|
+
verticalLines.push(mbrFloored.left - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.left, pointOnMbr.x, mbrFloored.right, mbrFloored.right + conf.CONNECTOR_ITEM_OFFSET);
|
|
36597
|
+
horizontalLines.push(mbrFloored.top - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.top, pointOnMbr.y, mbrFloored.bottom, mbrFloored.bottom + conf.CONNECTOR_ITEM_OFFSET);
|
|
36598
|
+
return newPoint;
|
|
36596
36599
|
};
|
|
36597
36600
|
if (start.pointType !== "Board" && startDir) {
|
|
36598
|
-
processPoint(start, startDir);
|
|
36601
|
+
newStart = processPoint(start, startDir);
|
|
36599
36602
|
}
|
|
36600
36603
|
if (end.pointType !== "Board" && endDir) {
|
|
36601
|
-
processPoint(end, endDir);
|
|
36602
|
-
}
|
|
36603
|
-
const
|
|
36604
|
-
|
|
36604
|
+
newEnd = processPoint(end, endDir);
|
|
36605
|
+
}
|
|
36606
|
+
const finalStart = newStart || start;
|
|
36607
|
+
const finalEnd = newEnd || end;
|
|
36608
|
+
const middle = new Point((finalStart.x + finalEnd.x) / 2, (finalStart.y + finalEnd.y) / 2);
|
|
36609
|
+
horizontalLines.push(middle.y, finalStart.y, finalEnd.y);
|
|
36610
|
+
verticalLines.push(middle.x, finalStart.x, finalEnd.x);
|
|
36611
|
+
toVisitPoints.forEach((p3) => {
|
|
36605
36612
|
horizontalLines.push(p3.y);
|
|
36606
36613
|
verticalLines.push(p3.x);
|
|
36607
36614
|
});
|
|
36608
|
-
const middle = new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
36609
|
-
horizontalLines.push(middle.y);
|
|
36610
|
-
verticalLines.push(middle.x);
|
|
36611
36615
|
const uniqueHorizontalLines = Array.from(new Set(horizontalLines)).sort((a2, b) => a2 - b);
|
|
36612
36616
|
const uniqueVerticalLines = Array.from(new Set(verticalLines)).sort((a2, b) => a2 - b);
|
|
36613
36617
|
const grid = uniqueVerticalLines.map((x) => uniqueHorizontalLines.map((y) => new Point(x, y)));
|
|
36614
36618
|
return {
|
|
36615
36619
|
grid,
|
|
36616
|
-
newStart
|
|
36617
|
-
newEnd
|
|
36620
|
+
newStart,
|
|
36621
|
+
newEnd,
|
|
36622
|
+
middlePoint: middle
|
|
36618
36623
|
};
|
|
36619
36624
|
}
|
|
36620
36625
|
function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
@@ -36774,77 +36779,50 @@ function reconstructPath(node2) {
|
|
|
36774
36779
|
}
|
|
36775
36780
|
return path2.reverse();
|
|
36776
36781
|
}
|
|
36782
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36783
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36784
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36785
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36786
|
+
}
|
|
36787
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36788
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36789
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36790
|
+
}
|
|
36791
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36792
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36793
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36794
|
+
}
|
|
36795
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36796
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36797
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36798
|
+
}
|
|
36799
|
+
const dx = endPoint.x - startPoint.x;
|
|
36800
|
+
const dy = endPoint.y - startPoint.y;
|
|
36801
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36802
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36803
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36804
|
+
const endConflictY = endDir === "bottom" && dy > 0 || endDir === "top" && dy < 0;
|
|
36805
|
+
if (startConflictX || endConflictY) {
|
|
36806
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
36807
|
+
}
|
|
36808
|
+
if (startConflictY || endConflictX) {
|
|
36809
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
36810
|
+
}
|
|
36811
|
+
return [];
|
|
36812
|
+
}
|
|
36777
36813
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36814
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36815
|
+
const startPoint = newStart || start;
|
|
36816
|
+
const endPoint = newEnd || end;
|
|
36778
36817
|
const startDir = getPointerDirection(start);
|
|
36779
36818
|
const endDir = getPointerDirection(end);
|
|
36780
|
-
const
|
|
36781
|
-
|
|
36782
|
-
|
|
36783
|
-
const processPoint = (point5, dir2) => {
|
|
36784
|
-
if (point5.pointType === "Board")
|
|
36785
|
-
return point5;
|
|
36786
|
-
const offsetMap = {
|
|
36787
|
-
top: { x: 0, y: -offset },
|
|
36788
|
-
bottom: { x: 0, y: offset },
|
|
36789
|
-
right: { x: offset, y: 0 },
|
|
36790
|
-
left: { x: -offset, y: 0 }
|
|
36791
|
-
};
|
|
36792
|
-
const itemMbr = point5.item.getMbr();
|
|
36793
|
-
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
36794
|
-
const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
36795
|
-
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
36796
|
-
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
36797
|
-
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
36798
|
-
return newPoint;
|
|
36799
|
-
};
|
|
36800
|
-
if (start.pointType !== "Board" && startDir) {
|
|
36801
|
-
startPoint = processPoint(start, startDir);
|
|
36802
|
-
}
|
|
36803
|
-
if (end.pointType !== "Board" && endDir) {
|
|
36804
|
-
endPoint = processPoint(end, endDir);
|
|
36805
|
-
}
|
|
36806
|
-
const stemWaypoints = [];
|
|
36807
|
-
if (startDir) {
|
|
36808
|
-
let stem;
|
|
36809
|
-
if (startDir === "right")
|
|
36810
|
-
stem = new Point(startPoint.x + offset, startPoint.y);
|
|
36811
|
-
else if (startDir === "left")
|
|
36812
|
-
stem = new Point(startPoint.x - offset, startPoint.y);
|
|
36813
|
-
else if (startDir === "bottom")
|
|
36814
|
-
stem = new Point(startPoint.x, startPoint.y + offset);
|
|
36815
|
-
else
|
|
36816
|
-
stem = new Point(startPoint.x, startPoint.y - offset);
|
|
36817
|
-
stemWaypoints.push(stem);
|
|
36818
|
-
}
|
|
36819
|
-
if (endDir) {
|
|
36820
|
-
let stem;
|
|
36821
|
-
if (endDir === "right")
|
|
36822
|
-
stem = new Point(endPoint.x + offset, endPoint.y);
|
|
36823
|
-
else if (endDir === "left")
|
|
36824
|
-
stem = new Point(endPoint.x - offset, endPoint.y);
|
|
36825
|
-
else if (endDir === "bottom")
|
|
36826
|
-
stem = new Point(endPoint.x, endPoint.y + offset);
|
|
36827
|
-
else
|
|
36828
|
-
stem = new Point(endPoint.x, endPoint.y - offset);
|
|
36829
|
-
stemWaypoints.push(stem);
|
|
36830
|
-
}
|
|
36831
|
-
const allGridPoints = [startPoint, endPoint, ...stemWaypoints, ...toVisitPoints];
|
|
36832
|
-
const { grid } = createGrid(startPoint, endPoint, allGridPoints);
|
|
36833
|
-
let finalWaypoints = [startPoint];
|
|
36834
|
-
if (stemWaypoints.length > 0) {
|
|
36835
|
-
finalWaypoints.push(stemWaypoints[0]);
|
|
36836
|
-
}
|
|
36837
|
-
finalWaypoints.push(...toVisitPoints);
|
|
36838
|
-
if (stemWaypoints.length > 1) {
|
|
36839
|
-
finalWaypoints.push(stemWaypoints[1]);
|
|
36840
|
-
}
|
|
36841
|
-
finalWaypoints.push(endPoint);
|
|
36842
|
-
const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
|
|
36843
|
-
const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, startPoint, endPoint);
|
|
36819
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36820
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
36821
|
+
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
36844
36822
|
return {
|
|
36845
36823
|
lines: getLines(pathPoints),
|
|
36846
|
-
newStart
|
|
36847
|
-
newEnd
|
|
36824
|
+
newStart,
|
|
36825
|
+
newEnd
|
|
36848
36826
|
};
|
|
36849
36827
|
}
|
|
36850
36828
|
|
package/dist/esm/index.js
CHANGED
|
@@ -36569,45 +36569,50 @@ function createGrid(start, end, toVisitPoints = []) {
|
|
|
36569
36569
|
const startDir = getPointerDirection(start);
|
|
36570
36570
|
const endDir = getPointerDirection(end);
|
|
36571
36571
|
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
36572
|
-
const offset = conf.CONNECTOR_ITEM_OFFSET;
|
|
36573
36572
|
const offsetMap = {
|
|
36574
|
-
top: { x: 0, y: -
|
|
36575
|
-
bottom: { x: 0, y:
|
|
36576
|
-
right: { x:
|
|
36577
|
-
left: { x: -
|
|
36573
|
+
top: { x: 0, y: -conf.CONNECTOR_ITEM_OFFSET },
|
|
36574
|
+
bottom: { x: 0, y: conf.CONNECTOR_ITEM_OFFSET },
|
|
36575
|
+
right: { x: conf.CONNECTOR_ITEM_OFFSET, y: 0 },
|
|
36576
|
+
left: { x: -conf.CONNECTOR_ITEM_OFFSET, y: 0 }
|
|
36578
36577
|
};
|
|
36579
36578
|
const horizontalLines = [];
|
|
36580
36579
|
const verticalLines = [];
|
|
36580
|
+
let newStart;
|
|
36581
|
+
let newEnd;
|
|
36581
36582
|
const processPoint = (point5, dir2) => {
|
|
36582
|
-
if (point5.pointType === "Board")
|
|
36583
|
-
return;
|
|
36584
36583
|
const itemMbr = point5.item.getMbr();
|
|
36585
|
-
const
|
|
36586
|
-
const
|
|
36587
|
-
|
|
36588
|
-
|
|
36584
|
+
const mbrFloored = new Mbr(Math.floor(itemMbr.left), Math.floor(itemMbr.top), Math.floor(itemMbr.right), Math.floor(itemMbr.bottom));
|
|
36585
|
+
const pointOnMbr = mbrFloored.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
36586
|
+
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
36587
|
+
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
36588
|
+
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
36589
|
+
verticalLines.push(mbrFloored.left - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.left, pointOnMbr.x, mbrFloored.right, mbrFloored.right + conf.CONNECTOR_ITEM_OFFSET);
|
|
36590
|
+
horizontalLines.push(mbrFloored.top - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.top, pointOnMbr.y, mbrFloored.bottom, mbrFloored.bottom + conf.CONNECTOR_ITEM_OFFSET);
|
|
36591
|
+
return newPoint;
|
|
36589
36592
|
};
|
|
36590
36593
|
if (start.pointType !== "Board" && startDir) {
|
|
36591
|
-
processPoint(start, startDir);
|
|
36594
|
+
newStart = processPoint(start, startDir);
|
|
36592
36595
|
}
|
|
36593
36596
|
if (end.pointType !== "Board" && endDir) {
|
|
36594
|
-
processPoint(end, endDir);
|
|
36595
|
-
}
|
|
36596
|
-
const
|
|
36597
|
-
|
|
36597
|
+
newEnd = processPoint(end, endDir);
|
|
36598
|
+
}
|
|
36599
|
+
const finalStart = newStart || start;
|
|
36600
|
+
const finalEnd = newEnd || end;
|
|
36601
|
+
const middle = new Point((finalStart.x + finalEnd.x) / 2, (finalStart.y + finalEnd.y) / 2);
|
|
36602
|
+
horizontalLines.push(middle.y, finalStart.y, finalEnd.y);
|
|
36603
|
+
verticalLines.push(middle.x, finalStart.x, finalEnd.x);
|
|
36604
|
+
toVisitPoints.forEach((p3) => {
|
|
36598
36605
|
horizontalLines.push(p3.y);
|
|
36599
36606
|
verticalLines.push(p3.x);
|
|
36600
36607
|
});
|
|
36601
|
-
const middle = new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
36602
|
-
horizontalLines.push(middle.y);
|
|
36603
|
-
verticalLines.push(middle.x);
|
|
36604
36608
|
const uniqueHorizontalLines = Array.from(new Set(horizontalLines)).sort((a2, b) => a2 - b);
|
|
36605
36609
|
const uniqueVerticalLines = Array.from(new Set(verticalLines)).sort((a2, b) => a2 - b);
|
|
36606
36610
|
const grid = uniqueVerticalLines.map((x) => uniqueHorizontalLines.map((y) => new Point(x, y)));
|
|
36607
36611
|
return {
|
|
36608
36612
|
grid,
|
|
36609
|
-
newStart
|
|
36610
|
-
newEnd
|
|
36613
|
+
newStart,
|
|
36614
|
+
newEnd,
|
|
36615
|
+
middlePoint: middle
|
|
36611
36616
|
};
|
|
36612
36617
|
}
|
|
36613
36618
|
function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
@@ -36767,77 +36772,50 @@ function reconstructPath(node2) {
|
|
|
36767
36772
|
}
|
|
36768
36773
|
return path2.reverse();
|
|
36769
36774
|
}
|
|
36775
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
36776
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
36777
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36778
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36779
|
+
}
|
|
36780
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
36781
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
36782
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
36783
|
+
}
|
|
36784
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
36785
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36786
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36787
|
+
}
|
|
36788
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
36789
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
36790
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
36791
|
+
}
|
|
36792
|
+
const dx = endPoint.x - startPoint.x;
|
|
36793
|
+
const dy = endPoint.y - startPoint.y;
|
|
36794
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
36795
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
36796
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
36797
|
+
const endConflictY = endDir === "bottom" && dy > 0 || endDir === "top" && dy < 0;
|
|
36798
|
+
if (startConflictX || endConflictY) {
|
|
36799
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
36800
|
+
}
|
|
36801
|
+
if (startConflictY || endConflictX) {
|
|
36802
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
36803
|
+
}
|
|
36804
|
+
return [];
|
|
36805
|
+
}
|
|
36770
36806
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
36807
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
36808
|
+
const startPoint = newStart || start;
|
|
36809
|
+
const endPoint = newEnd || end;
|
|
36771
36810
|
const startDir = getPointerDirection(start);
|
|
36772
36811
|
const endDir = getPointerDirection(end);
|
|
36773
|
-
const
|
|
36774
|
-
|
|
36775
|
-
|
|
36776
|
-
const processPoint = (point5, dir2) => {
|
|
36777
|
-
if (point5.pointType === "Board")
|
|
36778
|
-
return point5;
|
|
36779
|
-
const offsetMap = {
|
|
36780
|
-
top: { x: 0, y: -offset },
|
|
36781
|
-
bottom: { x: 0, y: offset },
|
|
36782
|
-
right: { x: offset, y: 0 },
|
|
36783
|
-
left: { x: -offset, y: 0 }
|
|
36784
|
-
};
|
|
36785
|
-
const itemMbr = point5.item.getMbr();
|
|
36786
|
-
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
36787
|
-
const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
36788
|
-
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
36789
|
-
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
36790
|
-
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
36791
|
-
return newPoint;
|
|
36792
|
-
};
|
|
36793
|
-
if (start.pointType !== "Board" && startDir) {
|
|
36794
|
-
startPoint = processPoint(start, startDir);
|
|
36795
|
-
}
|
|
36796
|
-
if (end.pointType !== "Board" && endDir) {
|
|
36797
|
-
endPoint = processPoint(end, endDir);
|
|
36798
|
-
}
|
|
36799
|
-
const stemWaypoints = [];
|
|
36800
|
-
if (startDir) {
|
|
36801
|
-
let stem;
|
|
36802
|
-
if (startDir === "right")
|
|
36803
|
-
stem = new Point(startPoint.x + offset, startPoint.y);
|
|
36804
|
-
else if (startDir === "left")
|
|
36805
|
-
stem = new Point(startPoint.x - offset, startPoint.y);
|
|
36806
|
-
else if (startDir === "bottom")
|
|
36807
|
-
stem = new Point(startPoint.x, startPoint.y + offset);
|
|
36808
|
-
else
|
|
36809
|
-
stem = new Point(startPoint.x, startPoint.y - offset);
|
|
36810
|
-
stemWaypoints.push(stem);
|
|
36811
|
-
}
|
|
36812
|
-
if (endDir) {
|
|
36813
|
-
let stem;
|
|
36814
|
-
if (endDir === "right")
|
|
36815
|
-
stem = new Point(endPoint.x + offset, endPoint.y);
|
|
36816
|
-
else if (endDir === "left")
|
|
36817
|
-
stem = new Point(endPoint.x - offset, endPoint.y);
|
|
36818
|
-
else if (endDir === "bottom")
|
|
36819
|
-
stem = new Point(endPoint.x, endPoint.y + offset);
|
|
36820
|
-
else
|
|
36821
|
-
stem = new Point(endPoint.x, endPoint.y - offset);
|
|
36822
|
-
stemWaypoints.push(stem);
|
|
36823
|
-
}
|
|
36824
|
-
const allGridPoints = [startPoint, endPoint, ...stemWaypoints, ...toVisitPoints];
|
|
36825
|
-
const { grid } = createGrid(startPoint, endPoint, allGridPoints);
|
|
36826
|
-
let finalWaypoints = [startPoint];
|
|
36827
|
-
if (stemWaypoints.length > 0) {
|
|
36828
|
-
finalWaypoints.push(stemWaypoints[0]);
|
|
36829
|
-
}
|
|
36830
|
-
finalWaypoints.push(...toVisitPoints);
|
|
36831
|
-
if (stemWaypoints.length > 1) {
|
|
36832
|
-
finalWaypoints.push(stemWaypoints[1]);
|
|
36833
|
-
}
|
|
36834
|
-
finalWaypoints.push(endPoint);
|
|
36835
|
-
const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
|
|
36836
|
-
const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, startPoint, endPoint);
|
|
36812
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
36813
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
36814
|
+
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
36837
36815
|
return {
|
|
36838
36816
|
lines: getLines(pathPoints),
|
|
36839
|
-
newStart
|
|
36840
|
-
newEnd
|
|
36817
|
+
newStart,
|
|
36818
|
+
newEnd
|
|
36841
36819
|
};
|
|
36842
36820
|
}
|
|
36843
36821
|
|
package/dist/esm/node.js
CHANGED
|
@@ -39037,45 +39037,50 @@ function createGrid(start, end, toVisitPoints = []) {
|
|
|
39037
39037
|
const startDir = getPointerDirection(start);
|
|
39038
39038
|
const endDir = getPointerDirection(end);
|
|
39039
39039
|
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
39040
|
-
const offset = conf.CONNECTOR_ITEM_OFFSET;
|
|
39041
39040
|
const offsetMap = {
|
|
39042
|
-
top: { x: 0, y: -
|
|
39043
|
-
bottom: { x: 0, y:
|
|
39044
|
-
right: { x:
|
|
39045
|
-
left: { x: -
|
|
39041
|
+
top: { x: 0, y: -conf.CONNECTOR_ITEM_OFFSET },
|
|
39042
|
+
bottom: { x: 0, y: conf.CONNECTOR_ITEM_OFFSET },
|
|
39043
|
+
right: { x: conf.CONNECTOR_ITEM_OFFSET, y: 0 },
|
|
39044
|
+
left: { x: -conf.CONNECTOR_ITEM_OFFSET, y: 0 }
|
|
39046
39045
|
};
|
|
39047
39046
|
const horizontalLines = [];
|
|
39048
39047
|
const verticalLines = [];
|
|
39048
|
+
let newStart;
|
|
39049
|
+
let newEnd;
|
|
39049
39050
|
const processPoint = (point5, dir2) => {
|
|
39050
|
-
if (point5.pointType === "Board")
|
|
39051
|
-
return;
|
|
39052
39051
|
const itemMbr = point5.item.getMbr();
|
|
39053
|
-
const
|
|
39054
|
-
const
|
|
39055
|
-
|
|
39056
|
-
|
|
39052
|
+
const mbrFloored = new Mbr(Math.floor(itemMbr.left), Math.floor(itemMbr.top), Math.floor(itemMbr.right), Math.floor(itemMbr.bottom));
|
|
39053
|
+
const pointOnMbr = mbrFloored.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
39054
|
+
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
39055
|
+
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
39056
|
+
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
39057
|
+
verticalLines.push(mbrFloored.left - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.left, pointOnMbr.x, mbrFloored.right, mbrFloored.right + conf.CONNECTOR_ITEM_OFFSET);
|
|
39058
|
+
horizontalLines.push(mbrFloored.top - conf.CONNECTOR_ITEM_OFFSET, mbrFloored.top, pointOnMbr.y, mbrFloored.bottom, mbrFloored.bottom + conf.CONNECTOR_ITEM_OFFSET);
|
|
39059
|
+
return newPoint;
|
|
39057
39060
|
};
|
|
39058
39061
|
if (start.pointType !== "Board" && startDir) {
|
|
39059
|
-
processPoint(start, startDir);
|
|
39062
|
+
newStart = processPoint(start, startDir);
|
|
39060
39063
|
}
|
|
39061
39064
|
if (end.pointType !== "Board" && endDir) {
|
|
39062
|
-
processPoint(end, endDir);
|
|
39063
|
-
}
|
|
39064
|
-
const
|
|
39065
|
-
|
|
39065
|
+
newEnd = processPoint(end, endDir);
|
|
39066
|
+
}
|
|
39067
|
+
const finalStart = newStart || start;
|
|
39068
|
+
const finalEnd = newEnd || end;
|
|
39069
|
+
const middle = new Point((finalStart.x + finalEnd.x) / 2, (finalStart.y + finalEnd.y) / 2);
|
|
39070
|
+
horizontalLines.push(middle.y, finalStart.y, finalEnd.y);
|
|
39071
|
+
verticalLines.push(middle.x, finalStart.x, finalEnd.x);
|
|
39072
|
+
toVisitPoints.forEach((p3) => {
|
|
39066
39073
|
horizontalLines.push(p3.y);
|
|
39067
39074
|
verticalLines.push(p3.x);
|
|
39068
39075
|
});
|
|
39069
|
-
const middle = new Point((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
39070
|
-
horizontalLines.push(middle.y);
|
|
39071
|
-
verticalLines.push(middle.x);
|
|
39072
39076
|
const uniqueHorizontalLines = Array.from(new Set(horizontalLines)).sort((a2, b) => a2 - b);
|
|
39073
39077
|
const uniqueVerticalLines = Array.from(new Set(verticalLines)).sort((a2, b) => a2 - b);
|
|
39074
39078
|
const grid = uniqueVerticalLines.map((x) => uniqueHorizontalLines.map((y) => new Point(x, y)));
|
|
39075
39079
|
return {
|
|
39076
39080
|
grid,
|
|
39077
|
-
newStart
|
|
39078
|
-
newEnd
|
|
39081
|
+
newStart,
|
|
39082
|
+
newEnd,
|
|
39083
|
+
middlePoint: middle
|
|
39079
39084
|
};
|
|
39080
39085
|
}
|
|
39081
39086
|
function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
|
|
@@ -39235,77 +39240,50 @@ function reconstructPath(node2) {
|
|
|
39235
39240
|
}
|
|
39236
39241
|
return path2.reverse();
|
|
39237
39242
|
}
|
|
39243
|
+
function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
|
|
39244
|
+
if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
|
|
39245
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39246
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39247
|
+
}
|
|
39248
|
+
if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
|
|
39249
|
+
const midY = (startPoint.y + endPoint.y) / 2;
|
|
39250
|
+
return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
|
|
39251
|
+
}
|
|
39252
|
+
if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
|
|
39253
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39254
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39255
|
+
}
|
|
39256
|
+
if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
|
|
39257
|
+
const midX = (startPoint.x + endPoint.x) / 2;
|
|
39258
|
+
return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
|
|
39259
|
+
}
|
|
39260
|
+
const dx = endPoint.x - startPoint.x;
|
|
39261
|
+
const dy = endPoint.y - startPoint.y;
|
|
39262
|
+
const startConflictX = startDir === "right" && dx < 0 || startDir === "left" && dx > 0;
|
|
39263
|
+
const startConflictY = startDir === "bottom" && dy < 0 || startDir === "top" && dy > 0;
|
|
39264
|
+
const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
|
|
39265
|
+
const endConflictY = endDir === "bottom" && dy > 0 || endDir === "top" && dy < 0;
|
|
39266
|
+
if (startConflictX || endConflictY) {
|
|
39267
|
+
return [new Point(startPoint.x, endPoint.y)];
|
|
39268
|
+
}
|
|
39269
|
+
if (startConflictY || endConflictX) {
|
|
39270
|
+
return [new Point(endPoint.x, startPoint.y)];
|
|
39271
|
+
}
|
|
39272
|
+
return [];
|
|
39273
|
+
}
|
|
39238
39274
|
function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
|
|
39275
|
+
const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
|
|
39276
|
+
const startPoint = newStart || start;
|
|
39277
|
+
const endPoint = newEnd || end;
|
|
39239
39278
|
const startDir = getPointerDirection(start);
|
|
39240
39279
|
const endDir = getPointerDirection(end);
|
|
39241
|
-
const
|
|
39242
|
-
|
|
39243
|
-
|
|
39244
|
-
const processPoint = (point5, dir2) => {
|
|
39245
|
-
if (point5.pointType === "Board")
|
|
39246
|
-
return point5;
|
|
39247
|
-
const offsetMap = {
|
|
39248
|
-
top: { x: 0, y: -offset },
|
|
39249
|
-
bottom: { x: 0, y: offset },
|
|
39250
|
-
right: { x: offset, y: 0 },
|
|
39251
|
-
left: { x: -offset, y: 0 }
|
|
39252
|
-
};
|
|
39253
|
-
const itemMbr = point5.item.getMbr();
|
|
39254
|
-
const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
|
|
39255
|
-
const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
|
|
39256
|
-
const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
|
|
39257
|
-
newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
|
|
39258
|
-
newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
|
|
39259
|
-
return newPoint;
|
|
39260
|
-
};
|
|
39261
|
-
if (start.pointType !== "Board" && startDir) {
|
|
39262
|
-
startPoint = processPoint(start, startDir);
|
|
39263
|
-
}
|
|
39264
|
-
if (end.pointType !== "Board" && endDir) {
|
|
39265
|
-
endPoint = processPoint(end, endDir);
|
|
39266
|
-
}
|
|
39267
|
-
const stemWaypoints = [];
|
|
39268
|
-
if (startDir) {
|
|
39269
|
-
let stem;
|
|
39270
|
-
if (startDir === "right")
|
|
39271
|
-
stem = new Point(startPoint.x + offset, startPoint.y);
|
|
39272
|
-
else if (startDir === "left")
|
|
39273
|
-
stem = new Point(startPoint.x - offset, startPoint.y);
|
|
39274
|
-
else if (startDir === "bottom")
|
|
39275
|
-
stem = new Point(startPoint.x, startPoint.y + offset);
|
|
39276
|
-
else
|
|
39277
|
-
stem = new Point(startPoint.x, startPoint.y - offset);
|
|
39278
|
-
stemWaypoints.push(stem);
|
|
39279
|
-
}
|
|
39280
|
-
if (endDir) {
|
|
39281
|
-
let stem;
|
|
39282
|
-
if (endDir === "right")
|
|
39283
|
-
stem = new Point(endPoint.x + offset, endPoint.y);
|
|
39284
|
-
else if (endDir === "left")
|
|
39285
|
-
stem = new Point(endPoint.x - offset, endPoint.y);
|
|
39286
|
-
else if (endDir === "bottom")
|
|
39287
|
-
stem = new Point(endPoint.x, endPoint.y + offset);
|
|
39288
|
-
else
|
|
39289
|
-
stem = new Point(endPoint.x, endPoint.y - offset);
|
|
39290
|
-
stemWaypoints.push(stem);
|
|
39291
|
-
}
|
|
39292
|
-
const allGridPoints = [startPoint, endPoint, ...stemWaypoints, ...toVisitPoints];
|
|
39293
|
-
const { grid } = createGrid(startPoint, endPoint, allGridPoints);
|
|
39294
|
-
let finalWaypoints = [startPoint];
|
|
39295
|
-
if (stemWaypoints.length > 0) {
|
|
39296
|
-
finalWaypoints.push(stemWaypoints[0]);
|
|
39297
|
-
}
|
|
39298
|
-
finalWaypoints.push(...toVisitPoints);
|
|
39299
|
-
if (stemWaypoints.length > 1) {
|
|
39300
|
-
finalWaypoints.push(stemWaypoints[1]);
|
|
39301
|
-
}
|
|
39302
|
-
finalWaypoints.push(endPoint);
|
|
39303
|
-
const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
|
|
39304
|
-
const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, startPoint, endPoint);
|
|
39280
|
+
const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
|
|
39281
|
+
const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
|
|
39282
|
+
const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
|
|
39305
39283
|
return {
|
|
39306
39284
|
lines: getLines(pathPoints),
|
|
39307
|
-
newStart
|
|
39308
|
-
newEnd
|
|
39285
|
+
newStart,
|
|
39286
|
+
newEnd
|
|
39309
39287
|
};
|
|
39310
39288
|
}
|
|
39311
39289
|
|