diff --git a/PROJECT_DESCRIPTION.md b/PROJECT_DESCRIPTION.md
index 4ca0dcf..92cc597 100644
--- a/PROJECT_DESCRIPTION.md
+++ b/PROJECT_DESCRIPTION.md
@@ -32,17 +32,17 @@ npm run build
## ๐ฏ Algorithm Selection Guide
-| Need | Algorithm(s) | Module |
-| --------------------------- | ---------------------------------------------------- | ---------------------------------------------- |
-| Grid pathfinding | A* (diagonals optional) / Dijkstra (weighted graphs) | `pathfinding/astar.ts`, `pathfinding/dijkstra.ts` |
-| Procedural textures | Perlin noise grid / 3D sample / Simplex noise / Worley | `procedural/perlin.ts`, `procedural/simplex.ts`, `procedural/worley.ts` |
-| Spatial queries | Quadtree partitioning / AABB helpers / SAT / Ray-circle / Swept AABB | `spatial/quadtree.ts`, `spatial/aabb.ts`, `spatial/sat.ts`, `spatial/circleRay.ts`, `spatial/sweptAabb.ts` |
-| Web performance | Debounce / Throttle / LRU Cache / Memoize / Request dedup | `util/*.ts` |
-| Text & search | Fuzzy search & score / Trie / Binary search / Levenshtein | `search/*.ts` |
-| Data transforms | Diff (LCS) / Deep clone / Group by | `data/*.ts` |
-| Graph traversal | BFS distances / DFS callbacks / Topological sort | `graph/traversal.ts` |
-| Geometry & visuals | Convex hull / Segment intersection / Point-in-poly / Bezier / Easings | `geometry/*.ts`, `visual/*.ts` |
-| AI behaviours | Seek / Flee / Arrive / Pursue / Wander / Boids / Behaviour trees / RVO crowd steering | `ai/steering.ts`, `ai/boids.ts`, `ai/behaviorTree.ts`, `ai/rvo.ts` |
+| Need | Algorithm(s) | Module | Example |
+| ---- | ------------ | ------ | ------- |
+| Grid pathfinding | `astar`, `dijkstra`, `manhattanDistance`, `gridFromString` | `pathfinding/astar.ts`, `pathfinding/dijkstra.ts` | `examples/astar.ts` |
+| Procedural textures & terrain | `perlin`, `perlin3D`, `simplex2D`, `simplex3D`, `worley`, `worleySample` | `procedural/*.ts` | `examples/simplex.ts`, `examples/worley.ts` |
+| Spatial queries & collision | `Quadtree`, `aabbCollision`, `aabbIntersection`, `satCollision`, `circleRayIntersection`, `sweptAABB` | `spatial/*.ts` | `examples/sat.ts` |
+| Web performance & UI throttling | `debounce`, `throttle`, `LRUCache`, `memoize`, `deduplicateRequest`, `clearRequestDedup`, `calculateVirtualRange` | `util/*.ts` | `examples/requestDedup.ts`, `examples/virtualScroll.ts` |
+| Text & search | `fuzzySearch`, `fuzzyScore`, `Trie`, `binarySearch`, `levenshteinDistance` | `search/*.ts` | `tests/search.test.ts` |
+| Data transforms & diffing | `diff`, `deepClone`, `groupBy`, `diffJson`, `applyJsonDiff` | `data/*.ts` | `tests/jsonDiff.test.ts` |
+| Graph traversal | `graphBFS`, `graphDFS`, `topologicalSort` | `graph/traversal.ts` | `tests/graph.test.ts` |
+| Geometry & visuals | `convexHull`, `lineIntersection`, `pointInPolygon`, `easing`, `quadraticBezier`, `cubicBezier` | `geometry/*.ts`, `visual/*.ts` | `tests/geometry.test.ts`, `tests/visual.test.ts` |
+| AI behaviours & crowds | `seek`, `flee`, `arrive`, `pursue`, `wander`, `updateBoids`, `BehaviorTree`, `rvoStep` | `ai/steering.ts`, `ai/boids.ts`, `ai/behaviorTree.ts`, `ai/rvo.ts` | `examples/steering.ts`, `examples/boids.ts`, `examples/rvo.ts` |
---
@@ -90,9 +90,9 @@ Consistency between runtime code, documentation, and TypeScript declarations kee
- **Pathfinding:** A*, Dijkstra, Manhattan heuristic, grid string parser.
- **Procedural:** 2D Perlin grid generator, 3D Perlin sampler.
- **Spatial:** Quadtree, AABB helpers, SAT convex polygon collision.
-- **Performance utilities:** Debounce, throttle, LRU cache, memoize.
+- **Performance utilities:** Debounce, throttle, LRU cache, memoize, request deduplication, virtual scrolling.
- **Search:** Fuzzy search + scoring, Trie-based autocomplete, binary search, Levenshtein distance.
-- **Data tools:** Diff operations (LCS), deep clone, groupBy.
+- **Data tools:** Diff operations (LCS), deep clone, groupBy, JSON diff/patch helpers.
- **Graph:** BFS distance map, DFS traversal, topological sort.
- **Geometry & visuals:** Convex hull, line intersection, point-in-polygon, easing presets, quadratic/cubic Bezier evaluation.
- **AI behaviours:** Steering behaviours (seek, flee, arrive, pursue, wander), boids, behaviour trees, RVO crowd steering.
@@ -103,7 +103,7 @@ Consistency between runtime code, documentation, and TypeScript declarations kee
- Additional noise types (Simplex, Worley) and cellular automata helpers.
- Extended AI suite (boids, behaviour trees) and optimisation algorithms (genetic, simulated annealing).
-- Crowd steering via reciprocal velocity obstacles (RVO) for dense-agent navigation.
+- Advanced crowd steering variants (RVO + static obstacles, flow-field blends).
- Richer collision toolkit (circle-ray, swept AABB) and physics utilities.
- Expanded example gallery with browser + Node showcases and interactive demos.
diff --git a/README.md b/README.md
index 6122d92..83a1560 100644
--- a/README.md
+++ b/README.md
@@ -21,15 +21,18 @@ CDN usage:
```
## Included Modules (v0.1.0)
-- **Pathfinding:** A*, Dijkstra, Manhattan heuristic, grid string parser
-- **Procedural:** 2D/3D Perlin noise, Simplex noise, Worley (cellular) noise
-- **Spatial:** Quadtree, AABB helpers, SAT polygon intersection, circle-ray intersection, swept AABB
-- **Search & Text:** Fuzzy search/scoring, Trie autocomplete, binary search, Levenshtein distance
-- **Data:** Diff (LCS), deep clone, groupBy, JSON diff/patch helpers
-- **Web performance:** Debounce, throttle, LRU cache, memoize, request deduplication helper, virtual scrolling range calculator
-- **Graph:** BFS distance map, DFS traversal, topological sort
-- **Visual & Geometry:** Convex hull, line intersection, point-in-polygon, easing presets, Bezier helpers
-- **AI Behaviours:** Steering behaviours (seek, flee, arrive, pursue, wander), boids flocking update, behaviour trees, reciprocal velocity obstacles (RVO)
+
+| Goal | Algorithms | Import From | Example |
+| ---- | ---------- | ----------- | ------- |
+| Pathfinding & navigation | `astar`, `dijkstra`, `manhattanDistance`, `gridFromString` | `pathfinding/astar.ts`, `pathfinding/dijkstra.ts` | `examples/astar.ts` |
+| Procedural generation | `perlin`, `perlin3D`, `simplex2D`, `simplex3D`, `worley`, `worleySample` | `procedural/*.ts` | `examples/simplex.ts`, `examples/worley.ts` |
+| Spatial queries & collision | `Quadtree`, `aabbCollision`, `aabbIntersection`, `satCollision`, `circleRayIntersection`, `sweptAABB` | `spatial/*.ts` | `examples/sat.ts` |
+| AI behaviours & crowds | `seek`, `flee`, `arrive`, `pursue`, `wander`, `updateBoids`, `BehaviorTree`, `rvoStep` | `ai/steering.ts`, `ai/boids.ts`, `ai/behaviorTree.ts`, `ai/rvo.ts` | `examples/steering.ts`, `examples/boids.ts`, `examples/rvo.ts` |
+| Web performance & UI | `debounce`, `throttle`, `LRUCache`, `memoize`, `deduplicateRequest`, `clearRequestDedup`, `calculateVirtualRange` | `util/*.ts` | `examples/requestDedup.ts`, `examples/virtualScroll.ts` |
+| Search & text | `fuzzySearch`, `fuzzyScore`, `Trie`, `binarySearch`, `levenshteinDistance` | `search/*.ts` | `tests/search.test.ts` |
+| Data & diff pipelines | `diff`, `deepClone`, `groupBy`, `diffJson`, `applyJsonDiff` | `data/*.ts` | `tests/jsonDiff.test.ts` |
+| Graph algorithms | `graphBFS`, `graphDFS`, `topologicalSort` | `graph/traversal.ts` | `tests/graph.test.ts` |
+| Visual & geometry | `convexHull`, `lineIntersection`, `pointInPolygon`, `easing`, `quadraticBezier`, `cubicBezier` | `geometry/*.ts`, `visual/*.ts` | `tests/geometry.test.ts`, `tests/visual.test.ts` |
## Scripts
```bash
@@ -43,7 +46,7 @@ npm run size # Enforce bundle size budget
```
## Roadmap Snapshot
-- Milestone 0.2 is tracking a reciprocal velocity obstacles (RVO) crowd steering module to expand the AI suite.
+- Milestone 0.2 next targets crowd-flow integrations (RVO + flow fields) and behaviour-tree decorators for richer AI control.
Examples live under `examples/` and can be executed with `tsx`/`ts-node` or compiled for the browser. See `examples/astar.ts`, `examples/steering.ts`, `examples/boids.ts`, `examples/requestDedup.ts`, `examples/sat.ts`, `examples/simplex.ts`, and `examples/worley.ts` for quick starts.
diff --git a/docs/index.d.ts b/docs/index.d.ts
index 819bfc2..c912b62 100644
--- a/docs/index.d.ts
+++ b/docs/index.d.ts
@@ -1,5 +1,18 @@
// LLM Algorithm Library - TypeScript Definitions
// Import from: https://cdn.jsdelivr.net/npm/llm-algorithms/dist/index.js
+//
+// ๐ Quick Navigation for LLMs / tooling
+// - ๐ฎ Pathfinding & Navigation โ astar, dijkstra (examples/astar.ts)
+// - ๐ Procedural Generation โ perlin, simplex2D/3D, worley (examples/simplex.ts, examples/worley.ts)
+// - ๐ฏ Spatial & Collision โ quadtree, aabb, sat, circleRayIntersection, sweptAABB (examples/sat.ts)
+// - ๐ค AI & Behaviour โ seek/flee/arrive/pursue/wander, updateBoids, BehaviorTree, rvoStep (examples/steering.ts, examples/boids.ts, examples/rvo.ts)
+// - โก Web Performance โ debounce, throttle, LRUCache, memoize, deduplicateRequest, virtual scroll (examples/requestDedup.ts, examples/virtualScroll.ts)
+// - ๐ Search & Text โ fuzzySearch, fuzzyScore, Trie, binarySearch, levenshteinDistance
+// - ๐ Data Pipelines โ diff, deepClone, groupBy, diffJson/applyJsonDiff
+// - ๐ Graph Algorithms โ graphBFS, graphDFS, topologicalSort
+// - ๐จ Visual & Geometry โ convexHull, lineIntersection, pointInPolygon, easing, bezier
+//
+// Each declaration includes "Use for", a performance hint, and the import path for quick selection.
// ============================================================================
// ๐ฎ PATHFINDING & NAVIGATION
@@ -530,7 +543,7 @@ export function updateBoids(boids: Boid[], options: BoidOptions): void;
* Reciprocal velocity obstacles (RVO) step for multi-agent avoidance.
* Use for: crowd steering, swarms, dense navigation.
* Performance: O(n ร log n) with neighbor filtering.
- * Import: ai/rvo.ts
+ * Import: ai/rvo.ts (run examples/rvo.ts to see three-agent avoidance).
*/
export interface RvoAgent extends Agent {
id?: string;
diff --git a/docs/index2.d.ts b/docs/index2.d.ts
new file mode 100644
index 0000000..b0d05c8
--- /dev/null
+++ b/docs/index2.d.ts
@@ -0,0 +1,29 @@
+///
+
+// LLM Algorithm Library โ Quick Directory
+// ----------------------------------------
+// This file gives language models a fast, text-only overview of the available
+// categories and the matching example files. The actual type signatures live in
+// `docs/index.d.ts` (referenced above).
+//
+// ๐ Quick Navigation
+// - ๐ฎ Pathfinding & Navigation โ astar, dijkstra (examples/astar.ts)
+// - ๐ Procedural Generation โ perlin/perlin3D, simplex2D/simplex3D, worley (examples/simplex.ts, examples/worley.ts)
+// - ๐ฏ Spatial & Collision โ Quadtree, aabbCollision, satCollision, circleRayIntersection, sweptAABB (examples/sat.ts)
+// - ๐ค AI & Behaviour โ steering helpers, updateBoids, BehaviorTree, rvoStep (examples/steering.ts, examples/boids.ts, examples/rvo.ts)
+// - โก Web Performance โ debounce, throttle, LRUCache, memoize, deduplicateRequest, calculateVirtualRange (examples/requestDedup.ts, examples/virtualScroll.ts)
+// - ๐ Search & Text โ fuzzySearch, fuzzyScore, Trie, binarySearch, levenshteinDistance
+// - ๐ Data Pipelines โ diff, deepClone, groupBy, diffJson/applyJsonDiff (tests/jsonDiff.test.ts)
+// - ๐ Graph Algorithms โ graphBFS, graphDFS, topologicalSort (tests/graph.test.ts)
+// - ๐จ Visual & Geometry โ convexHull, lineIntersection, pointInPolygon, easing, quadraticBezier, cubicBezier (tests/geometry.test.ts, tests/visual.test.ts)
+//
+// โ
Tips for LLMs
+// 1. Import from `llm-algorithms/dist/index.js` or the CDN mirror.
+// 2. Look up the full signature and JSDoc in `docs/index.d.ts`.
+// 3. Browse the matching file in `examples/` for runnable usage.
+// 4. Vitest suites inside `tests/` demonstrate edge cases.
+//
+// No additional declarations live here โ see the referenced file for the full
+// type surface.
+
+export {};
diff --git a/docs/project.md b/docs/project.md
new file mode 100644
index 0000000..d964a1d
--- /dev/null
+++ b/docs/project.md
@@ -0,0 +1,112 @@
+# LLM Algorithm Library โ Reference Companion
+
+This document complements `docs/index.d.ts` with high-level navigation notes that help human developers and coding assistants discover the right algorithms quickly.
+
+## ๐ Quick Start
+
+### For LLMs and automation
+1. Inspect the TypeScript definitions in `docs/index.d.ts` for signatures, โUse forโ blurbs, and performance notes.
+2. Pick the algorithm that matches your task from the selection guide below.
+3. Import from the package entry point or CDN:
+
+```ts
+import { astar } from 'llm-algorithms/dist/index.js';
+```
+
+```html
+
+```
+
+### For local development
+
+```bash
+npm install llm-algorithms
+npm run build # emit dist/
+```
+
+Examples in `examples/` are runnable with `tsx`/`ts-node` for quick validation.
+
+---
+
+## ๐ฏ Algorithm Selection Guide
+
+| Need | Algorithm(s) | Import From | Example |
+| ---- | ------------ | ----------- | ------- |
+| Grid pathfinding | `astar`, `dijkstra`, `manhattanDistance`, `gridFromString` | `pathfinding/astar.ts`, `pathfinding/dijkstra.ts` | `examples/astar.ts` |
+| Procedural generation | `perlin`, `perlin3D`, `simplex2D`, `simplex3D`, `worley`, `worleySample` | `procedural/*.ts` | `examples/simplex.ts`, `examples/worley.ts` |
+| Spatial queries & collision | `Quadtree`, `aabbCollision`, `aabbIntersection`, `satCollision`, `circleRayIntersection`, `sweptAABB` | `spatial/*.ts` | `examples/sat.ts` |
+| AI behaviours & crowds | `seek`, `flee`, `arrive`, `pursue`, `wander`, `updateBoids`, `BehaviorTree`, `rvoStep` | `ai/steering.ts`, `ai/boids.ts`, `ai/behaviorTree.ts`, `ai/rvo.ts` | `examples/steering.ts`, `examples/boids.ts`, `examples/rvo.ts` |
+| Web performance & UI | `debounce`, `throttle`, `LRUCache`, `memoize`, `deduplicateRequest`, `clearRequestDedup`, `calculateVirtualRange` | `util/*.ts` | `examples/requestDedup.ts`, `examples/virtualScroll.ts` |
+| Text & search | `fuzzySearch`, `fuzzyScore`, `Trie`, `binarySearch`, `levenshteinDistance` | `search/*.ts` | `tests/search.test.ts` |
+| Data transforms & diffing | `diff`, `deepClone`, `groupBy`, `diffJson`, `applyJsonDiff` | `data/*.ts` | `tests/jsonDiff.test.ts` |
+| Graph algorithms | `graphBFS`, `graphDFS`, `topologicalSort` | `graph/traversal.ts` | `tests/graph.test.ts` |
+| Geometry & visuals | `convexHull`, `lineIntersection`, `pointInPolygon`, `easing`, `quadraticBezier`, `cubicBezier` | `geometry/*.ts`, `visual/*.ts` | `tests/geometry.test.ts`, `tests/visual.test.ts` |
+
+---
+
+## ๐ฆ Project Structure (TypeScript)
+
+```
+llm-algorithms/
+โโโ docs/
+โ โโโ index.d.ts # Authoritative type surface + โUse forโ notes
+โ โโโ index2.d.ts # Quick navigation helper (references index.d.ts)
+โ โโโ project.md # This guide
+โโโ examples/ # Runnable scripts (astar, steering, boids, rvo, sat, simplex, worley, requestDedup, virtualScroll)
+โโโ src/
+โ โโโ ai/ # Steering, boids, behaviour tree, RVO
+โ โโโ data/ # Diff, deep clone, groupBy, JSON diff
+โ โโโ graph/ # BFS, DFS, topological sort
+โ โโโ pathfinding/ # A*, Dijkstra helpers
+โ โโโ procedural/ # Noise generators
+โ โโโ search/ # Fuzzy search, trie, binary search, Levenshtein
+โ โโโ spatial/ # Quadtree, AABB, SAT, circle-ray, swept AABB
+โ โโโ util/ # Debounce, throttle, LRU, memoize, dedup, virtual scroll
+โ โโโ visual/ # Easing curves, Bezier helpers
+โ โโโ types.ts # Shared geometric and agent types
+โ โโโ index.ts # Barrel exports
+โโโ tests/ # Vitest coverage ensuring examples remain truthful
+โโโ README.md # High-level summary + selection table
+```
+
+---
+
+## ๐ง Working With LLMs
+
+When prompting an LLM to add or extend functionality, ensure it follows these guardrails:
+
+1. **Implementation** โ add runtime code to `src//.ts` using modern TypeScript, rich JSDoc, and small pure helpers. Provide at least two `@example` blocks.
+2. **Types & docs** โ update `docs/index.d.ts` (and this guide if applicable) with description, โUse forโ line, performance note, import path, and any new interfaces/options.
+3. **Exports** โ wire the module through `src/index.ts` and add/extend the relevant types in `src/types.ts` when necessary.
+4. **Tests** โ create Vitest coverage in `tests/` demonstrating success paths and edge cases. Prefer deterministic fixtures to keep CI stable.
+5. **Examples** โ add or update an entry under `examples/` so users can run the algorithm quickly.
+6. **Quality gate** โ ensure `npm run lint`, `npm run typecheck`, `npm run build`, `npm run size`, and `npm run test:coverage` succeed before opening a PR.
+
+Following these steps keeps the documentation aligned with the code and makes the library predictable for both humans and language models.
+
+---
+
+## โ
Included Implementations (Snapshot)
+
+- **Pathfinding:** A*, Dijkstra, Manhattan heuristic, grid helpers.
+- **Procedural:** Perlin (2D/3D), Simplex (2D/3D), Worley noise.
+- **Spatial:** Quadtree, AABB helpers, SAT collision, circle-ray intersection, swept AABB.
+- **Web performance:** Debounce, throttle, LRU cache, memoize, request deduplication, virtual scroll windowing.
+- **Search & text:** Fuzzy search/scoring, Trie autocomplete, binary search, Levenshtein distance.
+- **Data pipelines:** Diff (LCS), deep clone, groupBy, JSON diff/patch helpers.
+- **Graph:** BFS distance map, DFS traversal, topological ordering.
+- **Geometry & visuals:** Convex hull, line intersection, point-in-polygon, easing curves, Bezier evaluation.
+- **AI behaviours:** Steering helpers, boids, behaviour trees, RVO crowd steering.
+
+---
+
+## ๐ญ Upcoming Focus
+
+- Flow-field integration with RVO for smoother large crowd routing.
+- Behaviour-tree decorators and reusable condition/action packs.
+- Additional procedural generators (erosion, domain-warped noise).
+- Expanded example gallery with visualization snippets.
+
+Contributions welcome! Follow conventional commits and keep examples runnable so docs stay in sync.
diff --git a/src/ai/rvo.ts b/src/ai/rvo.ts
index 28df2c4..24304d2 100644
--- a/src/ai/rvo.ts
+++ b/src/ai/rvo.ts
@@ -2,20 +2,76 @@ import type { RvoAgent, Vector2D } from '../types.js';
const EPSILON = 1e-6;
+/**
+ * Configuration for the RVO solver.
+ * Useful for: tuning responsiveness, limiting neighbor checks, scaling deflection strength.
+ */
export interface RvoOptions {
+ /** Seconds to look ahead when predicting collisions. */
timeHorizon?: number;
+ /** Maximum neighbors each agent considers for avoidance. */
maxNeighbors?: number;
+ /** Multiplier controlling how strongly agents slide away from conflicts. */
avoidanceStrength?: number;
}
+/**
+ * Velocity update returned by {@link rvoStep}.
+ */
export interface RvoResult {
+ /** Optional identifier carried over from the input agent. */
id?: string;
+ /** Steering-adjusted velocity vector that remains under the agent max speed. */
velocity: Vector2D;
}
/**
* Computes collision-avoiding agent velocities using reciprocal velocity obstacles (RVO).
* Useful for: crowd steering, swarm navigation, multi-agent avoidance.
+ *
+ * @param agents - Collection of crowd agents with their state and preferred velocities.
+ * @param options - Optional tuning parameters (time horizon, neighbor limits, avoidance strength).
+ * @returns Velocity updates per agent, preserving their `id` when provided.
+ *
+ * @example
+ * import { rvoStep } from 'llm-algorithms';
+ *
+ * const agents = [
+ * {
+ * id: 'alpha',
+ * position: { x: -1, y: 0 },
+ * velocity: { x: 1, y: 0 },
+ * preferredVelocity: { x: 1, y: 0 },
+ * radius: 0.35,
+ * maxSpeed: 1.5,
+ * },
+ * {
+ * id: 'beta',
+ * position: { x: 1, y: 0 },
+ * velocity: { x: -1, y: 0 },
+ * preferredVelocity: { x: -1, y: 0 },
+ * radius: 0.35,
+ * maxSpeed: 1.5,
+ * },
+ * ];
+ *
+ * const updated = rvoStep(agents, { timeHorizon: 2.5 });
+ * // updated[0].velocity.y and updated[1].velocity.y have opposite signs for lateral avoidance.
+ *
+ * @example
+ * import { rvoStep } from 'llm-algorithms';
+ *
+ * const swarm = new Array(25).fill(null).map((_, index) => ({
+ * id: `agent-${index}`,
+ * position: { x: Math.cos((index / 25) * Math.PI * 2), y: Math.sin((index / 25) * Math.PI * 2) },
+ * velocity: { x: 0, y: 0 },
+ * preferredVelocity: { x: 0.6, y: 0 },
+ * radius: 0.25,
+ * maxSpeed: 0.8,
+ * }));
+ *
+ * const step = rvoStep(swarm, { maxNeighbors: 10, avoidanceStrength: 0.5 });
+ * // step contains safe velocities that can be fed into your integration loop.
*/
export function rvoStep(
agents: ReadonlyArray,
diff --git a/src/types.ts b/src/types.ts
index 39c09bb..cf1496c 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -51,6 +51,10 @@ export interface Boid extends SteeringAgent {
acceleration: Vector2D;
}
+/**
+ * Crowd agent input used by the RVO solver.
+ * Useful for: crowd navigation, swarms, multi-agent avoidance.
+ */
export interface RvoAgent extends Agent {
id?: string;
radius: number;