microboard-temp 0.5.83 → 0.5.84

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.
@@ -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: -offset },
36737
- bottom: { x: 0, y: offset },
36738
- right: { x: offset, y: 0 },
36739
- left: { x: -offset, y: 0 }
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 pointOnMbrX = point5.x - offsetMap[dir2].x;
36748
- const pointOnMbrY = point5.y - offsetMap[dir2].y;
36749
- verticalLines.push(itemMbr.left - offset, itemMbr.left, pointOnMbrX, itemMbr.right, itemMbr.right + offset);
36750
- horizontalLines.push(itemMbr.top - offset, itemMbr.top, pointOnMbrY, itemMbr.bottom, itemMbr.bottom + offset);
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 allPoints = [start, end, ...toVisitPoints];
36759
- allPoints.forEach((p3) => {
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: start,
36772
- newEnd: end
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,52 @@ 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
+ if (startDir === "right" && dx < 0) {
36957
+ return [new Point(startPoint.x, endPoint.y)];
36958
+ }
36959
+ if (startDir === "left" && dx > 0) {
36960
+ return [new Point(startPoint.x, endPoint.y)];
36961
+ }
36962
+ if (startDir === "bottom" && dy < 0) {
36963
+ return [new Point(endPoint.x, startPoint.y)];
36964
+ }
36965
+ if (startDir === "top" && dy > 0) {
36966
+ return [new Point(endPoint.x, startPoint.y)];
36967
+ }
36968
+ return [];
36969
+ }
36932
36970
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36971
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36972
+ const startPoint = newStart || start;
36973
+ const endPoint = newEnd || end;
36933
36974
  const startDir = getPointerDirection(start);
36934
36975
  const endDir = getPointerDirection(end);
36935
- const offset = conf.CONNECTOR_ITEM_OFFSET;
36936
- let startPoint = start;
36937
- let endPoint = end;
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);
36976
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36977
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36978
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36999
36979
  return {
37000
36980
  lines: getLines(pathPoints),
37001
- newStart: startPoint,
37002
- newEnd: endPoint
36981
+ newStart,
36982
+ newEnd
37003
36983
  };
37004
36984
  }
37005
36985
 
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: -offset },
36737
- bottom: { x: 0, y: offset },
36738
- right: { x: offset, y: 0 },
36739
- left: { x: -offset, y: 0 }
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 pointOnMbrX = point5.x - offsetMap[dir2].x;
36748
- const pointOnMbrY = point5.y - offsetMap[dir2].y;
36749
- verticalLines.push(itemMbr.left - offset, itemMbr.left, pointOnMbrX, itemMbr.right, itemMbr.right + offset);
36750
- horizontalLines.push(itemMbr.top - offset, itemMbr.top, pointOnMbrY, itemMbr.bottom, itemMbr.bottom + offset);
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 allPoints = [start, end, ...toVisitPoints];
36759
- allPoints.forEach((p3) => {
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: start,
36772
- newEnd: end
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,52 @@ 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
+ if (startDir === "right" && dx < 0) {
36957
+ return [new Point(startPoint.x, endPoint.y)];
36958
+ }
36959
+ if (startDir === "left" && dx > 0) {
36960
+ return [new Point(startPoint.x, endPoint.y)];
36961
+ }
36962
+ if (startDir === "bottom" && dy < 0) {
36963
+ return [new Point(endPoint.x, startPoint.y)];
36964
+ }
36965
+ if (startDir === "top" && dy > 0) {
36966
+ return [new Point(endPoint.x, startPoint.y)];
36967
+ }
36968
+ return [];
36969
+ }
36932
36970
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36971
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36972
+ const startPoint = newStart || start;
36973
+ const endPoint = newEnd || end;
36933
36974
  const startDir = getPointerDirection(start);
36934
36975
  const endDir = getPointerDirection(end);
36935
- const offset = conf.CONNECTOR_ITEM_OFFSET;
36936
- let startPoint = start;
36937
- let endPoint = end;
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);
36976
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36977
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36978
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36999
36979
  return {
37000
36980
  lines: getLines(pathPoints),
37001
- newStart: startPoint,
37002
- newEnd: endPoint
36981
+ newStart,
36982
+ newEnd
37003
36983
  };
37004
36984
  }
37005
36985
 
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: -offset },
39210
- bottom: { x: 0, y: offset },
39211
- right: { x: offset, y: 0 },
39212
- left: { x: -offset, y: 0 }
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 pointOnMbrX = point5.x - offsetMap[dir2].x;
39221
- const pointOnMbrY = point5.y - offsetMap[dir2].y;
39222
- verticalLines.push(itemMbr.left - offset, itemMbr.left, pointOnMbrX, itemMbr.right, itemMbr.right + offset);
39223
- horizontalLines.push(itemMbr.top - offset, itemMbr.top, pointOnMbrY, itemMbr.bottom, itemMbr.bottom + offset);
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 allPoints = [start, end, ...toVisitPoints];
39232
- allPoints.forEach((p3) => {
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: start,
39245
- newEnd: end
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,52 @@ 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
+ if (startDir === "right" && dx < 0) {
39430
+ return [new Point(startPoint.x, endPoint.y)];
39431
+ }
39432
+ if (startDir === "left" && dx > 0) {
39433
+ return [new Point(startPoint.x, endPoint.y)];
39434
+ }
39435
+ if (startDir === "bottom" && dy < 0) {
39436
+ return [new Point(endPoint.x, startPoint.y)];
39437
+ }
39438
+ if (startDir === "top" && dy > 0) {
39439
+ return [new Point(endPoint.x, startPoint.y)];
39440
+ }
39441
+ return [];
39442
+ }
39405
39443
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39444
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
39445
+ const startPoint = newStart || start;
39446
+ const endPoint = newEnd || end;
39406
39447
  const startDir = getPointerDirection(start);
39407
39448
  const endDir = getPointerDirection(end);
39408
- const offset = conf.CONNECTOR_ITEM_OFFSET;
39409
- let startPoint = start;
39410
- let endPoint = end;
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);
39449
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
39450
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
39451
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
39472
39452
  return {
39473
39453
  lines: getLines(pathPoints),
39474
- newStart: startPoint,
39475
- newEnd: endPoint
39454
+ newStart,
39455
+ newEnd
39476
39456
  };
39477
39457
  }
39478
39458
 
@@ -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: -offset },
36582
- bottom: { x: 0, y: offset },
36583
- right: { x: offset, y: 0 },
36584
- left: { x: -offset, y: 0 }
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 pointOnMbrX = point5.x - offsetMap[dir2].x;
36593
- const pointOnMbrY = point5.y - offsetMap[dir2].y;
36594
- verticalLines.push(itemMbr.left - offset, itemMbr.left, pointOnMbrX, itemMbr.right, itemMbr.right + offset);
36595
- horizontalLines.push(itemMbr.top - offset, itemMbr.top, pointOnMbrY, itemMbr.bottom, itemMbr.bottom + offset);
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 allPoints = [start, end, ...toVisitPoints];
36604
- allPoints.forEach((p3) => {
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: start,
36617
- newEnd: end
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,52 @@ 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
+ if (startDir === "right" && dx < 0) {
36802
+ return [new Point(startPoint.x, endPoint.y)];
36803
+ }
36804
+ if (startDir === "left" && dx > 0) {
36805
+ return [new Point(startPoint.x, endPoint.y)];
36806
+ }
36807
+ if (startDir === "bottom" && dy < 0) {
36808
+ return [new Point(endPoint.x, startPoint.y)];
36809
+ }
36810
+ if (startDir === "top" && dy > 0) {
36811
+ return [new Point(endPoint.x, startPoint.y)];
36812
+ }
36813
+ return [];
36814
+ }
36777
36815
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36816
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36817
+ const startPoint = newStart || start;
36818
+ const endPoint = newEnd || end;
36778
36819
  const startDir = getPointerDirection(start);
36779
36820
  const endDir = getPointerDirection(end);
36780
- const offset = conf.CONNECTOR_ITEM_OFFSET;
36781
- let startPoint = start;
36782
- let endPoint = end;
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);
36821
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36822
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36823
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36844
36824
  return {
36845
36825
  lines: getLines(pathPoints),
36846
- newStart: startPoint,
36847
- newEnd: endPoint
36826
+ newStart,
36827
+ newEnd
36848
36828
  };
36849
36829
  }
36850
36830
 
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: -offset },
36575
- bottom: { x: 0, y: offset },
36576
- right: { x: offset, y: 0 },
36577
- left: { x: -offset, y: 0 }
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 pointOnMbrX = point5.x - offsetMap[dir2].x;
36586
- const pointOnMbrY = point5.y - offsetMap[dir2].y;
36587
- verticalLines.push(itemMbr.left - offset, itemMbr.left, pointOnMbrX, itemMbr.right, itemMbr.right + offset);
36588
- horizontalLines.push(itemMbr.top - offset, itemMbr.top, pointOnMbrY, itemMbr.bottom, itemMbr.bottom + offset);
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 allPoints = [start, end, ...toVisitPoints];
36597
- allPoints.forEach((p3) => {
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: start,
36610
- newEnd: end
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,52 @@ 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
+ if (startDir === "right" && dx < 0) {
36795
+ return [new Point(startPoint.x, endPoint.y)];
36796
+ }
36797
+ if (startDir === "left" && dx > 0) {
36798
+ return [new Point(startPoint.x, endPoint.y)];
36799
+ }
36800
+ if (startDir === "bottom" && dy < 0) {
36801
+ return [new Point(endPoint.x, startPoint.y)];
36802
+ }
36803
+ if (startDir === "top" && dy > 0) {
36804
+ return [new Point(endPoint.x, startPoint.y)];
36805
+ }
36806
+ return [];
36807
+ }
36770
36808
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36809
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36810
+ const startPoint = newStart || start;
36811
+ const endPoint = newEnd || end;
36771
36812
  const startDir = getPointerDirection(start);
36772
36813
  const endDir = getPointerDirection(end);
36773
- const offset = conf.CONNECTOR_ITEM_OFFSET;
36774
- let startPoint = start;
36775
- let endPoint = end;
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);
36814
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36815
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36816
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36837
36817
  return {
36838
36818
  lines: getLines(pathPoints),
36839
- newStart: startPoint,
36840
- newEnd: endPoint
36819
+ newStart,
36820
+ newEnd
36841
36821
  };
36842
36822
  }
36843
36823
 
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: -offset },
39043
- bottom: { x: 0, y: offset },
39044
- right: { x: offset, y: 0 },
39045
- left: { x: -offset, y: 0 }
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 pointOnMbrX = point5.x - offsetMap[dir2].x;
39054
- const pointOnMbrY = point5.y - offsetMap[dir2].y;
39055
- verticalLines.push(itemMbr.left - offset, itemMbr.left, pointOnMbrX, itemMbr.right, itemMbr.right + offset);
39056
- horizontalLines.push(itemMbr.top - offset, itemMbr.top, pointOnMbrY, itemMbr.bottom, itemMbr.bottom + offset);
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 allPoints = [start, end, ...toVisitPoints];
39065
- allPoints.forEach((p3) => {
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: start,
39078
- newEnd: end
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,52 @@ 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
+ if (startDir === "right" && dx < 0) {
39263
+ return [new Point(startPoint.x, endPoint.y)];
39264
+ }
39265
+ if (startDir === "left" && dx > 0) {
39266
+ return [new Point(startPoint.x, endPoint.y)];
39267
+ }
39268
+ if (startDir === "bottom" && dy < 0) {
39269
+ return [new Point(endPoint.x, startPoint.y)];
39270
+ }
39271
+ if (startDir === "top" && dy > 0) {
39272
+ return [new Point(endPoint.x, startPoint.y)];
39273
+ }
39274
+ return [];
39275
+ }
39238
39276
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39277
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
39278
+ const startPoint = newStart || start;
39279
+ const endPoint = newEnd || end;
39239
39280
  const startDir = getPointerDirection(start);
39240
39281
  const endDir = getPointerDirection(end);
39241
- const offset = conf.CONNECTOR_ITEM_OFFSET;
39242
- let startPoint = start;
39243
- let endPoint = end;
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);
39282
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
39283
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
39284
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
39305
39285
  return {
39306
39286
  lines: getLines(pathPoints),
39307
- newStart: startPoint,
39308
- newEnd: endPoint
39287
+ newStart,
39288
+ newEnd
39309
39289
  };
39310
39290
  }
39311
39291
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.5.83",
3
+ "version": "0.5.84",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",