microboard-temp 0.5.90 → 0.5.92

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.
@@ -36924,6 +36924,20 @@ function reconstructPath(node2) {
36924
36924
  }
36925
36925
  return path2.reverse();
36926
36926
  }
36927
+ function findClosestPointInGrid(point5, grid) {
36928
+ let closestPoint = grid[0][0];
36929
+ let minDistance = Infinity;
36930
+ for (const row2 of grid) {
36931
+ for (const gridPoint of row2) {
36932
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36933
+ if (distance < minDistance) {
36934
+ minDistance = distance;
36935
+ closestPoint = gridPoint;
36936
+ }
36937
+ }
36938
+ }
36939
+ return closestPoint;
36940
+ }
36927
36941
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36928
36942
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
36929
36943
  const midY = (startPoint.y + endPoint.y) / 2;
@@ -36968,19 +36982,25 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36968
36982
  return [];
36969
36983
  }
36970
36984
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36971
- const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36972
- const startPoint = newStart || start;
36973
- const endPoint = newEnd || end;
36985
+ const tempGridInfo = createGrid(start, end);
36986
+ const startPoint = tempGridInfo.newStart || start;
36987
+ const endPoint = tempGridInfo.newEnd || end;
36974
36988
  const startDir = getPointerDirection(start);
36975
36989
  const endDir = getPointerDirection(end);
36976
36990
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36977
- const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36978
- const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36979
- console.log("RESULT", {
36980
- lines: getLines(pathPoints),
36981
- newStart,
36982
- newEnd
36983
- });
36991
+ const allWaypoints = [...hookWaypoints, ...toVisitPoints];
36992
+ const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36993
+ const finalStart = newStart || start;
36994
+ const finalEnd = newEnd || end;
36995
+ const pointsToVisit = [finalStart, ...allWaypoints, finalEnd];
36996
+ const uniquePoints = pointsToVisit.reduce((acc, p3) => {
36997
+ if (!acc.some((existing) => existing.barelyEqual(p3))) {
36998
+ acc.push(p3);
36999
+ }
37000
+ return acc;
37001
+ }, []);
37002
+ const snappedPoints = uniquePoints.map((p3) => findClosestPointInGrid(p3, grid));
37003
+ const pathPoints = findPathPoints(snappedPoints, grid, obstacles, newStart, newEnd);
36984
37004
  return {
36985
37005
  lines: getLines(pathPoints),
36986
37006
  newStart,
package/dist/cjs/index.js CHANGED
@@ -36924,6 +36924,20 @@ function reconstructPath(node2) {
36924
36924
  }
36925
36925
  return path2.reverse();
36926
36926
  }
36927
+ function findClosestPointInGrid(point5, grid) {
36928
+ let closestPoint = grid[0][0];
36929
+ let minDistance = Infinity;
36930
+ for (const row2 of grid) {
36931
+ for (const gridPoint of row2) {
36932
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36933
+ if (distance < minDistance) {
36934
+ minDistance = distance;
36935
+ closestPoint = gridPoint;
36936
+ }
36937
+ }
36938
+ }
36939
+ return closestPoint;
36940
+ }
36927
36941
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36928
36942
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
36929
36943
  const midY = (startPoint.y + endPoint.y) / 2;
@@ -36968,19 +36982,25 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36968
36982
  return [];
36969
36983
  }
36970
36984
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36971
- const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36972
- const startPoint = newStart || start;
36973
- const endPoint = newEnd || end;
36985
+ const tempGridInfo = createGrid(start, end);
36986
+ const startPoint = tempGridInfo.newStart || start;
36987
+ const endPoint = tempGridInfo.newEnd || end;
36974
36988
  const startDir = getPointerDirection(start);
36975
36989
  const endDir = getPointerDirection(end);
36976
36990
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36977
- const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36978
- const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36979
- console.log("RESULT", {
36980
- lines: getLines(pathPoints),
36981
- newStart,
36982
- newEnd
36983
- });
36991
+ const allWaypoints = [...hookWaypoints, ...toVisitPoints];
36992
+ const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36993
+ const finalStart = newStart || start;
36994
+ const finalEnd = newEnd || end;
36995
+ const pointsToVisit = [finalStart, ...allWaypoints, finalEnd];
36996
+ const uniquePoints = pointsToVisit.reduce((acc, p3) => {
36997
+ if (!acc.some((existing) => existing.barelyEqual(p3))) {
36998
+ acc.push(p3);
36999
+ }
37000
+ return acc;
37001
+ }, []);
37002
+ const snappedPoints = uniquePoints.map((p3) => findClosestPointInGrid(p3, grid));
37003
+ const pathPoints = findPathPoints(snappedPoints, grid, obstacles, newStart, newEnd);
36984
37004
  return {
36985
37005
  lines: getLines(pathPoints),
36986
37006
  newStart,
package/dist/cjs/node.js CHANGED
@@ -39397,6 +39397,20 @@ function reconstructPath(node2) {
39397
39397
  }
39398
39398
  return path2.reverse();
39399
39399
  }
39400
+ function findClosestPointInGrid(point5, grid) {
39401
+ let closestPoint = grid[0][0];
39402
+ let minDistance = Infinity;
39403
+ for (const row2 of grid) {
39404
+ for (const gridPoint of row2) {
39405
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39406
+ if (distance < minDistance) {
39407
+ minDistance = distance;
39408
+ closestPoint = gridPoint;
39409
+ }
39410
+ }
39411
+ }
39412
+ return closestPoint;
39413
+ }
39400
39414
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39401
39415
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
39402
39416
  const midY = (startPoint.y + endPoint.y) / 2;
@@ -39441,19 +39455,25 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39441
39455
  return [];
39442
39456
  }
39443
39457
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39444
- const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
39445
- const startPoint = newStart || start;
39446
- const endPoint = newEnd || end;
39458
+ const tempGridInfo = createGrid(start, end);
39459
+ const startPoint = tempGridInfo.newStart || start;
39460
+ const endPoint = tempGridInfo.newEnd || end;
39447
39461
  const startDir = getPointerDirection(start);
39448
39462
  const endDir = getPointerDirection(end);
39449
39463
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
39450
- const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
39451
- const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
39452
- console.log("RESULT", {
39453
- lines: getLines(pathPoints),
39454
- newStart,
39455
- newEnd
39456
- });
39464
+ const allWaypoints = [...hookWaypoints, ...toVisitPoints];
39465
+ const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
39466
+ const finalStart = newStart || start;
39467
+ const finalEnd = newEnd || end;
39468
+ const pointsToVisit = [finalStart, ...allWaypoints, finalEnd];
39469
+ const uniquePoints = pointsToVisit.reduce((acc, p3) => {
39470
+ if (!acc.some((existing) => existing.barelyEqual(p3))) {
39471
+ acc.push(p3);
39472
+ }
39473
+ return acc;
39474
+ }, []);
39475
+ const snappedPoints = uniquePoints.map((p3) => findClosestPointInGrid(p3, grid));
39476
+ const pathPoints = findPathPoints(snappedPoints, grid, obstacles, newStart, newEnd);
39457
39477
  return {
39458
39478
  lines: getLines(pathPoints),
39459
39479
  newStart,
@@ -36769,6 +36769,20 @@ function reconstructPath(node2) {
36769
36769
  }
36770
36770
  return path2.reverse();
36771
36771
  }
36772
+ function findClosestPointInGrid(point5, grid) {
36773
+ let closestPoint = grid[0][0];
36774
+ let minDistance = Infinity;
36775
+ for (const row2 of grid) {
36776
+ for (const gridPoint of row2) {
36777
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36778
+ if (distance < minDistance) {
36779
+ minDistance = distance;
36780
+ closestPoint = gridPoint;
36781
+ }
36782
+ }
36783
+ }
36784
+ return closestPoint;
36785
+ }
36772
36786
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36773
36787
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
36774
36788
  const midY = (startPoint.y + endPoint.y) / 2;
@@ -36813,19 +36827,25 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36813
36827
  return [];
36814
36828
  }
36815
36829
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36816
- const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36817
- const startPoint = newStart || start;
36818
- const endPoint = newEnd || end;
36830
+ const tempGridInfo = createGrid(start, end);
36831
+ const startPoint = tempGridInfo.newStart || start;
36832
+ const endPoint = tempGridInfo.newEnd || end;
36819
36833
  const startDir = getPointerDirection(start);
36820
36834
  const endDir = getPointerDirection(end);
36821
36835
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36822
- const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36823
- const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36824
- console.log("RESULT", {
36825
- lines: getLines(pathPoints),
36826
- newStart,
36827
- newEnd
36828
- });
36836
+ const allWaypoints = [...hookWaypoints, ...toVisitPoints];
36837
+ const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36838
+ const finalStart = newStart || start;
36839
+ const finalEnd = newEnd || end;
36840
+ const pointsToVisit = [finalStart, ...allWaypoints, finalEnd];
36841
+ const uniquePoints = pointsToVisit.reduce((acc, p3) => {
36842
+ if (!acc.some((existing) => existing.barelyEqual(p3))) {
36843
+ acc.push(p3);
36844
+ }
36845
+ return acc;
36846
+ }, []);
36847
+ const snappedPoints = uniquePoints.map((p3) => findClosestPointInGrid(p3, grid));
36848
+ const pathPoints = findPathPoints(snappedPoints, grid, obstacles, newStart, newEnd);
36829
36849
  return {
36830
36850
  lines: getLines(pathPoints),
36831
36851
  newStart,
package/dist/esm/index.js CHANGED
@@ -36762,6 +36762,20 @@ function reconstructPath(node2) {
36762
36762
  }
36763
36763
  return path2.reverse();
36764
36764
  }
36765
+ function findClosestPointInGrid(point5, grid) {
36766
+ let closestPoint = grid[0][0];
36767
+ let minDistance = Infinity;
36768
+ for (const row2 of grid) {
36769
+ for (const gridPoint of row2) {
36770
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36771
+ if (distance < minDistance) {
36772
+ minDistance = distance;
36773
+ closestPoint = gridPoint;
36774
+ }
36775
+ }
36776
+ }
36777
+ return closestPoint;
36778
+ }
36765
36779
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36766
36780
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
36767
36781
  const midY = (startPoint.y + endPoint.y) / 2;
@@ -36806,19 +36820,25 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36806
36820
  return [];
36807
36821
  }
36808
36822
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36809
- const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
36810
- const startPoint = newStart || start;
36811
- const endPoint = newEnd || end;
36823
+ const tempGridInfo = createGrid(start, end);
36824
+ const startPoint = tempGridInfo.newStart || start;
36825
+ const endPoint = tempGridInfo.newEnd || end;
36812
36826
  const startDir = getPointerDirection(start);
36813
36827
  const endDir = getPointerDirection(end);
36814
36828
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36815
- const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
36816
- const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
36817
- console.log("RESULT", {
36818
- lines: getLines(pathPoints),
36819
- newStart,
36820
- newEnd
36821
- });
36829
+ const allWaypoints = [...hookWaypoints, ...toVisitPoints];
36830
+ const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36831
+ const finalStart = newStart || start;
36832
+ const finalEnd = newEnd || end;
36833
+ const pointsToVisit = [finalStart, ...allWaypoints, finalEnd];
36834
+ const uniquePoints = pointsToVisit.reduce((acc, p3) => {
36835
+ if (!acc.some((existing) => existing.barelyEqual(p3))) {
36836
+ acc.push(p3);
36837
+ }
36838
+ return acc;
36839
+ }, []);
36840
+ const snappedPoints = uniquePoints.map((p3) => findClosestPointInGrid(p3, grid));
36841
+ const pathPoints = findPathPoints(snappedPoints, grid, obstacles, newStart, newEnd);
36822
36842
  return {
36823
36843
  lines: getLines(pathPoints),
36824
36844
  newStart,
package/dist/esm/node.js CHANGED
@@ -39230,6 +39230,20 @@ function reconstructPath(node2) {
39230
39230
  }
39231
39231
  return path2.reverse();
39232
39232
  }
39233
+ function findClosestPointInGrid(point5, grid) {
39234
+ let closestPoint = grid[0][0];
39235
+ let minDistance = Infinity;
39236
+ for (const row2 of grid) {
39237
+ for (const gridPoint of row2) {
39238
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39239
+ if (distance < minDistance) {
39240
+ minDistance = distance;
39241
+ closestPoint = gridPoint;
39242
+ }
39243
+ }
39244
+ }
39245
+ return closestPoint;
39246
+ }
39233
39247
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39234
39248
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
39235
39249
  const midY = (startPoint.y + endPoint.y) / 2;
@@ -39274,19 +39288,25 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39274
39288
  return [];
39275
39289
  }
39276
39290
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39277
- const { grid, newStart, newEnd } = createGrid(start, end, toVisitPoints);
39278
- const startPoint = newStart || start;
39279
- const endPoint = newEnd || end;
39291
+ const tempGridInfo = createGrid(start, end);
39292
+ const startPoint = tempGridInfo.newStart || start;
39293
+ const endPoint = tempGridInfo.newEnd || end;
39280
39294
  const startDir = getPointerDirection(start);
39281
39295
  const endDir = getPointerDirection(end);
39282
39296
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
39283
- const points = [startPoint, ...hookWaypoints, ...toVisitPoints, endPoint];
39284
- const pathPoints = findPathPoints(points, grid, obstacles, newStart, newEnd);
39285
- console.log("RESULT", {
39286
- lines: getLines(pathPoints),
39287
- newStart,
39288
- newEnd
39289
- });
39297
+ const allWaypoints = [...hookWaypoints, ...toVisitPoints];
39298
+ const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
39299
+ const finalStart = newStart || start;
39300
+ const finalEnd = newEnd || end;
39301
+ const pointsToVisit = [finalStart, ...allWaypoints, finalEnd];
39302
+ const uniquePoints = pointsToVisit.reduce((acc, p3) => {
39303
+ if (!acc.some((existing) => existing.barelyEqual(p3))) {
39304
+ acc.push(p3);
39305
+ }
39306
+ return acc;
39307
+ }, []);
39308
+ const snappedPoints = uniquePoints.map((p3) => findClosestPointInGrid(p3, grid));
39309
+ const pathPoints = findPathPoints(snappedPoints, grid, obstacles, newStart, newEnd);
39290
39310
  return {
39291
39311
  lines: getLines(pathPoints),
39292
39312
  newStart,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.5.90",
3
+ "version": "0.5.92",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",