microboard-temp 0.5.95 → 0.5.97

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.
@@ -36848,30 +36848,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
36848
36848
  }
36849
36849
  return;
36850
36850
  }
36851
- function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36852
- if (points.length < 2) {
36853
- return points;
36854
- }
36855
- const finalPath = [points[0]];
36856
- const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
36857
- for (let i = 0;i < points.length - 1; i += 1) {
36858
- const startSegment = points[i];
36859
- const endSegment = points[i + 1];
36860
- const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
36861
- if (segmentPath && segmentPath.length > 0) {
36862
- for (let j = 1;j < segmentPath.length; j++) {
36863
- const point5 = segmentPath[j];
36864
- const key = `${point5.x},${point5.y}`;
36865
- finalPath.push(point5);
36866
- existingPathSegments.add(key);
36867
- }
36868
- } else {
36869
- console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
36870
- return [];
36871
- }
36872
- }
36873
- return finalPath;
36874
- }
36875
36851
  function reducePoints(points) {
36876
36852
  const uniquePoints = new Map;
36877
36853
  const result = [];
@@ -36927,26 +36903,18 @@ function reconstructPath(node2) {
36927
36903
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36928
36904
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
36929
36905
  const midY = (startPoint.y + endPoint.y) / 2;
36930
- console.log("111");
36931
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
36932
36906
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
36933
36907
  }
36934
36908
  if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
36935
36909
  const midY = (startPoint.y + endPoint.y) / 2;
36936
- console.log("222");
36937
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
36938
36910
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
36939
36911
  }
36940
36912
  if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
36941
36913
  const midX = (startPoint.x + endPoint.x) / 2;
36942
- console.log("333");
36943
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
36944
36914
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
36945
36915
  }
36946
36916
  if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
36947
36917
  const midX = (startPoint.x + endPoint.x) / 2;
36948
- console.log("444");
36949
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
36950
36918
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
36951
36919
  }
36952
36920
  const dx = endPoint.x - startPoint.x;
@@ -36956,59 +36924,44 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36956
36924
  const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
36957
36925
  const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
36958
36926
  if (startConflictX || endConflictY) {
36959
- console.log("555");
36960
- console.log([new Point(startPoint.x, endPoint.y)]);
36961
36927
  return [new Point(startPoint.x, endPoint.y)];
36962
36928
  }
36963
36929
  if (startConflictY || endConflictX) {
36964
- console.log("666");
36965
- console.log([new Point(endPoint.x, startPoint.y)]);
36966
36930
  return [new Point(endPoint.x, startPoint.y)];
36967
36931
  }
36968
36932
  return [];
36969
36933
  }
36970
- function findClosestValidPointInGrid(point5, grid, obstacles) {
36971
- let closestPoint = null;
36934
+ function findClosestPointInGrid(point5, grid) {
36935
+ let closestPoint = grid[0][0];
36972
36936
  let minDistance = Infinity;
36973
36937
  for (const row2 of grid) {
36974
36938
  for (const gridPoint of row2) {
36975
- const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
36976
- if (isPointValid) {
36977
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36978
- if (distance < minDistance) {
36979
- minDistance = distance;
36980
- closestPoint = gridPoint;
36981
- }
36939
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36940
+ if (distance < minDistance) {
36941
+ minDistance = distance;
36942
+ closestPoint = gridPoint;
36982
36943
  }
36983
36944
  }
36984
36945
  }
36985
36946
  return closestPoint;
36986
36947
  }
36987
36948
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36988
- const tempGridInfo = createGrid(start, end, toVisitPoints);
36949
+ const tempGridInfo = createGrid(start, end);
36989
36950
  const startPoint = tempGridInfo.newStart || start;
36990
36951
  const endPoint = tempGridInfo.newEnd || end;
36991
36952
  const startDir = getPointerDirection(start);
36992
36953
  const endDir = getPointerDirection(end);
36993
36954
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36994
- const allWaypoints = [...hookWaypoints, ...toVisitPoints];
36995
- const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36996
- const finalStart = newStart || start;
36997
- const finalEnd = newEnd || end;
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) {
36955
+ const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
36956
+ const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
36957
+ if (grid.length === 0 || grid[0].length === 0) {
37001
36958
  return { lines: [], newStart, newEnd };
37002
36959
  }
37003
- const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
37004
- if (!acc.some((existing) => existing.barelyEqual(p3))) {
37005
- acc.push(p3);
37006
- }
37007
- return acc;
37008
- }, []);
37009
- const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
36960
+ const searchStart = findClosestPointInGrid(newStart || start, grid);
36961
+ const searchEnd = findClosestPointInGrid(newEnd || end, grid);
36962
+ const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
37010
36963
  return {
37011
- lines: getLines(pathPoints),
36964
+ lines: pathPoints ? getLines(pathPoints) : [],
37012
36965
  newStart,
37013
36966
  newEnd
37014
36967
  };
package/dist/cjs/index.js CHANGED
@@ -36848,30 +36848,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
36848
36848
  }
36849
36849
  return;
36850
36850
  }
36851
- function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36852
- if (points.length < 2) {
36853
- return points;
36854
- }
36855
- const finalPath = [points[0]];
36856
- const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
36857
- for (let i = 0;i < points.length - 1; i += 1) {
36858
- const startSegment = points[i];
36859
- const endSegment = points[i + 1];
36860
- const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
36861
- if (segmentPath && segmentPath.length > 0) {
36862
- for (let j = 1;j < segmentPath.length; j++) {
36863
- const point5 = segmentPath[j];
36864
- const key = `${point5.x},${point5.y}`;
36865
- finalPath.push(point5);
36866
- existingPathSegments.add(key);
36867
- }
36868
- } else {
36869
- console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
36870
- return [];
36871
- }
36872
- }
36873
- return finalPath;
36874
- }
36875
36851
  function reducePoints(points) {
36876
36852
  const uniquePoints = new Map;
36877
36853
  const result = [];
@@ -36927,26 +36903,18 @@ function reconstructPath(node2) {
36927
36903
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36928
36904
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
36929
36905
  const midY = (startPoint.y + endPoint.y) / 2;
36930
- console.log("111");
36931
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
36932
36906
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
36933
36907
  }
36934
36908
  if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
36935
36909
  const midY = (startPoint.y + endPoint.y) / 2;
36936
- console.log("222");
36937
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
36938
36910
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
36939
36911
  }
36940
36912
  if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
36941
36913
  const midX = (startPoint.x + endPoint.x) / 2;
36942
- console.log("333");
36943
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
36944
36914
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
36945
36915
  }
36946
36916
  if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
36947
36917
  const midX = (startPoint.x + endPoint.x) / 2;
36948
- console.log("444");
36949
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
36950
36918
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
36951
36919
  }
36952
36920
  const dx = endPoint.x - startPoint.x;
@@ -36956,59 +36924,44 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36956
36924
  const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
36957
36925
  const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
36958
36926
  if (startConflictX || endConflictY) {
36959
- console.log("555");
36960
- console.log([new Point(startPoint.x, endPoint.y)]);
36961
36927
  return [new Point(startPoint.x, endPoint.y)];
36962
36928
  }
36963
36929
  if (startConflictY || endConflictX) {
36964
- console.log("666");
36965
- console.log([new Point(endPoint.x, startPoint.y)]);
36966
36930
  return [new Point(endPoint.x, startPoint.y)];
36967
36931
  }
36968
36932
  return [];
36969
36933
  }
36970
- function findClosestValidPointInGrid(point5, grid, obstacles) {
36971
- let closestPoint = null;
36934
+ function findClosestPointInGrid(point5, grid) {
36935
+ let closestPoint = grid[0][0];
36972
36936
  let minDistance = Infinity;
36973
36937
  for (const row2 of grid) {
36974
36938
  for (const gridPoint of row2) {
36975
- const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
36976
- if (isPointValid) {
36977
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36978
- if (distance < minDistance) {
36979
- minDistance = distance;
36980
- closestPoint = gridPoint;
36981
- }
36939
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36940
+ if (distance < minDistance) {
36941
+ minDistance = distance;
36942
+ closestPoint = gridPoint;
36982
36943
  }
36983
36944
  }
36984
36945
  }
36985
36946
  return closestPoint;
36986
36947
  }
36987
36948
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36988
- const tempGridInfo = createGrid(start, end, toVisitPoints);
36949
+ const tempGridInfo = createGrid(start, end);
36989
36950
  const startPoint = tempGridInfo.newStart || start;
36990
36951
  const endPoint = tempGridInfo.newEnd || end;
36991
36952
  const startDir = getPointerDirection(start);
36992
36953
  const endDir = getPointerDirection(end);
36993
36954
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36994
- const allWaypoints = [...hookWaypoints, ...toVisitPoints];
36995
- const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36996
- const finalStart = newStart || start;
36997
- const finalEnd = newEnd || end;
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) {
36955
+ const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
36956
+ const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
36957
+ if (grid.length === 0 || grid[0].length === 0) {
37001
36958
  return { lines: [], newStart, newEnd };
37002
36959
  }
37003
- const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
37004
- if (!acc.some((existing) => existing.barelyEqual(p3))) {
37005
- acc.push(p3);
37006
- }
37007
- return acc;
37008
- }, []);
37009
- const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
36960
+ const searchStart = findClosestPointInGrid(newStart || start, grid);
36961
+ const searchEnd = findClosestPointInGrid(newEnd || end, grid);
36962
+ const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
37010
36963
  return {
37011
- lines: getLines(pathPoints),
36964
+ lines: pathPoints ? getLines(pathPoints) : [],
37012
36965
  newStart,
37013
36966
  newEnd
37014
36967
  };
package/dist/cjs/node.js CHANGED
@@ -39321,30 +39321,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
39321
39321
  }
39322
39322
  return;
39323
39323
  }
39324
- function findPathPoints(points, grid, obstacles, newStart, newEnd) {
39325
- if (points.length < 2) {
39326
- return points;
39327
- }
39328
- const finalPath = [points[0]];
39329
- const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
39330
- for (let i = 0;i < points.length - 1; i += 1) {
39331
- const startSegment = points[i];
39332
- const endSegment = points[i + 1];
39333
- const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
39334
- if (segmentPath && segmentPath.length > 0) {
39335
- for (let j = 1;j < segmentPath.length; j++) {
39336
- const point5 = segmentPath[j];
39337
- const key = `${point5.x},${point5.y}`;
39338
- finalPath.push(point5);
39339
- existingPathSegments.add(key);
39340
- }
39341
- } else {
39342
- console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
39343
- return [];
39344
- }
39345
- }
39346
- return finalPath;
39347
- }
39348
39324
  function reducePoints(points) {
39349
39325
  const uniquePoints = new Map;
39350
39326
  const result = [];
@@ -39400,26 +39376,18 @@ function reconstructPath(node2) {
39400
39376
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39401
39377
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
39402
39378
  const midY = (startPoint.y + endPoint.y) / 2;
39403
- console.log("111");
39404
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
39405
39379
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
39406
39380
  }
39407
39381
  if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
39408
39382
  const midY = (startPoint.y + endPoint.y) / 2;
39409
- console.log("222");
39410
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
39411
39383
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
39412
39384
  }
39413
39385
  if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
39414
39386
  const midX = (startPoint.x + endPoint.x) / 2;
39415
- console.log("333");
39416
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
39417
39387
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
39418
39388
  }
39419
39389
  if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
39420
39390
  const midX = (startPoint.x + endPoint.x) / 2;
39421
- console.log("444");
39422
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
39423
39391
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
39424
39392
  }
39425
39393
  const dx = endPoint.x - startPoint.x;
@@ -39429,59 +39397,44 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39429
39397
  const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
39430
39398
  const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
39431
39399
  if (startConflictX || endConflictY) {
39432
- console.log("555");
39433
- console.log([new Point(startPoint.x, endPoint.y)]);
39434
39400
  return [new Point(startPoint.x, endPoint.y)];
39435
39401
  }
39436
39402
  if (startConflictY || endConflictX) {
39437
- console.log("666");
39438
- console.log([new Point(endPoint.x, startPoint.y)]);
39439
39403
  return [new Point(endPoint.x, startPoint.y)];
39440
39404
  }
39441
39405
  return [];
39442
39406
  }
39443
- function findClosestValidPointInGrid(point5, grid, obstacles) {
39444
- let closestPoint = null;
39407
+ function findClosestPointInGrid(point5, grid) {
39408
+ let closestPoint = grid[0][0];
39445
39409
  let minDistance = Infinity;
39446
39410
  for (const row2 of grid) {
39447
39411
  for (const gridPoint of row2) {
39448
- const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
39449
- if (isPointValid) {
39450
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39451
- if (distance < minDistance) {
39452
- minDistance = distance;
39453
- closestPoint = gridPoint;
39454
- }
39412
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39413
+ if (distance < minDistance) {
39414
+ minDistance = distance;
39415
+ closestPoint = gridPoint;
39455
39416
  }
39456
39417
  }
39457
39418
  }
39458
39419
  return closestPoint;
39459
39420
  }
39460
39421
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39461
- const tempGridInfo = createGrid(start, end, toVisitPoints);
39422
+ const tempGridInfo = createGrid(start, end);
39462
39423
  const startPoint = tempGridInfo.newStart || start;
39463
39424
  const endPoint = tempGridInfo.newEnd || end;
39464
39425
  const startDir = getPointerDirection(start);
39465
39426
  const endDir = getPointerDirection(end);
39466
39427
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
39467
- const allWaypoints = [...hookWaypoints, ...toVisitPoints];
39468
- const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
39469
- const finalStart = newStart || start;
39470
- const finalEnd = newEnd || end;
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) {
39428
+ const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
39429
+ const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
39430
+ if (grid.length === 0 || grid[0].length === 0) {
39474
39431
  return { lines: [], newStart, newEnd };
39475
39432
  }
39476
- const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
39477
- if (!acc.some((existing) => existing.barelyEqual(p3))) {
39478
- acc.push(p3);
39479
- }
39480
- return acc;
39481
- }, []);
39482
- const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
39433
+ const searchStart = findClosestPointInGrid(newStart || start, grid);
39434
+ const searchEnd = findClosestPointInGrid(newEnd || end, grid);
39435
+ const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
39483
39436
  return {
39484
- lines: getLines(pathPoints),
39437
+ lines: pathPoints ? getLines(pathPoints) : [],
39485
39438
  newStart,
39486
39439
  newEnd
39487
39440
  };
@@ -36693,30 +36693,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
36693
36693
  }
36694
36694
  return;
36695
36695
  }
36696
- function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36697
- if (points.length < 2) {
36698
- return points;
36699
- }
36700
- const finalPath = [points[0]];
36701
- const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
36702
- for (let i = 0;i < points.length - 1; i += 1) {
36703
- const startSegment = points[i];
36704
- const endSegment = points[i + 1];
36705
- const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
36706
- if (segmentPath && segmentPath.length > 0) {
36707
- for (let j = 1;j < segmentPath.length; j++) {
36708
- const point5 = segmentPath[j];
36709
- const key = `${point5.x},${point5.y}`;
36710
- finalPath.push(point5);
36711
- existingPathSegments.add(key);
36712
- }
36713
- } else {
36714
- console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
36715
- return [];
36716
- }
36717
- }
36718
- return finalPath;
36719
- }
36720
36696
  function reducePoints(points) {
36721
36697
  const uniquePoints = new Map;
36722
36698
  const result = [];
@@ -36772,26 +36748,18 @@ function reconstructPath(node2) {
36772
36748
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36773
36749
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
36774
36750
  const midY = (startPoint.y + endPoint.y) / 2;
36775
- console.log("111");
36776
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
36777
36751
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
36778
36752
  }
36779
36753
  if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
36780
36754
  const midY = (startPoint.y + endPoint.y) / 2;
36781
- console.log("222");
36782
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
36783
36755
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
36784
36756
  }
36785
36757
  if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
36786
36758
  const midX = (startPoint.x + endPoint.x) / 2;
36787
- console.log("333");
36788
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
36789
36759
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
36790
36760
  }
36791
36761
  if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
36792
36762
  const midX = (startPoint.x + endPoint.x) / 2;
36793
- console.log("444");
36794
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
36795
36763
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
36796
36764
  }
36797
36765
  const dx = endPoint.x - startPoint.x;
@@ -36801,59 +36769,44 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36801
36769
  const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
36802
36770
  const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
36803
36771
  if (startConflictX || endConflictY) {
36804
- console.log("555");
36805
- console.log([new Point(startPoint.x, endPoint.y)]);
36806
36772
  return [new Point(startPoint.x, endPoint.y)];
36807
36773
  }
36808
36774
  if (startConflictY || endConflictX) {
36809
- console.log("666");
36810
- console.log([new Point(endPoint.x, startPoint.y)]);
36811
36775
  return [new Point(endPoint.x, startPoint.y)];
36812
36776
  }
36813
36777
  return [];
36814
36778
  }
36815
- function findClosestValidPointInGrid(point5, grid, obstacles) {
36816
- let closestPoint = null;
36779
+ function findClosestPointInGrid(point5, grid) {
36780
+ let closestPoint = grid[0][0];
36817
36781
  let minDistance = Infinity;
36818
36782
  for (const row2 of grid) {
36819
36783
  for (const gridPoint of row2) {
36820
- const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
36821
- if (isPointValid) {
36822
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36823
- if (distance < minDistance) {
36824
- minDistance = distance;
36825
- closestPoint = gridPoint;
36826
- }
36784
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36785
+ if (distance < minDistance) {
36786
+ minDistance = distance;
36787
+ closestPoint = gridPoint;
36827
36788
  }
36828
36789
  }
36829
36790
  }
36830
36791
  return closestPoint;
36831
36792
  }
36832
36793
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36833
- const tempGridInfo = createGrid(start, end, toVisitPoints);
36794
+ const tempGridInfo = createGrid(start, end);
36834
36795
  const startPoint = tempGridInfo.newStart || start;
36835
36796
  const endPoint = tempGridInfo.newEnd || end;
36836
36797
  const startDir = getPointerDirection(start);
36837
36798
  const endDir = getPointerDirection(end);
36838
36799
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36839
- const allWaypoints = [...hookWaypoints, ...toVisitPoints];
36840
- const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36841
- const finalStart = newStart || start;
36842
- const finalEnd = newEnd || end;
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) {
36800
+ const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
36801
+ const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
36802
+ if (grid.length === 0 || grid[0].length === 0) {
36846
36803
  return { lines: [], newStart, newEnd };
36847
36804
  }
36848
- const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
36849
- if (!acc.some((existing) => existing.barelyEqual(p3))) {
36850
- acc.push(p3);
36851
- }
36852
- return acc;
36853
- }, []);
36854
- const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
36805
+ const searchStart = findClosestPointInGrid(newStart || start, grid);
36806
+ const searchEnd = findClosestPointInGrid(newEnd || end, grid);
36807
+ const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
36855
36808
  return {
36856
- lines: getLines(pathPoints),
36809
+ lines: pathPoints ? getLines(pathPoints) : [],
36857
36810
  newStart,
36858
36811
  newEnd
36859
36812
  };
package/dist/esm/index.js CHANGED
@@ -36686,30 +36686,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
36686
36686
  }
36687
36687
  return;
36688
36688
  }
36689
- function findPathPoints(points, grid, obstacles, newStart, newEnd) {
36690
- if (points.length < 2) {
36691
- return points;
36692
- }
36693
- const finalPath = [points[0]];
36694
- const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
36695
- for (let i = 0;i < points.length - 1; i += 1) {
36696
- const startSegment = points[i];
36697
- const endSegment = points[i + 1];
36698
- const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
36699
- if (segmentPath && segmentPath.length > 0) {
36700
- for (let j = 1;j < segmentPath.length; j++) {
36701
- const point5 = segmentPath[j];
36702
- const key = `${point5.x},${point5.y}`;
36703
- finalPath.push(point5);
36704
- existingPathSegments.add(key);
36705
- }
36706
- } else {
36707
- console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
36708
- return [];
36709
- }
36710
- }
36711
- return finalPath;
36712
- }
36713
36689
  function reducePoints(points) {
36714
36690
  const uniquePoints = new Map;
36715
36691
  const result = [];
@@ -36765,26 +36741,18 @@ function reconstructPath(node2) {
36765
36741
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36766
36742
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
36767
36743
  const midY = (startPoint.y + endPoint.y) / 2;
36768
- console.log("111");
36769
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
36770
36744
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
36771
36745
  }
36772
36746
  if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
36773
36747
  const midY = (startPoint.y + endPoint.y) / 2;
36774
- console.log("222");
36775
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
36776
36748
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
36777
36749
  }
36778
36750
  if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
36779
36751
  const midX = (startPoint.x + endPoint.x) / 2;
36780
- console.log("333");
36781
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
36782
36752
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
36783
36753
  }
36784
36754
  if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
36785
36755
  const midX = (startPoint.x + endPoint.x) / 2;
36786
- console.log("444");
36787
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
36788
36756
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
36789
36757
  }
36790
36758
  const dx = endPoint.x - startPoint.x;
@@ -36794,59 +36762,44 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
36794
36762
  const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
36795
36763
  const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
36796
36764
  if (startConflictX || endConflictY) {
36797
- console.log("555");
36798
- console.log([new Point(startPoint.x, endPoint.y)]);
36799
36765
  return [new Point(startPoint.x, endPoint.y)];
36800
36766
  }
36801
36767
  if (startConflictY || endConflictX) {
36802
- console.log("666");
36803
- console.log([new Point(endPoint.x, startPoint.y)]);
36804
36768
  return [new Point(endPoint.x, startPoint.y)];
36805
36769
  }
36806
36770
  return [];
36807
36771
  }
36808
- function findClosestValidPointInGrid(point5, grid, obstacles) {
36809
- let closestPoint = null;
36772
+ function findClosestPointInGrid(point5, grid) {
36773
+ let closestPoint = grid[0][0];
36810
36774
  let minDistance = Infinity;
36811
36775
  for (const row2 of grid) {
36812
36776
  for (const gridPoint of row2) {
36813
- const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
36814
- if (isPointValid) {
36815
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36816
- if (distance < minDistance) {
36817
- minDistance = distance;
36818
- closestPoint = gridPoint;
36819
- }
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;
36820
36781
  }
36821
36782
  }
36822
36783
  }
36823
36784
  return closestPoint;
36824
36785
  }
36825
36786
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36826
- const tempGridInfo = createGrid(start, end, toVisitPoints);
36787
+ const tempGridInfo = createGrid(start, end);
36827
36788
  const startPoint = tempGridInfo.newStart || start;
36828
36789
  const endPoint = tempGridInfo.newEnd || end;
36829
36790
  const startDir = getPointerDirection(start);
36830
36791
  const endDir = getPointerDirection(end);
36831
36792
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
36832
- const allWaypoints = [...hookWaypoints, ...toVisitPoints];
36833
- const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36834
- const finalStart = newStart || start;
36835
- const finalEnd = newEnd || end;
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) {
36793
+ const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
36794
+ const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
36795
+ if (grid.length === 0 || grid[0].length === 0) {
36839
36796
  return { lines: [], newStart, newEnd };
36840
36797
  }
36841
- const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
36842
- if (!acc.some((existing) => existing.barelyEqual(p3))) {
36843
- acc.push(p3);
36844
- }
36845
- return acc;
36846
- }, []);
36847
- const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
36798
+ const searchStart = findClosestPointInGrid(newStart || start, grid);
36799
+ const searchEnd = findClosestPointInGrid(newEnd || end, grid);
36800
+ const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
36848
36801
  return {
36849
- lines: getLines(pathPoints),
36802
+ lines: pathPoints ? getLines(pathPoints) : [],
36850
36803
  newStart,
36851
36804
  newEnd
36852
36805
  };
package/dist/esm/node.js CHANGED
@@ -39154,30 +39154,6 @@ function findPath(start, end, grid, obstacles, existingPath, newStart, newEnd) {
39154
39154
  }
39155
39155
  return;
39156
39156
  }
39157
- function findPathPoints(points, grid, obstacles, newStart, newEnd) {
39158
- if (points.length < 2) {
39159
- return points;
39160
- }
39161
- const finalPath = [points[0]];
39162
- const existingPathSegments = new Set([`${points[0].x},${points[0].y}`]);
39163
- for (let i = 0;i < points.length - 1; i += 1) {
39164
- const startSegment = points[i];
39165
- const endSegment = points[i + 1];
39166
- const segmentPath = findPath(startSegment, endSegment, grid, obstacles, existingPathSegments, newStart, newEnd);
39167
- if (segmentPath && segmentPath.length > 0) {
39168
- for (let j = 1;j < segmentPath.length; j++) {
39169
- const point5 = segmentPath[j];
39170
- const key = `${point5.x},${point5.y}`;
39171
- finalPath.push(point5);
39172
- existingPathSegments.add(key);
39173
- }
39174
- } else {
39175
- console.error(`Could not find path from ${startSegment.x},${startSegment.y} to ${endSegment.x},${endSegment.y}`);
39176
- return [];
39177
- }
39178
- }
39179
- return finalPath;
39180
- }
39181
39157
  function reducePoints(points) {
39182
39158
  const uniquePoints = new Map;
39183
39159
  const result = [];
@@ -39233,26 +39209,18 @@ function reconstructPath(node2) {
39233
39209
  function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39234
39210
  if (startDir === "right" && endDir === "left" && startPoint.x > endPoint.x) {
39235
39211
  const midY = (startPoint.y + endPoint.y) / 2;
39236
- console.log("111");
39237
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
39238
39212
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
39239
39213
  }
39240
39214
  if (startDir === "left" && endDir === "right" && startPoint.x < endPoint.x) {
39241
39215
  const midY = (startPoint.y + endPoint.y) / 2;
39242
- console.log("222");
39243
- console.log([new Point(startPoint.x, midY), new Point(endPoint.x, midY)]);
39244
39216
  return [new Point(startPoint.x, midY), new Point(endPoint.x, midY)];
39245
39217
  }
39246
39218
  if (startDir === "bottom" && endDir === "top" && startPoint.y > endPoint.y) {
39247
39219
  const midX = (startPoint.x + endPoint.x) / 2;
39248
- console.log("333");
39249
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
39250
39220
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
39251
39221
  }
39252
39222
  if (startDir === "top" && endDir === "bottom" && startPoint.y < endPoint.y) {
39253
39223
  const midX = (startPoint.x + endPoint.x) / 2;
39254
- console.log("444");
39255
- console.log([new Point(midX, startPoint.y), new Point(midX, endPoint.y)]);
39256
39224
  return [new Point(midX, startPoint.y), new Point(midX, endPoint.y)];
39257
39225
  }
39258
39226
  const dx = endPoint.x - startPoint.x;
@@ -39262,59 +39230,44 @@ function createHookWaypoints(startPoint, endPoint, startDir, endDir) {
39262
39230
  const endConflictX = endDir === "right" && dx > 0 || endDir === "left" && dx < 0;
39263
39231
  const endConflictY = endDir === "bottom" && dy < 0 || endDir === "top" && dy > 0;
39264
39232
  if (startConflictX || endConflictY) {
39265
- console.log("555");
39266
- console.log([new Point(startPoint.x, endPoint.y)]);
39267
39233
  return [new Point(startPoint.x, endPoint.y)];
39268
39234
  }
39269
39235
  if (startConflictY || endConflictX) {
39270
- console.log("666");
39271
- console.log([new Point(endPoint.x, startPoint.y)]);
39272
39236
  return [new Point(endPoint.x, startPoint.y)];
39273
39237
  }
39274
39238
  return [];
39275
39239
  }
39276
- function findClosestValidPointInGrid(point5, grid, obstacles) {
39277
- let closestPoint = null;
39240
+ function findClosestPointInGrid(point5, grid) {
39241
+ let closestPoint = grid[0][0];
39278
39242
  let minDistance = Infinity;
39279
39243
  for (const row2 of grid) {
39280
39244
  for (const gridPoint of row2) {
39281
- const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
39282
- if (isPointValid) {
39283
- const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39284
- if (distance < minDistance) {
39285
- minDistance = distance;
39286
- closestPoint = gridPoint;
39287
- }
39245
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39246
+ if (distance < minDistance) {
39247
+ minDistance = distance;
39248
+ closestPoint = gridPoint;
39288
39249
  }
39289
39250
  }
39290
39251
  }
39291
39252
  return closestPoint;
39292
39253
  }
39293
39254
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39294
- const tempGridInfo = createGrid(start, end, toVisitPoints);
39255
+ const tempGridInfo = createGrid(start, end);
39295
39256
  const startPoint = tempGridInfo.newStart || start;
39296
39257
  const endPoint = tempGridInfo.newEnd || end;
39297
39258
  const startDir = getPointerDirection(start);
39298
39259
  const endDir = getPointerDirection(end);
39299
39260
  const hookWaypoints = createHookWaypoints(startPoint, endPoint, startDir, endDir);
39300
- const allWaypoints = [...hookWaypoints, ...toVisitPoints];
39301
- const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
39302
- const finalStart = newStart || start;
39303
- const finalEnd = newEnd || end;
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) {
39261
+ const allGuidingPoints = [...hookWaypoints, ...toVisitPoints];
39262
+ const { grid, newStart, newEnd } = createGrid(start, end, allGuidingPoints);
39263
+ if (grid.length === 0 || grid[0].length === 0) {
39307
39264
  return { lines: [], newStart, newEnd };
39308
39265
  }
39309
- const uniquePoints = snappedAndValidatedPoints.reduce((acc, p3) => {
39310
- if (!acc.some((existing) => existing.barelyEqual(p3))) {
39311
- acc.push(p3);
39312
- }
39313
- return acc;
39314
- }, []);
39315
- const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
39266
+ const searchStart = findClosestPointInGrid(newStart || start, grid);
39267
+ const searchEnd = findClosestPointInGrid(newEnd || end, grid);
39268
+ const pathPoints = findPath(searchStart, searchEnd, grid, obstacles, new Set, newStart, newEnd);
39316
39269
  return {
39317
- lines: getLines(pathPoints),
39270
+ lines: pathPoints ? getLines(pathPoints) : [],
39318
39271
  newStart,
39319
39272
  newEnd
39320
39273
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.5.95",
3
+ "version": "0.5.97",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",