microboard-temp 0.5.80 → 0.5.82

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