microboard-temp 0.5.91 → 0.5.93

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.
@@ -36967,6 +36967,37 @@ 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
+ function findClosestValidPointInGrid(point5, grid, obstacles) {
36985
+ let closestPoint = null;
36986
+ let minDistance = Infinity;
36987
+ for (const row2 of grid) {
36988
+ for (const gridPoint of row2) {
36989
+ const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
36990
+ if (isPointValid) {
36991
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36992
+ if (distance < minDistance) {
36993
+ minDistance = distance;
36994
+ closestPoint = gridPoint;
36995
+ }
36996
+ }
36997
+ }
36998
+ }
36999
+ return closestPoint;
37000
+ }
36970
37001
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36971
37002
  const tempGridInfo = createGrid(start, end);
36972
37003
  const startPoint = tempGridInfo.newStart || start;
@@ -36978,7 +37009,10 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36978
37009
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36979
37010
  const finalStart = newStart || start;
36980
37011
  const finalEnd = newEnd || end;
36981
- const points = [finalStart, ...allWaypoints, finalEnd];
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];
36982
37016
  const uniquePoints = points.reduce((acc, p3) => {
36983
37017
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
36984
37018
  acc.push(p3);
@@ -36986,11 +37020,6 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36986
37020
  return acc;
36987
37021
  }, []);
36988
37022
  const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
36989
- console.log("RESULT", {
36990
- lines: getLines(pathPoints),
36991
- newStart,
36992
- newEnd
36993
- });
36994
37023
  return {
36995
37024
  lines: getLines(pathPoints),
36996
37025
  newStart,
package/dist/cjs/index.js CHANGED
@@ -36967,6 +36967,37 @@ 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
+ function findClosestValidPointInGrid(point5, grid, obstacles) {
36985
+ let closestPoint = null;
36986
+ let minDistance = Infinity;
36987
+ for (const row2 of grid) {
36988
+ for (const gridPoint of row2) {
36989
+ const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
36990
+ if (isPointValid) {
36991
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36992
+ if (distance < minDistance) {
36993
+ minDistance = distance;
36994
+ closestPoint = gridPoint;
36995
+ }
36996
+ }
36997
+ }
36998
+ }
36999
+ return closestPoint;
37000
+ }
36970
37001
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36971
37002
  const tempGridInfo = createGrid(start, end);
36972
37003
  const startPoint = tempGridInfo.newStart || start;
@@ -36978,7 +37009,10 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36978
37009
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36979
37010
  const finalStart = newStart || start;
36980
37011
  const finalEnd = newEnd || end;
36981
- const points = [finalStart, ...allWaypoints, finalEnd];
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];
36982
37016
  const uniquePoints = points.reduce((acc, p3) => {
36983
37017
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
36984
37018
  acc.push(p3);
@@ -36986,11 +37020,6 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36986
37020
  return acc;
36987
37021
  }, []);
36988
37022
  const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
36989
- console.log("RESULT", {
36990
- lines: getLines(pathPoints),
36991
- newStart,
36992
- newEnd
36993
- });
36994
37023
  return {
36995
37024
  lines: getLines(pathPoints),
36996
37025
  newStart,
package/dist/cjs/node.js CHANGED
@@ -39440,6 +39440,37 @@ 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
+ function findClosestValidPointInGrid(point5, grid, obstacles) {
39458
+ let closestPoint = null;
39459
+ let minDistance = Infinity;
39460
+ for (const row2 of grid) {
39461
+ for (const gridPoint of row2) {
39462
+ const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
39463
+ if (isPointValid) {
39464
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39465
+ if (distance < minDistance) {
39466
+ minDistance = distance;
39467
+ closestPoint = gridPoint;
39468
+ }
39469
+ }
39470
+ }
39471
+ }
39472
+ return closestPoint;
39473
+ }
39443
39474
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39444
39475
  const tempGridInfo = createGrid(start, end);
39445
39476
  const startPoint = tempGridInfo.newStart || start;
@@ -39451,7 +39482,10 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39451
39482
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
39452
39483
  const finalStart = newStart || start;
39453
39484
  const finalEnd = newEnd || end;
39454
- const points = [finalStart, ...allWaypoints, finalEnd];
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];
39455
39489
  const uniquePoints = points.reduce((acc, p3) => {
39456
39490
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
39457
39491
  acc.push(p3);
@@ -39459,11 +39493,6 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39459
39493
  return acc;
39460
39494
  }, []);
39461
39495
  const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
39462
- console.log("RESULT", {
39463
- lines: getLines(pathPoints),
39464
- newStart,
39465
- newEnd
39466
- });
39467
39496
  return {
39468
39497
  lines: getLines(pathPoints),
39469
39498
  newStart,
@@ -36812,6 +36812,37 @@ 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
+ function findClosestValidPointInGrid(point5, grid, obstacles) {
36830
+ let closestPoint = null;
36831
+ let minDistance = Infinity;
36832
+ for (const row2 of grid) {
36833
+ for (const gridPoint of row2) {
36834
+ const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
36835
+ if (isPointValid) {
36836
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36837
+ if (distance < minDistance) {
36838
+ minDistance = distance;
36839
+ closestPoint = gridPoint;
36840
+ }
36841
+ }
36842
+ }
36843
+ }
36844
+ return closestPoint;
36845
+ }
36815
36846
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36816
36847
  const tempGridInfo = createGrid(start, end);
36817
36848
  const startPoint = tempGridInfo.newStart || start;
@@ -36823,7 +36854,10 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36823
36854
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36824
36855
  const finalStart = newStart || start;
36825
36856
  const finalEnd = newEnd || end;
36826
- const points = [finalStart, ...allWaypoints, finalEnd];
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];
36827
36861
  const uniquePoints = points.reduce((acc, p3) => {
36828
36862
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
36829
36863
  acc.push(p3);
@@ -36831,11 +36865,6 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36831
36865
  return acc;
36832
36866
  }, []);
36833
36867
  const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
36834
- console.log("RESULT", {
36835
- lines: getLines(pathPoints),
36836
- newStart,
36837
- newEnd
36838
- });
36839
36868
  return {
36840
36869
  lines: getLines(pathPoints),
36841
36870
  newStart,
package/dist/esm/index.js CHANGED
@@ -36805,6 +36805,37 @@ 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
+ function findClosestValidPointInGrid(point5, grid, obstacles) {
36823
+ let closestPoint = null;
36824
+ let minDistance = Infinity;
36825
+ for (const row2 of grid) {
36826
+ for (const gridPoint of row2) {
36827
+ const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
36828
+ if (isPointValid) {
36829
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
36830
+ if (distance < minDistance) {
36831
+ minDistance = distance;
36832
+ closestPoint = gridPoint;
36833
+ }
36834
+ }
36835
+ }
36836
+ }
36837
+ return closestPoint;
36838
+ }
36808
36839
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36809
36840
  const tempGridInfo = createGrid(start, end);
36810
36841
  const startPoint = tempGridInfo.newStart || start;
@@ -36816,7 +36847,10 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36816
36847
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
36817
36848
  const finalStart = newStart || start;
36818
36849
  const finalEnd = newEnd || end;
36819
- const points = [finalStart, ...allWaypoints, finalEnd];
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];
36820
36854
  const uniquePoints = points.reduce((acc, p3) => {
36821
36855
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
36822
36856
  acc.push(p3);
@@ -36824,11 +36858,6 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
36824
36858
  return acc;
36825
36859
  }, []);
36826
36860
  const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
36827
- console.log("RESULT", {
36828
- lines: getLines(pathPoints),
36829
- newStart,
36830
- newEnd
36831
- });
36832
36861
  return {
36833
36862
  lines: getLines(pathPoints),
36834
36863
  newStart,
package/dist/esm/node.js CHANGED
@@ -39273,6 +39273,37 @@ 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
+ function findClosestValidPointInGrid(point5, grid, obstacles) {
39291
+ let closestPoint = null;
39292
+ let minDistance = Infinity;
39293
+ for (const row2 of grid) {
39294
+ for (const gridPoint of row2) {
39295
+ const isPointValid = !obstacles.some((obstacle) => obstacle.isAlmostInside(gridPoint, conf.CONNECTOR_ITEM_OFFSET - 1));
39296
+ if (isPointValid) {
39297
+ const distance = Math.abs(point5.x - gridPoint.x) + Math.abs(point5.y - gridPoint.y);
39298
+ if (distance < minDistance) {
39299
+ minDistance = distance;
39300
+ closestPoint = gridPoint;
39301
+ }
39302
+ }
39303
+ }
39304
+ }
39305
+ return closestPoint;
39306
+ }
39276
39307
  function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39277
39308
  const tempGridInfo = createGrid(start, end);
39278
39309
  const startPoint = tempGridInfo.newStart || start;
@@ -39284,7 +39315,10 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39284
39315
  const { grid, newStart, newEnd } = createGrid(start, end, allWaypoints);
39285
39316
  const finalStart = newStart || start;
39286
39317
  const finalEnd = newEnd || end;
39287
- const points = [finalStart, ...allWaypoints, finalEnd];
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];
39288
39322
  const uniquePoints = points.reduce((acc, p3) => {
39289
39323
  if (!acc.some((existing) => existing.barelyEqual(p3))) {
39290
39324
  acc.push(p3);
@@ -39292,11 +39326,6 @@ function findOrthogonalPath(start, end, obstacles, toVisitPoints = []) {
39292
39326
  return acc;
39293
39327
  }, []);
39294
39328
  const pathPoints = findPathPoints(uniquePoints, grid, obstacles, newStart, newEnd);
39295
- console.log("RESULT", {
39296
- lines: getLines(pathPoints),
39297
- newStart,
39298
- newEnd
39299
- });
39300
39329
  return {
39301
39330
  lines: getLines(pathPoints),
39302
39331
  newStart,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.5.91",
3
+ "version": "0.5.93",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",