microboard-temp 0.5.93 → 0.5.95

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.
@@ -36849,15 +36849,15 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
36849
36849
  return;
36850
36850
  }
36851
36851
  function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36852
- const finalPath = [];
36853
- const existingPathSegments = new Set;
36854
- if (points.length > 0) {
36855
- finalPath.push(points[0]);
36856
- const startKey = `${points[0].x},${points[0].y}`;
36857
- existingPathSegments.add(startKey);
36852
+ if (points.length < 2) {
36853
+ return points;
36858
36854
  }
36855
+ const finalPath = [points[0]];
36856
+ const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
36859
36857
  for (let i = 0;i < points.length - 1; i += 1) {
36860
- const segmentPath = findPath(points[i], points[i + 1], grid, obstacles, existingPathSegments, newStart, newEnd);
36858
+ const startSegment = points[i];
36859
+ const endSegment = points[i + 1];
36860
+ const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
36861
36861
  if (segmentPath && segmentPath.length > 0) {
36862
36862
  for (let j = 1;j < segmentPath.length; j++) {
36863
36863
  const point5 = segmentPath[j];
@@ -36866,8 +36866,8 @@ function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36866
36866
  existingPathSegments.add(key);
36867
36867
  }
36868
36868
  } else {
36869
- points.splice(i + 1, 1);
36870
- i--;
36869
+ console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
36870
+ return [];
36871
36871
  }
36872
36872
  }
36873
36873
  return finalPath;
@@ -36967,20 +36967,6 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36967
36967
  }
36968
36968
  return [];
36969
36969
  }
36970
- function findClosestPointInGrid(point5, grid) {
36971
- let closestPoint = grid[0][0];
36972
- let minDistance = Infinity;
36973
- for (const row2 of grid) {
36974
- for (const gridPoint of row2) {
36975
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36976
- if (distance < minDistance) {
36977
- minDistance = distance;
36978
- closestPoint = gridPoint;
36979
- }
36980
- }
36981
- }
36982
- return closestPoint;
36983
- }
36984
36970
  function findClosestValidPointInGrid(point5, grid, obstacles) {
36985
36971
  let closestPoint = null;
36986
36972
  let minDistance = Infinity;
@@ -36999,7 +36985,7 @@ function findClosestValidPointInGrid(point5, grid, obstacles) {
36999
36985
  return closestPoint;
37000
36986
  }
37001
36987
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
37002
- const tempGridInfo = createGrid(start, end);
36988
+ const tempGridInfo = createGrid(start, end, toVisitPoints);
37003
36989
  const startPoint = tempGridInfo.newStart || start;
37004
36990
  const endPoint = tempGridInfo.newEnd || end;
37005
36991
  const startDir = getPointerDirection(start);
@@ -37009,11 +36995,12 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
37009
36995
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
37010
36996
  const finalStart = newStart || start;
37011
36997
  const finalEnd = newEnd || end;
37012
- const snappedStart = findClosestPointInGrid(finalStart, grid);
37013
- const snappedEnd = findClosestPointInGrid(finalEnd, grid);
37014
- const snappedWaypoints = allWaypoints.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
37015
- const points = [snappedStart, ...snappedWaypoints, snappedEnd];
37016
- const uniquePoints = points.reduce((acc, p3) => {
36998
+ const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
36999
+ const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
37000
+ if (snappedAndValidatedPoints.length < 2) {
37001
+ return { lines: [], newStart, newEnd };
37002
+ }
37003
+ const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
37017
37004
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
37018
37005
  acc.push(p3);
37019
37006
  }
package/dist/cjs/index.js CHANGED
@@ -36849,15 +36849,15 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
36849
36849
  return;
36850
36850
  }
36851
36851
  function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36852
- const finalPath = [];
36853
- const existingPathSegments = new Set;
36854
- if (points.length > 0) {
36855
- finalPath.push(points[0]);
36856
- const startKey = `${points[0].x},${points[0].y}`;
36857
- existingPathSegments.add(startKey);
36852
+ if (points.length < 2) {
36853
+ return points;
36858
36854
  }
36855
+ const finalPath = [points[0]];
36856
+ const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
36859
36857
  for (let i = 0;i < points.length - 1; i += 1) {
36860
- const segmentPath = findPath(points[i], points[i + 1], grid, obstacles, existingPathSegments, newStart, newEnd);
36858
+ const startSegment = points[i];
36859
+ const endSegment = points[i + 1];
36860
+ const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
36861
36861
  if (segmentPath && segmentPath.length > 0) {
36862
36862
  for (let j = 1;j < segmentPath.length; j++) {
36863
36863
  const point5 = segmentPath[j];
@@ -36866,8 +36866,8 @@ function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36866
36866
  existingPathSegments.add(key);
36867
36867
  }
36868
36868
  } else {
36869
- points.splice(i + 1, 1);
36870
- i--;
36869
+ console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
36870
+ return [];
36871
36871
  }
36872
36872
  }
36873
36873
  return finalPath;
@@ -36967,20 +36967,6 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36967
36967
  }
36968
36968
  return [];
36969
36969
  }
36970
- function findClosestPointInGrid(point5, grid) {
36971
- let closestPoint = grid[0][0];
36972
- let minDistance = Infinity;
36973
- for (const row2 of grid) {
36974
- for (const gridPoint of row2) {
36975
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36976
- if (distance < minDistance) {
36977
- minDistance = distance;
36978
- closestPoint = gridPoint;
36979
- }
36980
- }
36981
- }
36982
- return closestPoint;
36983
- }
36984
36970
  function findClosestValidPointInGrid(point5, grid, obstacles) {
36985
36971
  let closestPoint = null;
36986
36972
  let minDistance = Infinity;
@@ -36999,7 +36985,7 @@ function findClosestValidPointInGrid(point5, grid, obstacles) {
36999
36985
  return closestPoint;
37000
36986
  }
37001
36987
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
37002
- const tempGridInfo = createGrid(start, end);
36988
+ const tempGridInfo = createGrid(start, end, toVisitPoints);
37003
36989
  const startPoint = tempGridInfo.newStart || start;
37004
36990
  const endPoint = tempGridInfo.newEnd || end;
37005
36991
  const startDir = getPointerDirection(start);
@@ -37009,11 +36995,12 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
37009
36995
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
37010
36996
  const finalStart = newStart || start;
37011
36997
  const finalEnd = newEnd || end;
37012
- const snappedStart = findClosestPointInGrid(finalStart, grid);
37013
- const snappedEnd = findClosestPointInGrid(finalEnd, grid);
37014
- const snappedWaypoints = allWaypoints.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
37015
- const points = [snappedStart, ...snappedWaypoints, snappedEnd];
37016
- const uniquePoints = points.reduce((acc, p3) => {
36998
+ const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
36999
+ const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
37000
+ if (snappedAndValidatedPoints.length < 2) {
37001
+ return { lines: [], newStart, newEnd };
37002
+ }
37003
+ const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
37017
37004
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
37018
37005
  acc.push(p3);
37019
37006
  }
package/dist/cjs/node.js CHANGED
@@ -39322,15 +39322,15 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
39322
39322
  return;
39323
39323
  }
39324
39324
  function findPathPoints(points, grid, obstacles, newStart, newEnd) {
39325
- const finalPath = [];
39326
- const existingPathSegments = new Set;
39327
- if (points.length > 0) {
39328
- finalPath.push(points[0]);
39329
- const startKey = `${points[0].x},${points[0].y}`;
39330
- existingPathSegments.add(startKey);
39325
+ if (points.length < 2) {
39326
+ return points;
39331
39327
  }
39328
+ const finalPath = [points[0]];
39329
+ const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
39332
39330
  for (let i = 0;i < points.length - 1; i += 1) {
39333
- const segmentPath = findPath(points[i], points[i + 1], grid, obstacles, existingPathSegments, newStart, newEnd);
39331
+ const startSegment = points[i];
39332
+ const endSegment = points[i + 1];
39333
+ const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
39334
39334
  if (segmentPath && segmentPath.length > 0) {
39335
39335
  for (let j = 1;j < segmentPath.length; j++) {
39336
39336
  const point5 = segmentPath[j];
@@ -39339,8 +39339,8 @@ function findPathPoints(points, grid, obstacles, newStart, newEnd) {
39339
39339
  existingPathSegments.add(key);
39340
39340
  }
39341
39341
  } else {
39342
- points.splice(i + 1, 1);
39343
- i--;
39342
+ console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
39343
+ return [];
39344
39344
  }
39345
39345
  }
39346
39346
  return finalPath;
@@ -39440,20 +39440,6 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39440
39440
  }
39441
39441
  return [];
39442
39442
  }
39443
- function findClosestPointInGrid(point5, grid) {
39444
- let closestPoint = grid[0][0];
39445
- let minDistance = Infinity;
39446
- for (const row2 of grid) {
39447
- for (const gridPoint of row2) {
39448
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39449
- if (distance < minDistance) {
39450
- minDistance = distance;
39451
- closestPoint = gridPoint;
39452
- }
39453
- }
39454
- }
39455
- return closestPoint;
39456
- }
39457
39443
  function findClosestValidPointInGrid(point5, grid, obstacles) {
39458
39444
  let closestPoint = null;
39459
39445
  let minDistance = Infinity;
@@ -39472,7 +39458,7 @@ function findClosestValidPointInGrid(point5, grid, obstacles) {
39472
39458
  return closestPoint;
39473
39459
  }
39474
39460
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39475
- const tempGridInfo = createGrid(start, end);
39461
+ const tempGridInfo = createGrid(start, end, toVisitPoints);
39476
39462
  const startPoint = tempGridInfo.newStart || start;
39477
39463
  const endPoint = tempGridInfo.newEnd || end;
39478
39464
  const startDir = getPointerDirection(start);
@@ -39482,11 +39468,12 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39482
39468
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
39483
39469
  const finalStart = newStart || start;
39484
39470
  const finalEnd = newEnd || end;
39485
- const snappedStart = findClosestPointInGrid(finalStart, grid);
39486
- const snappedEnd = findClosestPointInGrid(finalEnd, grid);
39487
- const snappedWaypoints = allWaypoints.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
39488
- const points = [snappedStart, ...snappedWaypoints, snappedEnd];
39489
- const uniquePoints = points.reduce((acc, p3) => {
39471
+ const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
39472
+ const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
39473
+ if (snappedAndValidatedPoints.length < 2) {
39474
+ return { lines: [], newStart, newEnd };
39475
+ }
39476
+ const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
39490
39477
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
39491
39478
  acc.push(p3);
39492
39479
  }
@@ -36694,15 +36694,15 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
36694
36694
  return;
36695
36695
  }
36696
36696
  function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36697
- const finalPath = [];
36698
- const existingPathSegments = new Set;
36699
- if (points.length > 0) {
36700
- finalPath.push(points[0]);
36701
- const startKey = `${points[0].x},${points[0].y}`;
36702
- existingPathSegments.add(startKey);
36697
+ if (points.length < 2) {
36698
+ return points;
36703
36699
  }
36700
+ const finalPath = [points[0]];
36701
+ const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
36704
36702
  for (let i = 0;i < points.length - 1; i += 1) {
36705
- const segmentPath = findPath(points[i], points[i + 1], grid, obstacles, existingPathSegments, newStart, newEnd);
36703
+ const startSegment = points[i];
36704
+ const endSegment = points[i + 1];
36705
+ const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
36706
36706
  if (segmentPath && segmentPath.length > 0) {
36707
36707
  for (let j = 1;j < segmentPath.length; j++) {
36708
36708
  const point5 = segmentPath[j];
@@ -36711,8 +36711,8 @@ function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36711
36711
  existingPathSegments.add(key);
36712
36712
  }
36713
36713
  } else {
36714
- points.splice(i + 1, 1);
36715
- i--;
36714
+ console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
36715
+ return [];
36716
36716
  }
36717
36717
  }
36718
36718
  return finalPath;
@@ -36812,20 +36812,6 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36812
36812
  }
36813
36813
  return [];
36814
36814
  }
36815
- function findClosestPointInGrid(point5, grid) {
36816
- let closestPoint = grid[0][0];
36817
- let minDistance = Infinity;
36818
- for (const row2 of grid) {
36819
- for (const gridPoint of row2) {
36820
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36821
- if (distance < minDistance) {
36822
- minDistance = distance;
36823
- closestPoint = gridPoint;
36824
- }
36825
- }
36826
- }
36827
- return closestPoint;
36828
- }
36829
36815
  function findClosestValidPointInGrid(point5, grid, obstacles) {
36830
36816
  let closestPoint = null;
36831
36817
  let minDistance = Infinity;
@@ -36844,7 +36830,7 @@ function findClosestValidPointInGrid(point5, grid, obstacles) {
36844
36830
  return closestPoint;
36845
36831
  }
36846
36832
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36847
- const tempGridInfo = createGrid(start, end);
36833
+ const tempGridInfo = createGrid(start, end, toVisitPoints);
36848
36834
  const startPoint = tempGridInfo.newStart || start;
36849
36835
  const endPoint = tempGridInfo.newEnd || end;
36850
36836
  const startDir = getPointerDirection(start);
@@ -36854,11 +36840,12 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36854
36840
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36855
36841
  const finalStart = newStart || start;
36856
36842
  const finalEnd = newEnd || end;
36857
- const snappedStart = findClosestPointInGrid(finalStart, grid);
36858
- const snappedEnd = findClosestPointInGrid(finalEnd, grid);
36859
- const snappedWaypoints = allWaypoints.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
36860
- const points = [snappedStart, ...snappedWaypoints, snappedEnd];
36861
- const uniquePoints = points.reduce((acc, p3) => {
36843
+ const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
36844
+ const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
36845
+ if (snappedAndValidatedPoints.length < 2) {
36846
+ return { lines: [], newStart, newEnd };
36847
+ }
36848
+ const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
36862
36849
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
36863
36850
  acc.push(p3);
36864
36851
  }
package/dist/esm/index.js CHANGED
@@ -36687,15 +36687,15 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
36687
36687
  return;
36688
36688
  }
36689
36689
  function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36690
- const finalPath = [];
36691
- const existingPathSegments = new Set;
36692
- if (points.length > 0) {
36693
- finalPath.push(points[0]);
36694
- const startKey = `${points[0].x},${points[0].y}`;
36695
- existingPathSegments.add(startKey);
36690
+ if (points.length < 2) {
36691
+ return points;
36696
36692
  }
36693
+ const finalPath = [points[0]];
36694
+ const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
36697
36695
  for (let i = 0;i < points.length - 1; i += 1) {
36698
- const segmentPath = findPath(points[i], points[i + 1], grid, obstacles, existingPathSegments, newStart, newEnd);
36696
+ const startSegment = points[i];
36697
+ const endSegment = points[i + 1];
36698
+ const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
36699
36699
  if (segmentPath && segmentPath.length > 0) {
36700
36700
  for (let j = 1;j < segmentPath.length; j++) {
36701
36701
  const point5 = segmentPath[j];
@@ -36704,8 +36704,8 @@ function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36704
36704
  existingPathSegments.add(key);
36705
36705
  }
36706
36706
  } else {
36707
- points.splice(i + 1, 1);
36708
- i--;
36707
+ console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
36708
+ return [];
36709
36709
  }
36710
36710
  }
36711
36711
  return finalPath;
@@ -36805,20 +36805,6 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36805
36805
  }
36806
36806
  return [];
36807
36807
  }
36808
- function findClosestPointInGrid(point5, grid) {
36809
- let closestPoint = grid[0][0];
36810
- let minDistance = Infinity;
36811
- for (const row2 of grid) {
36812
- for (const gridPoint of row2) {
36813
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36814
- if (distance < minDistance) {
36815
- minDistance = distance;
36816
- closestPoint = gridPoint;
36817
- }
36818
- }
36819
- }
36820
- return closestPoint;
36821
- }
36822
36808
  function findClosestValidPointInGrid(point5, grid, obstacles) {
36823
36809
  let closestPoint = null;
36824
36810
  let minDistance = Infinity;
@@ -36837,7 +36823,7 @@ function findClosestValidPointInGrid(point5, grid, obstacles) {
36837
36823
  return closestPoint;
36838
36824
  }
36839
36825
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36840
- const tempGridInfo = createGrid(start, end);
36826
+ const tempGridInfo = createGrid(start, end, toVisitPoints);
36841
36827
  const startPoint = tempGridInfo.newStart || start;
36842
36828
  const endPoint = tempGridInfo.newEnd || end;
36843
36829
  const startDir = getPointerDirection(start);
@@ -36847,11 +36833,12 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36847
36833
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36848
36834
  const finalStart = newStart || start;
36849
36835
  const finalEnd = newEnd || end;
36850
- const snappedStart = findClosestPointInGrid(finalStart, grid);
36851
- const snappedEnd = findClosestPointInGrid(finalEnd, grid);
36852
- const snappedWaypoints = allWaypoints.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
36853
- const points = [snappedStart, ...snappedWaypoints, snappedEnd];
36854
- const uniquePoints = points.reduce((acc, p3) => {
36836
+ const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
36837
+ const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
36838
+ if (snappedAndValidatedPoints.length < 2) {
36839
+ return { lines: [], newStart, newEnd };
36840
+ }
36841
+ const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
36855
36842
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
36856
36843
  acc.push(p3);
36857
36844
  }
package/dist/esm/node.js CHANGED
@@ -39155,15 +39155,15 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
39155
39155
  return;
39156
39156
  }
39157
39157
  function findPathPoints(points, grid, obstacles, newStart, newEnd) {
39158
- const finalPath = [];
39159
- const existingPathSegments = new Set;
39160
- if (points.length > 0) {
39161
- finalPath.push(points[0]);
39162
- const startKey = `${points[0].x},${points[0].y}`;
39163
- existingPathSegments.add(startKey);
39158
+ if (points.length < 2) {
39159
+ return points;
39164
39160
  }
39161
+ const finalPath = [points[0]];
39162
+ const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
39165
39163
  for (let i = 0;i < points.length - 1; i += 1) {
39166
- const segmentPath = findPath(points[i], points[i + 1], grid, obstacles, existingPathSegments, newStart, newEnd);
39164
+ const startSegment = points[i];
39165
+ const endSegment = points[i + 1];
39166
+ const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
39167
39167
  if (segmentPath && segmentPath.length > 0) {
39168
39168
  for (let j = 1;j < segmentPath.length; j++) {
39169
39169
  const point5 = segmentPath[j];
@@ -39172,8 +39172,8 @@ function findPathPoints(points, grid, obstacles, newStart, newEnd) {
39172
39172
  existingPathSegments.add(key);
39173
39173
  }
39174
39174
  } else {
39175
- points.splice(i + 1, 1);
39176
- i--;
39175
+ console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
39176
+ return [];
39177
39177
  }
39178
39178
  }
39179
39179
  return finalPath;
@@ -39273,20 +39273,6 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39273
39273
  }
39274
39274
  return [];
39275
39275
  }
39276
- function findClosestPointInGrid(point5, grid) {
39277
- let closestPoint = grid[0][0];
39278
- let minDistance = Infinity;
39279
- for (const row2 of grid) {
39280
- for (const gridPoint of row2) {
39281
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39282
- if (distance < minDistance) {
39283
- minDistance = distance;
39284
- closestPoint = gridPoint;
39285
- }
39286
- }
39287
- }
39288
- return closestPoint;
39289
- }
39290
39276
  function findClosestValidPointInGrid(point5, grid, obstacles) {
39291
39277
  let closestPoint = null;
39292
39278
  let minDistance = Infinity;
@@ -39305,7 +39291,7 @@ function findClosestValidPointInGrid(point5, grid, obstacles) {
39305
39291
  return closestPoint;
39306
39292
  }
39307
39293
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39308
- const tempGridInfo = createGrid(start, end);
39294
+ const tempGridInfo = createGrid(start, end, toVisitPoints);
39309
39295
  const startPoint = tempGridInfo.newStart || start;
39310
39296
  const endPoint = tempGridInfo.newEnd || end;
39311
39297
  const startDir = getPointerDirection(start);
@@ -39315,11 +39301,12 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39315
39301
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
39316
39302
  const finalStart = newStart || start;
39317
39303
  const finalEnd = newEnd || end;
39318
- const snappedStart = findClosestPointInGrid(finalStart, grid);
39319
- const snappedEnd = findClosestPointInGrid(finalEnd, grid);
39320
- const snappedWaypoints = allWaypoints.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
39321
- const points = [snappedStart, ...snappedWaypoints, snappedEnd];
39322
- const uniquePoints = points.reduce((acc, p3) => {
39304
+ const pointsToSnap = [finalStart, ...allWaypoints, finalEnd];
39305
+ const snappedAndValidatedPoints = pointsToSnap.map((p3) => findClosestValidPointInGrid(p3, grid, obstacles)).filter((p3) => p3 !== null);
39306
+ if (snappedAndValidatedPoints.length < 2) {
39307
+ return { lines: [], newStart, newEnd };
39308
+ }
39309
+ const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
39323
39310
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
39324
39311
  acc.push(p3);
39325
39312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.5.93",
3
+ "version": "0.5.95",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",