@hayro_o7/labyrinth 0.0.6 → 0.0.7

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.
@@ -128,10 +128,13 @@
128
128
  const result = findOptimalMultiGoalPath(graph, computedStartNode, computedGoalNodes);
129
129
  optimalPath = result.optimalPath;
130
130
 
131
- // Generate visualization steps for the optimal path
131
+ // Generate visualization steps by running BFS for each segment
132
132
  steps = [];
133
- for (const nodeId of optimalPath) {
134
- steps.push({ nodeId, type: 'path' });
133
+ const tour = [computedStartNode, ...computedGoalNodes];
134
+
135
+ for (let i = 0; i < tour.length - 1; i++) {
136
+ const segmentResult = bidirectionalBFS(graph, tour[i], tour[i + 1]);
137
+ steps.push(...segmentResult.steps);
135
138
  }
136
139
  } else {
137
140
  const result = bidirectionalBFS(graph, computedStartNode, computedGoalNodes[0]);
@@ -5,6 +5,7 @@ export interface GraphGeneratorOptions {
5
5
  height?: number;
6
6
  maxConnectionsPerNode?: number;
7
7
  connectionRadius?: number;
8
+ minNodeDistance?: number;
8
9
  seed?: number;
9
10
  }
10
11
  export declare function generateRandomGraph(options: GraphGeneratorOptions): GeneralGraph;
@@ -6,14 +6,31 @@ function seededRandom(seed) {
6
6
  };
7
7
  }
8
8
  export function generateRandomGraph(options) {
9
- const { nodeCount, width = 600, height = 600, maxConnectionsPerNode = 5, connectionRadius = 150, seed } = options;
9
+ const { nodeCount, width = 600, height = 600, maxConnectionsPerNode = 5, connectionRadius = 150, minNodeDistance = 30, seed } = options;
10
10
  const random = seed !== undefined ? seededRandom(seed) : Math.random;
11
11
  const nodes = new Map();
12
12
  const padding = 50;
13
- // Generate node positions in a rectangular cloud
13
+ const nodePositions = [];
14
+ // Generate node positions with minimum distance constraint
14
15
  for (let i = 0; i < nodeCount; i++) {
15
- const x = padding + random() * (width - 2 * padding);
16
- const y = padding + random() * (height - 2 * padding);
16
+ let x, y;
17
+ let attempts = 0;
18
+ const maxAttempts = 100;
19
+ do {
20
+ x = padding + random() * (width - 2 * padding);
21
+ y = padding + random() * (height - 2 * padding);
22
+ attempts++;
23
+ // Check if position is far enough from existing nodes
24
+ const tooClose = nodePositions.some(pos => {
25
+ const dx = pos.x - x;
26
+ const dy = pos.y - y;
27
+ return Math.sqrt(dx * dx + dy * dy) < minNodeDistance;
28
+ });
29
+ if (!tooClose || attempts >= maxAttempts) {
30
+ break;
31
+ }
32
+ } while (true);
33
+ nodePositions.push({ x, y });
17
34
  nodes.set(`n${i}`, {
18
35
  id: `n${i}`,
19
36
  x,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hayro_o7/labyrinth",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",