microboard-temp 0.5.82 → 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.
@@ -36934,85 +36934,52 @@ function reconstructPath(node2) {
36934
36934
  }
36935
36935
  return path2.reverse();
36936
36936
  }
36937
- function preCalculatePathPoints(start, end) {
36938
- const startDir = getPointerDirection(start);
36939
- const endDir = getPointerDirection(end);
36940
- const offset = conf.CONNECTOR_ITEM_OFFSET;
36941
- let startPoint = start;
36942
- let endPoint = end;
36943
- const stemWaypoints = [];
36944
- const allWaypoints = [];
36945
- const processPoint = (point5, dir2) => {
36946
- if (point5.pointType === "Board") {
36947
- return point5;
36948
- }
36949
- const offsetMap = {
36950
- top: { x: 0, y: -offset },
36951
- bottom: { x: 0, y: offset },
36952
- right: { x: offset, y: 0 },
36953
- left: { x: -offset, y: 0 }
36954
- };
36955
- const itemMbr = point5.item.getMbr();
36956
- const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
36957
- const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
36958
- const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
36959
- newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
36960
- newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
36961
- return newPoint;
36962
- };
36963
- if (start.pointType !== "Board" && startDir) {
36964
- startPoint = processPoint(start, startDir);
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)];
36965
36941
  }
36966
- if (end.pointType !== "Board" && endDir) {
36967
- endPoint = processPoint(end, endDir);
36968
- }
36969
- if (startDir) {
36970
- let stem;
36971
- if (startDir === "right")
36972
- stem = new Point(startPoint.x + offset, startPoint.y);
36973
- else if (startDir === "left")
36974
- stem = new Point(startPoint.x - offset, startPoint.y);
36975
- else if (startDir === "bottom")
36976
- stem = new Point(startPoint.x, startPoint.y + offset);
36977
- else
36978
- stem = new Point(startPoint.x, startPoint.y - offset);
36979
- stemWaypoints.push(stem);
36980
- allWaypoints.push(stem);
36981
- }
36982
- if (endDir) {
36983
- let stem;
36984
- if (endDir === "right")
36985
- stem = new Point(endPoint.x + offset, endPoint.y);
36986
- else if (endDir === "left")
36987
- stem = new Point(endPoint.x - offset, endPoint.y);
36988
- else if (endDir === "bottom")
36989
- stem = new Point(endPoint.x, endPoint.y + offset);
36990
- else
36991
- stem = new Point(endPoint.x, endPoint.y - offset);
36992
- stemWaypoints.push(stem);
36993
- allWaypoints.push(stem);
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)];
36994
36961
  }
36995
- return { startPoint, endPoint, stemWaypoints, allWaypoints };
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 [];
36996
36969
  }
36997
36970
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36998
- const { startPoint, endPoint, stemWaypoints, allWaypoints } = preCalculatePathPoints(start, end);
36999
- const gridPoints = [...allWaypoints, ...toVisitPoints];
37000
- const { grid, newStart, newEnd } = createGrid(start, end, gridPoints);
37001
- let finalWaypoints = [startPoint];
37002
- if (stemWaypoints.length > 0) {
37003
- finalWaypoints.push(stemWaypoints[0]);
37004
- }
37005
- finalWaypoints.push(...toVisitPoints);
37006
- if (stemWaypoints.length > 1) {
37007
- finalWaypoints.push(stemWaypoints[1]);
37008
- }
37009
- finalWaypoints.push(endPoint);
37010
- const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
37011
- const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, newStart, newEnd);
36971
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36972
+ const startPoint = newStart || start;
36973
+ const endPoint = newEnd || end;
36974
+ const startDir = getPointerDirection(start);
36975
+ const endDir = getPointerDirection(end);
36976
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36977
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36978
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
37012
36979
  return {
37013
36980
  lines: getLines(pathPoints),
37014
- newStart: startPoint,
37015
- newEnd: endPoint
36981
+ newStart,
36982
+ newEnd
37016
36983
  };
37017
36984
  }
37018
36985
 
package/dist/cjs/index.js CHANGED
@@ -36934,85 +36934,52 @@ function reconstructPath(node2) {
36934
36934
  }
36935
36935
  return path2.reverse();
36936
36936
  }
36937
- function preCalculatePathPoints(start, end) {
36938
- const startDir = getPointerDirection(start);
36939
- const endDir = getPointerDirection(end);
36940
- const offset = conf.CONNECTOR_ITEM_OFFSET;
36941
- let startPoint = start;
36942
- let endPoint = end;
36943
- const stemWaypoints = [];
36944
- const allWaypoints = [];
36945
- const processPoint = (point5, dir2) => {
36946
- if (point5.pointType === "Board") {
36947
- return point5;
36948
- }
36949
- const offsetMap = {
36950
- top: { x: 0, y: -offset },
36951
- bottom: { x: 0, y: offset },
36952
- right: { x: offset, y: 0 },
36953
- left: { x: -offset, y: 0 }
36954
- };
36955
- const itemMbr = point5.item.getMbr();
36956
- const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
36957
- const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
36958
- const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
36959
- newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
36960
- newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
36961
- return newPoint;
36962
- };
36963
- if (start.pointType !== "Board" && startDir) {
36964
- startPoint = processPoint(start, startDir);
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)];
36965
36941
  }
36966
- if (end.pointType !== "Board" && endDir) {
36967
- endPoint = processPoint(end, endDir);
36968
- }
36969
- if (startDir) {
36970
- let stem;
36971
- if (startDir === "right")
36972
- stem = new Point(startPoint.x + offset, startPoint.y);
36973
- else if (startDir === "left")
36974
- stem = new Point(startPoint.x - offset, startPoint.y);
36975
- else if (startDir === "bottom")
36976
- stem = new Point(startPoint.x, startPoint.y + offset);
36977
- else
36978
- stem = new Point(startPoint.x, startPoint.y - offset);
36979
- stemWaypoints.push(stem);
36980
- allWaypoints.push(stem);
36981
- }
36982
- if (endDir) {
36983
- let stem;
36984
- if (endDir === "right")
36985
- stem = new Point(endPoint.x + offset, endPoint.y);
36986
- else if (endDir === "left")
36987
- stem = new Point(endPoint.x - offset, endPoint.y);
36988
- else if (endDir === "bottom")
36989
- stem = new Point(endPoint.x, endPoint.y + offset);
36990
- else
36991
- stem = new Point(endPoint.x, endPoint.y - offset);
36992
- stemWaypoints.push(stem);
36993
- allWaypoints.push(stem);
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)];
36994
36961
  }
36995
- return { startPoint, endPoint, stemWaypoints, allWaypoints };
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 [];
36996
36969
  }
36997
36970
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36998
- const { startPoint, endPoint, stemWaypoints, allWaypoints } = preCalculatePathPoints(start, end);
36999
- const gridPoints = [...allWaypoints, ...toVisitPoints];
37000
- const { grid, newStart, newEnd } = createGrid(start, end, gridPoints);
37001
- let finalWaypoints = [startPoint];
37002
- if (stemWaypoints.length > 0) {
37003
- finalWaypoints.push(stemWaypoints[0]);
37004
- }
37005
- finalWaypoints.push(...toVisitPoints);
37006
- if (stemWaypoints.length > 1) {
37007
- finalWaypoints.push(stemWaypoints[1]);
37008
- }
37009
- finalWaypoints.push(endPoint);
37010
- const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
37011
- const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, newStart, newEnd);
36971
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36972
+ const startPoint = newStart || start;
36973
+ const endPoint = newEnd || end;
36974
+ const startDir = getPointerDirection(start);
36975
+ const endDir = getPointerDirection(end);
36976
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36977
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36978
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
37012
36979
  return {
37013
36980
  lines: getLines(pathPoints),
37014
- newStart: startPoint,
37015
- newEnd: endPoint
36981
+ newStart,
36982
+ newEnd
37016
36983
  };
37017
36984
  }
37018
36985
 
package/dist/cjs/node.js CHANGED
@@ -39407,85 +39407,52 @@ function reconstructPath(node2) {
39407
39407
  }
39408
39408
  return path2.reverse();
39409
39409
  }
39410
- function preCalculatePathPoints(start, end) {
39411
- const startDir = getPointerDirection(start);
39412
- const endDir = getPointerDirection(end);
39413
- const offset = conf.CONNECTOR_ITEM_OFFSET;
39414
- let startPoint = start;
39415
- let endPoint = end;
39416
- const stemWaypoints = [];
39417
- const allWaypoints = [];
39418
- const processPoint = (point5, dir2) => {
39419
- if (point5.pointType === "Board") {
39420
- return point5;
39421
- }
39422
- const offsetMap = {
39423
- top: { x: 0, y: -offset },
39424
- bottom: { x: 0, y: offset },
39425
- right: { x: offset, y: 0 },
39426
- left: { x: -offset, y: 0 }
39427
- };
39428
- const itemMbr = point5.item.getMbr();
39429
- const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
39430
- const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
39431
- const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
39432
- newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
39433
- newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
39434
- return newPoint;
39435
- };
39436
- if (start.pointType !== "Board" && startDir) {
39437
- startPoint = processPoint(start, startDir);
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)];
39438
39414
  }
39439
- if (end.pointType !== "Board" && endDir) {
39440
- endPoint = processPoint(end, endDir);
39441
- }
39442
- if (startDir) {
39443
- let stem;
39444
- if (startDir === "right")
39445
- stem = new Point(startPoint.x + offset, startPoint.y);
39446
- else if (startDir === "left")
39447
- stem = new Point(startPoint.x - offset, startPoint.y);
39448
- else if (startDir === "bottom")
39449
- stem = new Point(startPoint.x, startPoint.y + offset);
39450
- else
39451
- stem = new Point(startPoint.x, startPoint.y - offset);
39452
- stemWaypoints.push(stem);
39453
- allWaypoints.push(stem);
39454
- }
39455
- if (endDir) {
39456
- let stem;
39457
- if (endDir === "right")
39458
- stem = new Point(endPoint.x + offset, endPoint.y);
39459
- else if (endDir === "left")
39460
- stem = new Point(endPoint.x - offset, endPoint.y);
39461
- else if (endDir === "bottom")
39462
- stem = new Point(endPoint.x, endPoint.y + offset);
39463
- else
39464
- stem = new Point(endPoint.x, endPoint.y - offset);
39465
- stemWaypoints.push(stem);
39466
- allWaypoints.push(stem);
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)];
39467
39434
  }
39468
- return { startPoint, endPoint, stemWaypoints, allWaypoints };
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 [];
39469
39442
  }
39470
39443
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39471
- const { startPoint, endPoint, stemWaypoints, allWaypoints } = preCalculatePathPoints(start, end);
39472
- const gridPoints = [...allWaypoints, ...toVisitPoints];
39473
- const { grid, newStart, newEnd } = createGrid(start, end, gridPoints);
39474
- let finalWaypoints = [startPoint];
39475
- if (stemWaypoints.length > 0) {
39476
- finalWaypoints.push(stemWaypoints[0]);
39477
- }
39478
- finalWaypoints.push(...toVisitPoints);
39479
- if (stemWaypoints.length > 1) {
39480
- finalWaypoints.push(stemWaypoints[1]);
39481
- }
39482
- finalWaypoints.push(endPoint);
39483
- const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
39484
- const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, newStart, newEnd);
39444
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
39445
+ const startPoint = newStart || start;
39446
+ const endPoint = newEnd || end;
39447
+ const startDir = getPointerDirection(start);
39448
+ const endDir = getPointerDirection(end);
39449
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
39450
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
39451
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
39485
39452
  return {
39486
39453
  lines: getLines(pathPoints),
39487
- newStart: startPoint,
39488
- newEnd: endPoint
39454
+ newStart,
39455
+ newEnd
39489
39456
  };
39490
39457
  }
39491
39458
 
@@ -36779,85 +36779,52 @@ function reconstructPath(node2) {
36779
36779
  }
36780
36780
  return path2.reverse();
36781
36781
  }
36782
- function preCalculatePathPoints(start, end) {
36783
- const startDir = getPointerDirection(start);
36784
- const endDir = getPointerDirection(end);
36785
- const offset = conf.CONNECTOR_ITEM_OFFSET;
36786
- let startPoint = start;
36787
- let endPoint = end;
36788
- const stemWaypoints = [];
36789
- const allWaypoints = [];
36790
- const processPoint = (point5, dir2) => {
36791
- if (point5.pointType === "Board") {
36792
- return point5;
36793
- }
36794
- const offsetMap = {
36795
- top: { x: 0, y: -offset },
36796
- bottom: { x: 0, y: offset },
36797
- right: { x: offset, y: 0 },
36798
- left: { x: -offset, y: 0 }
36799
- };
36800
- const itemMbr = point5.item.getMbr();
36801
- const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
36802
- const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
36803
- const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
36804
- newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
36805
- newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
36806
- return newPoint;
36807
- };
36808
- if (start.pointType !== "Board" && startDir) {
36809
- startPoint = processPoint(start, startDir);
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)];
36810
36786
  }
36811
- if (end.pointType !== "Board" && endDir) {
36812
- endPoint = processPoint(end, endDir);
36813
- }
36814
- if (startDir) {
36815
- let stem;
36816
- if (startDir === "right")
36817
- stem = new Point(startPoint.x + offset, startPoint.y);
36818
- else if (startDir === "left")
36819
- stem = new Point(startPoint.x - offset, startPoint.y);
36820
- else if (startDir === "bottom")
36821
- stem = new Point(startPoint.x, startPoint.y + offset);
36822
- else
36823
- stem = new Point(startPoint.x, startPoint.y - offset);
36824
- stemWaypoints.push(stem);
36825
- allWaypoints.push(stem);
36826
- }
36827
- if (endDir) {
36828
- let stem;
36829
- if (endDir === "right")
36830
- stem = new Point(endPoint.x + offset, endPoint.y);
36831
- else if (endDir === "left")
36832
- stem = new Point(endPoint.x - offset, endPoint.y);
36833
- else if (endDir === "bottom")
36834
- stem = new Point(endPoint.x, endPoint.y + offset);
36835
- else
36836
- stem = new Point(endPoint.x, endPoint.y - offset);
36837
- stemWaypoints.push(stem);
36838
- allWaypoints.push(stem);
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)];
36839
36806
  }
36840
- return { startPoint, endPoint, stemWaypoints, allWaypoints };
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 [];
36841
36814
  }
36842
36815
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36843
- const { startPoint, endPoint, stemWaypoints, allWaypoints } = preCalculatePathPoints(start, end);
36844
- const gridPoints = [...allWaypoints, ...toVisitPoints];
36845
- const { grid, newStart, newEnd } = createGrid(start, end, gridPoints);
36846
- let finalWaypoints = [startPoint];
36847
- if (stemWaypoints.length > 0) {
36848
- finalWaypoints.push(stemWaypoints[0]);
36849
- }
36850
- finalWaypoints.push(...toVisitPoints);
36851
- if (stemWaypoints.length > 1) {
36852
- finalWaypoints.push(stemWaypoints[1]);
36853
- }
36854
- finalWaypoints.push(endPoint);
36855
- const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
36856
- const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, newStart, newEnd);
36816
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36817
+ const startPoint = newStart || start;
36818
+ const endPoint = newEnd || end;
36819
+ const startDir = getPointerDirection(start);
36820
+ const endDir = getPointerDirection(end);
36821
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36822
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36823
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36857
36824
  return {
36858
36825
  lines: getLines(pathPoints),
36859
- newStart: startPoint,
36860
- newEnd: endPoint
36826
+ newStart,
36827
+ newEnd
36861
36828
  };
36862
36829
  }
36863
36830
 
package/dist/esm/index.js CHANGED
@@ -36772,85 +36772,52 @@ function reconstructPath(node2) {
36772
36772
  }
36773
36773
  return path2.reverse();
36774
36774
  }
36775
- function preCalculatePathPoints(start, end) {
36776
- const startDir = getPointerDirection(start);
36777
- const endDir = getPointerDirection(end);
36778
- const offset = conf.CONNECTOR_ITEM_OFFSET;
36779
- let startPoint = start;
36780
- let endPoint = end;
36781
- const stemWaypoints = [];
36782
- const allWaypoints = [];
36783
- const processPoint = (point5, dir2) => {
36784
- if (point5.pointType === "Board") {
36785
- return point5;
36786
- }
36787
- const offsetMap = {
36788
- top: { x: 0, y: -offset },
36789
- bottom: { x: 0, y: offset },
36790
- right: { x: offset, y: 0 },
36791
- left: { x: -offset, y: 0 }
36792
- };
36793
- const itemMbr = point5.item.getMbr();
36794
- const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
36795
- const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
36796
- const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
36797
- newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
36798
- newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
36799
- return newPoint;
36800
- };
36801
- if (start.pointType !== "Board" && startDir) {
36802
- startPoint = processPoint(start, startDir);
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)];
36803
36779
  }
36804
- if (end.pointType !== "Board" && endDir) {
36805
- endPoint = processPoint(end, endDir);
36806
- }
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
- allWaypoints.push(stem);
36819
- }
36820
- if (endDir) {
36821
- let stem;
36822
- if (endDir === "right")
36823
- stem = new Point(endPoint.x + offset, endPoint.y);
36824
- else if (endDir === "left")
36825
- stem = new Point(endPoint.x - offset, endPoint.y);
36826
- else if (endDir === "bottom")
36827
- stem = new Point(endPoint.x, endPoint.y + offset);
36828
- else
36829
- stem = new Point(endPoint.x, endPoint.y - offset);
36830
- stemWaypoints.push(stem);
36831
- allWaypoints.push(stem);
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)];
36832
36799
  }
36833
- return { startPoint, endPoint, stemWaypoints, allWaypoints };
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 [];
36834
36807
  }
36835
36808
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36836
- const { startPoint, endPoint, stemWaypoints, allWaypoints } = preCalculatePathPoints(start, end);
36837
- const gridPoints = [...allWaypoints, ...toVisitPoints];
36838
- const { grid, newStart, newEnd } = createGrid(start, end, gridPoints);
36839
- let finalWaypoints = [startPoint];
36840
- if (stemWaypoints.length > 0) {
36841
- finalWaypoints.push(stemWaypoints[0]);
36842
- }
36843
- finalWaypoints.push(...toVisitPoints);
36844
- if (stemWaypoints.length > 1) {
36845
- finalWaypoints.push(stemWaypoints[1]);
36846
- }
36847
- finalWaypoints.push(endPoint);
36848
- const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
36849
- const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, newStart, newEnd);
36809
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36810
+ const startPoint = newStart || start;
36811
+ const endPoint = newEnd || end;
36812
+ const startDir = getPointerDirection(start);
36813
+ const endDir = getPointerDirection(end);
36814
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36815
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36816
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36850
36817
  return {
36851
36818
  lines: getLines(pathPoints),
36852
- newStart: startPoint,
36853
- newEnd: endPoint
36819
+ newStart,
36820
+ newEnd
36854
36821
  };
36855
36822
  }
36856
36823
 
package/dist/esm/node.js CHANGED
@@ -39240,85 +39240,52 @@ function reconstructPath(node2) {
39240
39240
  }
39241
39241
  return path2.reverse();
39242
39242
  }
39243
- function preCalculatePathPoints(start, end) {
39244
- const startDir = getPointerDirection(start);
39245
- const endDir = getPointerDirection(end);
39246
- const offset = conf.CONNECTOR_ITEM_OFFSET;
39247
- let startPoint = start;
39248
- let endPoint = end;
39249
- const stemWaypoints = [];
39250
- const allWaypoints = [];
39251
- const processPoint = (point5, dir2) => {
39252
- if (point5.pointType === "Board") {
39253
- return point5;
39254
- }
39255
- const offsetMap = {
39256
- top: { x: 0, y: -offset },
39257
- bottom: { x: 0, y: offset },
39258
- right: { x: offset, y: 0 },
39259
- left: { x: -offset, y: 0 }
39260
- };
39261
- const itemMbr = point5.item.getMbr();
39262
- const revertMapDir = { top: 0, bottom: 1, right: 2, left: 3 };
39263
- const pointOnMbr = itemMbr.getLines()[revertMapDir[dir2]].getNearestPointOnLineSegment(point5);
39264
- const newPoint = Object.create(Object.getPrototypeOf(point5), Object.getOwnPropertyDescriptors(point5));
39265
- newPoint.x = pointOnMbr.x + offsetMap[dir2].x;
39266
- newPoint.y = pointOnMbr.y + offsetMap[dir2].y;
39267
- return newPoint;
39268
- };
39269
- if (start.pointType !== "Board" && startDir) {
39270
- startPoint = processPoint(start, startDir);
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)];
39271
39247
  }
39272
- if (end.pointType !== "Board" && endDir) {
39273
- endPoint = processPoint(end, endDir);
39274
- }
39275
- if (startDir) {
39276
- let stem;
39277
- if (startDir === "right")
39278
- stem = new Point(startPoint.x + offset, startPoint.y);
39279
- else if (startDir === "left")
39280
- stem = new Point(startPoint.x - offset, startPoint.y);
39281
- else if (startDir === "bottom")
39282
- stem = new Point(startPoint.x, startPoint.y + offset);
39283
- else
39284
- stem = new Point(startPoint.x, startPoint.y - offset);
39285
- stemWaypoints.push(stem);
39286
- allWaypoints.push(stem);
39287
- }
39288
- if (endDir) {
39289
- let stem;
39290
- if (endDir === "right")
39291
- stem = new Point(endPoint.x + offset, endPoint.y);
39292
- else if (endDir === "left")
39293
- stem = new Point(endPoint.x - offset, endPoint.y);
39294
- else if (endDir === "bottom")
39295
- stem = new Point(endPoint.x, endPoint.y + offset);
39296
- else
39297
- stem = new Point(endPoint.x, endPoint.y - offset);
39298
- stemWaypoints.push(stem);
39299
- allWaypoints.push(stem);
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)];
39300
39267
  }
39301
- return { startPoint, endPoint, stemWaypoints, allWaypoints };
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 [];
39302
39275
  }
39303
39276
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39304
- const { startPoint, endPoint, stemWaypoints, allWaypoints } = preCalculatePathPoints(start, end);
39305
- const gridPoints = [...allWaypoints, ...toVisitPoints];
39306
- const { grid, newStart, newEnd } = createGrid(start, end, gridPoints);
39307
- let finalWaypoints = [startPoint];
39308
- if (stemWaypoints.length > 0) {
39309
- finalWaypoints.push(stemWaypoints[0]);
39310
- }
39311
- finalWaypoints.push(...toVisitPoints);
39312
- if (stemWaypoints.length > 1) {
39313
- finalWaypoints.push(stemWaypoints[1]);
39314
- }
39315
- finalWaypoints.push(endPoint);
39316
- const uniqueWaypoints = finalWaypoints.filter((point5, index2, self2) => index2 === 0 || !point5.barelyEqual(self2[index2 - 1]));
39317
- const pathPoints = findPathPoints(uniqueWaypoints, grid, obstacles, newStart, newEnd);
39277
+ const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
39278
+ const startPoint = newStart || start;
39279
+ const endPoint = newEnd || end;
39280
+ const startDir = getPointerDirection(start);
39281
+ const endDir = getPointerDirection(end);
39282
+ const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
39283
+ const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
39284
+ const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
39318
39285
  return {
39319
39286
  lines: getLines(pathPoints),
39320
- newStart: startPoint,
39321
- newEnd: endPoint
39287
+ newStart,
39288
+ newEnd
39322
39289
  };
39323
39290
  }
39324
39291
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.5.82",
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",