microboard-temp 0.5.81 → 0.5.83

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