@esengine/pathfinding 13.0.0 → 13.1.0
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.
- package/dist/{KDTree-Bw4Faf2O.d.ts → IIncrementalPathfinding-3qs7e_pO.d.ts} +1 -371
- package/dist/KDTree-2rs2EXvm.d.ts +407 -0
- package/dist/LinearProgram-DyD3pI6v.d.ts +56 -0
- package/dist/avoidance.d.ts +31 -0
- package/dist/avoidance.js +31 -0
- package/dist/avoidance.js.map +1 -0
- package/dist/chunk-JTZP55BJ.js +935 -0
- package/dist/chunk-JTZP55BJ.js.map +1 -0
- package/dist/chunk-KEYTX37K.js +1 -0
- package/dist/chunk-KEYTX37K.js.map +1 -0
- package/dist/chunk-T626JPC7.js +10 -0
- package/dist/chunk-T626JPC7.js.map +1 -0
- package/dist/{chunk-OA7ZZQMH.js → chunk-VNC2YAAL.js} +6 -908
- package/dist/chunk-VNC2YAAL.js.map +1 -0
- package/dist/{chunk-GTFFYRZM.js → chunk-YKA3PWU3.js} +1 -8
- package/dist/{chunk-GTFFYRZM.js.map → chunk-YKA3PWU3.js.map} +1 -1
- package/dist/ecs.d.ts +2 -1
- package/dist/ecs.js +10 -6
- package/dist/ecs.js.map +1 -1
- package/dist/index.d.ts +5 -27
- package/dist/index.js +16 -11
- package/dist/index.js.map +1 -1
- package/dist/nodes.js +4 -2
- package/dist/nodes.js.map +1 -1
- package/package.json +7 -3
- package/dist/chunk-OA7ZZQMH.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/avoidance/ILocalAvoidance.ts","../src/avoidance/LinearProgram.ts","../src/avoidance/ObstacleBuilder.ts","../src/avoidance/ORCASolver.ts","../src/avoidance/KDTree.ts"],"sourcesContent":["/**\n * @zh ORCA 局部避让接口定义\n * @en ORCA Local Avoidance Interface Definitions\n */\n\nimport type { IVector2 } from '@esengine/ecs-framework-math';\n\nexport type { IVector2 };\n\n/**\n * @zh ORCA 约束线(半平面)\n * @en ORCA constraint line (half-plane)\n *\n * @zh 约束线定义了一个半平面,代理的速度必须在允许的一侧\n * @en A constraint line defines a half-plane, agent's velocity must be on the allowed side\n */\nexport interface IORCALine {\n /**\n * @zh 线上的一点\n * @en A point on the line\n */\n point: IVector2;\n\n /**\n * @zh 线的方向向量(单位向量,允许区域在左侧)\n * @en Direction vector of the line (unit vector, allowed region is on the left)\n */\n direction: IVector2;\n}\n\n// =============================================================================\n// 代理数据 | Agent Data\n// =============================================================================\n\n/**\n * @zh 避让代理数据\n * @en Avoidance agent data\n *\n * @zh 包含计算 ORCA 所需的所有代理信息\n * @en Contains all agent information needed for ORCA computation\n */\nexport interface IAvoidanceAgent {\n /**\n * @zh 代理唯一标识\n * @en Unique identifier for the agent\n */\n id: number;\n\n /**\n * @zh 当前位置\n * @en Current position\n */\n position: IVector2;\n\n /**\n * @zh 当前速度\n * @en Current velocity\n */\n velocity: IVector2;\n\n /**\n * @zh 首选速度(通常指向目标方向)\n * @en Preferred velocity (usually towards target)\n */\n preferredVelocity: IVector2;\n\n /**\n * @zh 代理半径\n * @en Agent radius\n */\n radius: number;\n\n /**\n * @zh 最大速度\n * @en Maximum speed\n */\n maxSpeed: number;\n\n /**\n * @zh 邻居检测距离\n * @en Neighbor detection distance\n */\n neighborDist: number;\n\n /**\n * @zh 最大邻居数量\n * @en Maximum number of neighbors to consider\n */\n maxNeighbors: number;\n\n /**\n * @zh 代理避让时间视野(秒)\n * @en Time horizon for agent avoidance (seconds)\n *\n * @zh 更大的值会让代理更早开始避让\n * @en Larger values make agents start avoiding earlier\n */\n timeHorizon: number;\n\n /**\n * @zh 障碍物避让时间视野(秒)\n * @en Time horizon for obstacle avoidance (seconds)\n */\n timeHorizonObst: number;\n}\n\n// =============================================================================\n// 障碍物 | Obstacles\n// =============================================================================\n\n/**\n * @zh 静态障碍物顶点(链表节点)\n * @en Static obstacle vertex (linked list node)\n */\nexport interface IObstacleVertex {\n /**\n * @zh 顶点位置\n * @en Vertex position\n */\n point: IVector2;\n\n /**\n * @zh 下一个顶点(构成障碍物边,循环链表)\n * @en Next vertex (forms obstacle edge, circular linked list)\n */\n next: IObstacleVertex;\n\n /**\n * @zh 前一个顶点(循环链表)\n * @en Previous vertex (circular linked list)\n */\n previous: IObstacleVertex;\n\n /**\n * @zh 边的单位方向向量(从此顶点指向 next 顶点)\n * @en Unit direction vector of edge (from this vertex towards next vertex)\n */\n direction: IVector2;\n\n /**\n * @zh 是否为凸顶点\n * @en Whether this is a convex vertex\n */\n isConvex: boolean;\n\n /**\n * @zh 顶点 ID(用于调试)\n * @en Vertex ID (for debugging)\n */\n id: number;\n}\n\n/**\n * @zh 静态障碍物(多边形)\n * @en Static obstacle (polygon)\n *\n * @zh 重要:顶点必须按逆时针(CCW)顺序排列(在 Y 轴向上的坐标系中)\n * @en Important: Vertices must be in counter-clockwise (CCW) order (in Y-axis up coordinate system)\n *\n * @zh 可以使用 math 库中的 Polygon.ensureCCW() 确保正确顺序\n * @en Use Polygon.ensureCCW() from math library to ensure correct order\n *\n * @zh 在 Y 轴向下的坐标系(如 Canvas)中,视觉上的 CCW 需要传入 yAxisDown=true\n * @en In Y-axis down coordinate system (like Canvas), use yAxisDown=true for visual CCW\n *\n * @example\n * ```typescript\n * import { Polygon } from '@esengine/ecs-framework-math';\n *\n * // 标准 Y 轴向上坐标系\n * const obstacle: IObstacle = {\n * vertices: Polygon.ensureCCW(myVertices)\n * };\n *\n * // Canvas/屏幕坐标系(Y 轴向下)\n * const obstacle: IObstacle = {\n * vertices: Polygon.ensureCCW(myVertices, true)\n * };\n * ```\n */\nexport interface IObstacle {\n /**\n * @zh 顶点列表(逆时针顺序,Y 轴向上坐标系)\n * @en Vertex list (counter-clockwise order in Y-axis up coordinate system)\n */\n vertices: IVector2[];\n}\n\n// =============================================================================\n// 求解器接口 | Solver Interface\n// =============================================================================\n\n/**\n * @zh ORCA 求解器配置\n * @en ORCA solver configuration\n */\nexport interface IORCASolverConfig {\n /**\n * @zh 默认时间视野(代理)\n * @en Default time horizon for agents\n */\n defaultTimeHorizon?: number;\n\n /**\n * @zh 默认时间视野(障碍物)\n * @en Default time horizon for obstacles\n */\n defaultTimeHorizonObst?: number;\n\n /**\n * @zh 时间步长(用于碰撞响应)\n * @en Time step (for collision response)\n */\n timeStep?: number;\n\n /**\n * @zh 数值精度阈值\n * @en Numerical precision threshold\n */\n epsilon?: number;\n}\n\n/**\n * @zh ORCA 求解结果\n * @en ORCA solve result\n */\nexport interface IORCAResult {\n /**\n * @zh 计算得到的新速度\n * @en Computed new velocity\n */\n velocity: IVector2;\n\n /**\n * @zh 是否找到可行解\n * @en Whether a feasible solution was found\n */\n feasible: boolean;\n\n /**\n * @zh 生成的 ORCA 约束线数量\n * @en Number of ORCA lines generated\n */\n numLines: number;\n}\n\n/**\n * @zh ORCA 求解器接口\n * @en ORCA solver interface\n */\nexport interface IORCASolver {\n /**\n * @zh 计算代理的新速度\n * @en Compute new velocity for agent\n *\n * @param agent - @zh 当前代理 @en Current agent\n * @param neighbors - @zh 邻近代理列表 @en List of neighbor agents\n * @param obstacles - @zh 静态障碍物列表 @en List of static obstacles\n * @param deltaTime - @zh 时间步长 @en Time step\n * @returns @zh 新速度 @en New velocity\n */\n computeNewVelocity(\n agent: IAvoidanceAgent,\n neighbors: readonly IAvoidanceAgent[],\n obstacles: readonly IObstacle[],\n deltaTime: number\n ): IVector2;\n}\n\n// =============================================================================\n// 空间索引接口 | Spatial Index Interface\n// =============================================================================\n\n/**\n * @zh 邻居查询结果\n * @en Neighbor query result\n */\nexport interface INeighborResult {\n /**\n * @zh 代理数据\n * @en Agent data\n */\n agent: IAvoidanceAgent;\n\n /**\n * @zh 距离的平方\n * @en Squared distance\n */\n distanceSq: number;\n}\n\n/**\n * @zh 空间索引接口(用于快速邻居查询)\n * @en Spatial index interface (for fast neighbor queries)\n */\nexport interface ISpatialIndex {\n /**\n * @zh 构建空间索引\n * @en Build spatial index\n *\n * @param agents - @zh 代理列表 @en List of agents\n */\n build(agents: readonly IAvoidanceAgent[]): void;\n\n /**\n * @zh 查询指定范围内的邻居\n * @en Query neighbors within specified range\n *\n * @param position - @zh 查询位置 @en Query position\n * @param radius - @zh 查询半径 @en Query radius\n * @param maxResults - @zh 最大返回数量 @en Maximum number of results\n * @param excludeId - @zh 排除的代理 ID @en Agent ID to exclude\n * @returns @zh 邻居列表(按距离排序)@en List of neighbors (sorted by distance)\n */\n queryNeighbors(\n position: IVector2,\n radius: number,\n maxResults: number,\n excludeId?: number\n ): INeighborResult[];\n\n /**\n * @zh 清空索引\n * @en Clear the index\n */\n clear(): void;\n}\n\n// =============================================================================\n// 默认配置 | Default Configuration\n// =============================================================================\n\n/**\n * @zh 默认 ORCA 求解器配置\n * @en Default ORCA solver configuration\n */\nexport const DEFAULT_ORCA_CONFIG: Required<IORCASolverConfig> = {\n defaultTimeHorizon: 2.0,\n defaultTimeHorizonObst: 1.0,\n timeStep: 1 / 60,\n epsilon: 0.00001\n};\n\n/**\n * @zh 默认代理参数\n * @en Default agent parameters\n */\nexport const DEFAULT_AGENT_PARAMS = {\n radius: 0.5,\n maxSpeed: 5.0,\n neighborDist: 15.0,\n maxNeighbors: 10,\n timeHorizon: 2.0,\n timeHorizonObst: 1.0\n};\n","/**\n * @zh 2D 线性规划求解器\n * @en 2D Linear Programming Solver\n *\n * @zh 用于 ORCA 算法中的速度优化求解\n * @en Used for velocity optimization in ORCA algorithm\n */\n\nimport { Vector2, type IVector2 } from '@esengine/ecs-framework-math';\nimport type { IORCALine } from './ILocalAvoidance';\n\n// =============================================================================\n// 常量 | Constants\n// =============================================================================\n\n/**\n * @zh 数值精度阈值\n * @en Numerical precision threshold\n */\nconst EPSILON = 0.00001;\n\nconst { dot, det, lengthSq } = Vector2;\n\n// =============================================================================\n// 线性规划求解 | Linear Programming Solver\n// =============================================================================\n\n/**\n * @zh 1D 线性规划\n * @en 1D Linear Programming\n *\n * @zh 在一条线上找到满足约束的最优点\n * @en Find optimal point on a line that satisfies constraints\n *\n * @param lines - @zh 约束线列表 @en List of constraint lines\n * @param lineNo - @zh 当前处理的线索引 @en Index of current line being processed\n * @param radius - @zh 最大速度(圆盘半径)@en Maximum speed (disk radius)\n * @param optVelocity - @zh 首选速度 @en Preferred velocity\n * @param directionOpt - @zh 是否优化方向 @en Whether to optimize direction\n * @param result - @zh 结果向量(输出)@en Result vector (output)\n * @returns @zh 是否找到可行解 @en Whether a feasible solution was found\n */\nfunction linearProgram1(\n lines: readonly IORCALine[],\n lineNo: number,\n radius: number,\n optVelocity: IVector2,\n directionOpt: boolean,\n result: Vector2\n): boolean {\n const line = lines[lineNo]!;\n const dotProduct = dot(line.point, line.direction);\n const discriminant = dotProduct * dotProduct + radius * radius - lengthSq(line.point);\n\n if (discriminant < 0) {\n return false;\n }\n\n const sqrtDiscriminant = Math.sqrt(discriminant);\n let tLeft = -dotProduct - sqrtDiscriminant;\n let tRight = -dotProduct + sqrtDiscriminant;\n\n for (let i = 0; i < lineNo; i++) {\n const constraint = lines[i]!;\n const denominator = det(line.direction, constraint.direction);\n const numerator = det(constraint.direction, {\n x: line.point.x - constraint.point.x,\n y: line.point.y - constraint.point.y\n });\n\n if (Math.abs(denominator) <= EPSILON) {\n if (numerator < 0) {\n return false;\n }\n continue;\n }\n\n const t = numerator / denominator;\n\n if (denominator >= 0) {\n tRight = Math.min(tRight, t);\n } else {\n tLeft = Math.max(tLeft, t);\n }\n\n if (tLeft > tRight) {\n return false;\n }\n }\n\n let t: number;\n if (directionOpt) {\n if (dot(optVelocity, line.direction) > 0) {\n t = tRight;\n } else {\n t = tLeft;\n }\n } else {\n t = dot(line.direction, {\n x: optVelocity.x - line.point.x,\n y: optVelocity.y - line.point.y\n });\n\n if (t < tLeft) {\n t = tLeft;\n } else if (t > tRight) {\n t = tRight;\n }\n }\n\n result.x = line.point.x + t * line.direction.x;\n result.y = line.point.y + t * line.direction.y;\n\n return true;\n}\n\n/**\n * @zh 2D 线性规划\n * @en 2D Linear Programming\n *\n * @zh 在多个半平面约束下找到最优速度\n * @en Find optimal velocity under multiple half-plane constraints\n *\n * @param lines - @zh 约束线列表 @en List of constraint lines\n * @param radius - @zh 最大速度(圆盘半径)@en Maximum speed (disk radius)\n * @param optVelocity - @zh 首选速度 @en Preferred velocity\n * @param directionOpt - @zh 是否优化方向 @en Whether to optimize direction\n * @param result - @zh 结果向量(输出)@en Result vector (output)\n * @returns @zh 第一个失败的约束索引,如果成功则返回 lines.length @en Index of first failed constraint, or lines.length if successful\n */\nexport function linearProgram2(\n lines: readonly IORCALine[],\n radius: number,\n optVelocity: IVector2,\n directionOpt: boolean,\n result: Vector2\n): number {\n if (directionOpt) {\n result.x = optVelocity.x * radius;\n result.y = optVelocity.y * radius;\n } else if (lengthSq(optVelocity) > radius * radius) {\n const len = Math.sqrt(lengthSq(optVelocity));\n result.x = optVelocity.x / len * radius;\n result.y = optVelocity.y / len * radius;\n } else {\n result.x = optVelocity.x;\n result.y = optVelocity.y;\n }\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!;\n const detVal = det(line.direction, { x: line.point.x - result.x, y: line.point.y - result.y });\n if (detVal > 0) {\n const tempResult = result.clone();\n if (!linearProgram1(lines, i, radius, optVelocity, directionOpt, result)) {\n result.copy(tempResult);\n return i;\n }\n }\n }\n\n return lines.length;\n}\n\n/**\n * @zh 3D 线性规划(回退方案)\n * @en 3D Linear Programming (fallback)\n *\n * @zh 当 2D 线性规划失败时,使用此方法找到最小穿透的速度\n * @en When 2D LP fails, use this to find velocity with minimum penetration\n *\n * @param lines - @zh 约束线列表 @en List of constraint lines\n * @param numObstLines - @zh 障碍物约束线数量 @en Number of obstacle constraint lines\n * @param beginLine - @zh 开始处理的线索引 @en Index of line to start processing\n * @param radius - @zh 最大速度 @en Maximum speed\n * @param result - @zh 结果向量(输入/输出)@en Result vector (input/output)\n */\nexport function linearProgram3(\n lines: IORCALine[],\n numObstLines: number,\n beginLine: number,\n radius: number,\n result: Vector2\n): void {\n let distance = 0;\n\n for (let i = beginLine; i < lines.length; i++) {\n const line = lines[i]!;\n if (det(line.direction, { x: line.point.x - result.x, y: line.point.y - result.y }) > distance) {\n const projLines: IORCALine[] = [];\n\n for (let j = 0; j < numObstLines; j++) {\n projLines.push(lines[j]!);\n }\n\n for (let j = numObstLines; j < i; j++) {\n const line1 = lines[j]!;\n const line2 = lines[i]!;\n\n let newLine: IORCALine;\n const determinant = det(line1.direction, line2.direction);\n\n if (Math.abs(determinant) <= EPSILON) {\n if (dot(line1.direction, line2.direction) > 0) {\n continue;\n }\n\n newLine = {\n point: {\n x: 0.5 * (line1.point.x + line2.point.x),\n y: 0.5 * (line1.point.y + line2.point.y)\n },\n direction: { x: 0, y: 0 }\n };\n } else {\n const diff = {\n x: line1.point.x - line2.point.x,\n y: line1.point.y - line2.point.y\n };\n const t = det(line2.direction, diff) / determinant;\n\n newLine = {\n point: {\n x: line1.point.x + t * line1.direction.x,\n y: line1.point.y + t * line1.direction.y\n },\n direction: { x: 0, y: 0 }\n };\n }\n\n const dirDiff = {\n x: line1.direction.x - line2.direction.x,\n y: line1.direction.y - line2.direction.y\n };\n const dirLen = Math.sqrt(lengthSq(dirDiff));\n if (dirLen > EPSILON) {\n newLine.direction.x = dirDiff.x / dirLen;\n newLine.direction.y = dirDiff.y / dirLen;\n }\n\n projLines.push(newLine);\n }\n\n const tempResult = result.clone();\n const optVelocity = { x: -lines[i]!.direction.y, y: lines[i]!.direction.x };\n\n if (linearProgram2(projLines, radius, optVelocity, true, result) < projLines.length) {\n result.copy(tempResult);\n }\n\n distance = det(lines[i]!.direction, {\n x: lines[i]!.point.x - result.x,\n y: lines[i]!.point.y - result.y\n });\n }\n }\n}\n\n/**\n * @zh 求解 ORCA 线性规划\n * @en Solve ORCA Linear Programming\n *\n * @zh 综合使用 2D 和 3D 线性规划求解最优速度\n * @en Use both 2D and 3D LP to solve for optimal velocity\n *\n * @param lines - @zh ORCA 约束线列表 @en List of ORCA constraint lines\n * @param numObstLines - @zh 障碍物约束线数量(优先级更高)@en Number of obstacle lines (higher priority)\n * @param maxSpeed - @zh 最大速度 @en Maximum speed\n * @param preferredVelocity - @zh 首选速度 @en Preferred velocity\n * @returns @zh 计算得到的新速度 @en Computed new velocity\n */\nexport function solveORCALinearProgram(\n lines: IORCALine[],\n numObstLines: number,\n maxSpeed: number,\n preferredVelocity: IVector2\n): Vector2 {\n const result = new Vector2();\n\n const lineFail = linearProgram2(lines, maxSpeed, preferredVelocity, false, result);\n\n if (lineFail < lines.length) {\n linearProgram3(lines, numObstLines, lineFail, maxSpeed, result);\n }\n\n return result;\n}\n","/**\n * @zh 障碍物构建器\n * @en Obstacle Builder\n */\n\nimport type { IVector2 } from '@esengine/ecs-framework-math';\nimport type { IObstacle, IObstacleVertex } from './ILocalAvoidance';\n\nconst EPSILON = 0.00001;\n\n/**\n * @zh 计算点相对于线段的位置(左侧判断)\n * @en Compute point position relative to line segment (left-of test)\n *\n * @zh 使用叉积判断点在向量的哪一侧\n * @en Use cross product to determine which side of the vector the point is on\n *\n * @zh 返回值 > 0 表示 p3 在向量 p1->p2 的左边\n * @en Returns > 0 if p3 is to the left of vector p1->p2\n */\nfunction leftOf(p1: IVector2, p2: IVector2, p3: IVector2): number {\n return (p1.x - p3.x) * (p2.y - p1.y) - (p1.y - p3.y) * (p2.x - p1.x);\n}\n\n/**\n * @zh 从顶点数组创建障碍物链表\n * @en Create obstacle linked list from vertex array\n *\n * @param vertices - @zh 顶点数组(CCW 顺序)@en Vertex array (CCW order)\n * @param startId - @zh 起始顶点 ID @en Starting vertex ID\n */\nexport function createObstacleVertices(\n vertices: readonly IVector2[],\n startId: number = 0\n): IObstacleVertex[] {\n const n = vertices.length;\n if (n < 2) {\n return [];\n }\n\n const obstacleVertices: IObstacleVertex[] = [];\n for (let i = 0; i < n; i++) {\n obstacleVertices.push({\n point: { x: vertices[i]!.x, y: vertices[i]!.y },\n direction: { x: 0, y: 0 },\n next: null as unknown as IObstacleVertex,\n previous: null as unknown as IObstacleVertex,\n isConvex: false,\n id: startId + i\n });\n }\n\n for (let i = 0; i < n; i++) {\n const curr = obstacleVertices[i]!;\n const next = obstacleVertices[(i + 1) % n]!;\n const prev = obstacleVertices[(i + n - 1) % n]!;\n\n curr.next = next;\n curr.previous = prev;\n\n const dx = next.point.x - curr.point.x;\n const dy = next.point.y - curr.point.y;\n const edgeLen = Math.sqrt(dx * dx + dy * dy);\n\n if (edgeLen > EPSILON) {\n curr.direction = { x: dx / edgeLen, y: dy / edgeLen };\n } else {\n curr.direction = { x: 1, y: 0 };\n }\n }\n\n for (let i = 0; i < n; i++) {\n const curr = obstacleVertices[i]!;\n const prev = curr.previous;\n const next = curr.next;\n curr.isConvex = leftOf(prev.point, curr.point, next.point) >= 0;\n }\n\n return obstacleVertices;\n}\n\n/**\n * @zh 从障碍物数组创建所有障碍物顶点\n * @en Create all obstacle vertices from obstacle array\n */\nexport function buildObstacleVertices(\n obstacles: readonly IObstacle[]\n): IObstacleVertex[] {\n const allVertices: IObstacleVertex[] = [];\n let nextId = 0;\n\n for (const obstacle of obstacles) {\n const vertices = createObstacleVertices(obstacle.vertices, nextId);\n allVertices.push(...vertices);\n nextId += vertices.length;\n }\n\n return allVertices;\n}\n\n/**\n * @zh 确保顶点按逆时针顺序排列\n * @en Ensure vertices are in counter-clockwise order\n */\nexport function ensureCCW(vertices: IVector2[], yAxisDown: boolean = false): IVector2[] {\n if (vertices.length < 3) {\n return vertices;\n }\n\n let signedArea = 0;\n for (let i = 0; i < vertices.length; i++) {\n const curr = vertices[i]!;\n const next = vertices[(i + 1) % vertices.length]!;\n signedArea += (curr.x * next.y - next.x * curr.y);\n }\n signedArea *= 0.5;\n\n const isCCW = yAxisDown ? signedArea < 0 : signedArea > 0;\n\n if (isCCW) {\n return vertices;\n }\n\n return [...vertices].reverse();\n}\n","/**\n * @zh ORCA 避让算法求解器\n * @en ORCA Avoidance Algorithm Solver\n *\n * @zh 实现最优互惠碰撞避免(ORCA)算法,用于多代理局部避让\n * @en Implements Optimal Reciprocal Collision Avoidance (ORCA) algorithm for multi-agent local avoidance\n */\n\nimport { Vector2, type IVector2 } from '@esengine/ecs-framework-math';\nimport type {\n IAvoidanceAgent,\n IObstacle,\n IObstacleVertex,\n IORCALine,\n IORCASolver,\n IORCASolverConfig\n} from './ILocalAvoidance';\nimport { DEFAULT_ORCA_CONFIG } from './ILocalAvoidance';\nimport { solveORCALinearProgram } from './LinearProgram';\nimport { buildObstacleVertices } from './ObstacleBuilder';\n\n/**\n * @zh 数值精度阈值\n * @en Numerical precision threshold\n */\nconst EPSILON = 0.00001;\n\nconst { det, dot, lengthSq, len } = Vector2;\n\n/**\n * @zh 向量归一化\n * @en Normalize vector\n */\nfunction normalize(v: IVector2): IVector2 {\n const length = len(v);\n if (length < EPSILON) {\n return { x: 0, y: 0 };\n }\n return { x: v.x / length, y: v.y / length };\n}\n\n/**\n * @zh ORCA 求解器实现\n * @en ORCA Solver implementation\n *\n * @zh 实现最优互惠碰撞避免算法,计算代理的安全速度\n * @en Implements Optimal Reciprocal Collision Avoidance algorithm to compute safe velocities for agents\n */\nexport class ORCASolver implements IORCASolver {\n private readonly config: Required<IORCASolverConfig>;\n\n constructor(config: IORCASolverConfig = {}) {\n this.config = { ...DEFAULT_ORCA_CONFIG, ...config };\n }\n\n /**\n * @zh 计算代理的新速度\n * @en Compute new velocity for agent\n *\n * @param agent - @zh 当前代理 @en Current agent\n * @param neighbors - @zh 邻近代理列表 @en List of neighboring agents\n * @param obstacles - @zh 障碍物列表 @en List of obstacles\n * @param deltaTime - @zh 时间步长 @en Time step\n * @returns @zh 计算得到的新速度 @en Computed new velocity\n */\n computeNewVelocity(\n agent: IAvoidanceAgent,\n neighbors: readonly IAvoidanceAgent[],\n obstacles: readonly IObstacle[],\n deltaTime: number\n ): IVector2 {\n const orcaLines: IORCALine[] = [];\n\n const obstacleVertices = buildObstacleVertices(obstacles);\n const numObstLines = this.createObstacleORCALines(agent, obstacleVertices, orcaLines);\n this.createAgentORCALines(agent, neighbors, deltaTime, orcaLines);\n\n return solveORCALinearProgram(\n orcaLines,\n numObstLines,\n agent.maxSpeed,\n agent.preferredVelocity\n );\n }\n\n /**\n * @zh 创建代理间的 ORCA 约束线\n * @en Create ORCA constraint lines for agent-agent avoidance\n */\n private createAgentORCALines(\n agent: IAvoidanceAgent,\n neighbors: readonly IAvoidanceAgent[],\n deltaTime: number,\n orcaLines: IORCALine[]\n ): void {\n const invTimeHorizon = 1.0 / agent.timeHorizon;\n\n for (const other of neighbors) {\n if (other.id === agent.id) continue;\n\n const relativePosition: IVector2 = {\n x: other.position.x - agent.position.x,\n y: other.position.y - agent.position.y\n };\n\n const relativeVelocity: IVector2 = {\n x: agent.velocity.x - other.velocity.x,\n y: agent.velocity.y - other.velocity.y\n };\n\n const distSq = lengthSq(relativePosition);\n const combinedRadius = agent.radius + other.radius;\n const combinedRadiusSq = combinedRadius * combinedRadius;\n\n const line: IORCALine = {\n point: { x: 0, y: 0 },\n direction: { x: 0, y: 0 }\n };\n\n let u: IVector2;\n\n if (distSq > combinedRadiusSq) {\n // @zh 无碰撞情况\n // @en No collision case\n const w: IVector2 = {\n x: relativeVelocity.x - invTimeHorizon * relativePosition.x,\n y: relativeVelocity.y - invTimeHorizon * relativePosition.y\n };\n\n const wLengthSq = lengthSq(w);\n const dotProduct1 = dot(w, relativePosition);\n\n if (dotProduct1 < 0 && dotProduct1 * dotProduct1 > combinedRadiusSq * wLengthSq) {\n // @zh 投影到截止圆\n // @en Project on cut-off circle\n const wLength = Math.sqrt(wLengthSq);\n const unitW = normalize(w);\n\n line.direction = { x: unitW.y, y: -unitW.x };\n u = {\n x: (combinedRadius * invTimeHorizon - wLength) * unitW.x,\n y: (combinedRadius * invTimeHorizon - wLength) * unitW.y\n };\n } else {\n // @zh 投影到腿部\n // @en Project on legs\n const leg = Math.sqrt(distSq - combinedRadiusSq);\n\n if (det(relativePosition, w) > 0) {\n line.direction = {\n x: (relativePosition.x * leg - relativePosition.y * combinedRadius) / distSq,\n y: (relativePosition.x * combinedRadius + relativePosition.y * leg) / distSq\n };\n } else {\n line.direction = {\n x: -(relativePosition.x * leg + relativePosition.y * combinedRadius) / distSq,\n y: -(-relativePosition.x * combinedRadius + relativePosition.y * leg) / distSq\n };\n }\n\n const dotProduct2 = dot(relativeVelocity, line.direction);\n u = {\n x: dotProduct2 * line.direction.x - relativeVelocity.x,\n y: dotProduct2 * line.direction.y - relativeVelocity.y\n };\n }\n } else {\n // @zh 碰撞情况\n // @en Collision case\n const invTimeStep = 1.0 / deltaTime;\n\n const w: IVector2 = {\n x: relativeVelocity.x - invTimeStep * relativePosition.x,\n y: relativeVelocity.y - invTimeStep * relativePosition.y\n };\n\n const wLength = len(w);\n const unitW = wLength > EPSILON\n ? { x: w.x / wLength, y: w.y / wLength }\n : { x: 1, y: 0 };\n\n line.direction = { x: unitW.y, y: -unitW.x };\n u = {\n x: (combinedRadius * invTimeStep - wLength) * unitW.x,\n y: (combinedRadius * invTimeStep - wLength) * unitW.y\n };\n }\n\n line.point = {\n x: agent.velocity.x + 0.5 * u.x,\n y: agent.velocity.y + 0.5 * u.y\n };\n\n orcaLines.push(line);\n }\n }\n\n /**\n * @zh 创建障碍物的 ORCA 约束线\n * @en Create ORCA constraint lines for obstacle avoidance\n */\n private createObstacleORCALines(\n agent: IAvoidanceAgent,\n obstacleVertices: IObstacleVertex[],\n orcaLines: IORCALine[]\n ): number {\n const invTimeHorizonObst = 1.0 / agent.timeHorizonObst;\n const radiusSq = agent.radius * agent.radius;\n let numObstLines = 0;\n\n for (const obstacle1 of obstacleVertices) {\n const obstacle2 = obstacle1.next;\n\n const relativePosition1: IVector2 = {\n x: obstacle1.point.x - agent.position.x,\n y: obstacle1.point.y - agent.position.y\n };\n const relativePosition2: IVector2 = {\n x: obstacle2.point.x - agent.position.x,\n y: obstacle2.point.y - agent.position.y\n };\n\n // @zh 跳过代理位于内侧的边(对于 CCW 多边形,内侧在左边)\n // @en Skip edges where agent is on interior side (for CCW polygons, interior is on left)\n const obstacleVector: IVector2 = {\n x: obstacle2.point.x - obstacle1.point.x,\n y: obstacle2.point.y - obstacle1.point.y\n };\n const signedDistToEdge = det(obstacleVector, relativePosition1);\n\n if (signedDistToEdge < -EPSILON) {\n continue;\n }\n\n // @zh 检查是否已被现有 ORCA 线覆盖\n // @en Check if already covered by existing ORCA lines\n let alreadyCovered = false;\n for (const existingLine of orcaLines) {\n const scaledRelPos1: IVector2 = {\n x: invTimeHorizonObst * relativePosition1.x - existingLine.point.x,\n y: invTimeHorizonObst * relativePosition1.y - existingLine.point.y\n };\n const scaledRelPos2: IVector2 = {\n x: invTimeHorizonObst * relativePosition2.x - existingLine.point.x,\n y: invTimeHorizonObst * relativePosition2.y - existingLine.point.y\n };\n\n if (det(scaledRelPos1, existingLine.direction) - invTimeHorizonObst * agent.radius >= -EPSILON &&\n det(scaledRelPos2, existingLine.direction) - invTimeHorizonObst * agent.radius >= -EPSILON) {\n alreadyCovered = true;\n break;\n }\n }\n\n if (alreadyCovered) {\n continue;\n }\n\n const distSq1 = lengthSq(relativePosition1);\n const distSq2 = lengthSq(relativePosition2);\n const obstacleVectorSq = lengthSq(obstacleVector);\n\n const s = obstacleVectorSq > EPSILON\n ? -dot(relativePosition1, obstacleVector) / obstacleVectorSq\n : 0;\n\n const distSqLineToEdge = lengthSq({\n x: -relativePosition1.x - s * obstacleVector.x,\n y: -relativePosition1.y - s * obstacleVector.y\n });\n\n const line: IORCALine = {\n point: { x: 0, y: 0 },\n direction: { x: 0, y: 0 }\n };\n\n // @zh 与左顶点碰撞\n // @en Collision with left vertex\n if (s < 0 && distSq1 <= radiusSq) {\n if (obstacle1.isConvex) {\n line.point = { x: 0, y: 0 };\n line.direction = normalize({ x: -relativePosition1.y, y: relativePosition1.x });\n orcaLines.push(line);\n numObstLines++;\n }\n continue;\n }\n\n // @zh 与右顶点碰撞\n // @en Collision with right vertex\n if (s > 1 && distSq2 <= radiusSq) {\n if (obstacle2.isConvex && det(relativePosition2, obstacle2.direction) >= 0) {\n line.point = { x: 0, y: 0 };\n line.direction = normalize({ x: -relativePosition2.y, y: relativePosition2.x });\n orcaLines.push(line);\n numObstLines++;\n }\n continue;\n }\n\n // @zh 与边碰撞\n // @en Collision with edge segment\n if (s >= 0 && s <= 1 && distSqLineToEdge <= radiusSq) {\n line.point = { x: 0, y: 0 };\n line.direction = { x: -obstacle1.direction.x, y: -obstacle1.direction.y };\n orcaLines.push(line);\n numObstLines++;\n continue;\n }\n\n // @zh 无碰撞 - 计算腿部方向\n // @en No collision - compute leg directions\n let obs1 = obstacle1;\n let obs2 = obstacle2;\n let leftLegDirection: IVector2;\n let rightLegDirection: IVector2;\n\n if (s < 0 && distSqLineToEdge <= radiusSq) {\n // @zh 从左顶点斜视\n // @en Obliquely viewed from left vertex\n if (!obstacle1.isConvex) continue;\n obs2 = obstacle1;\n\n const leg1 = Math.sqrt(Math.max(0, distSq1 - radiusSq));\n leftLegDirection = {\n x: (relativePosition1.x * leg1 - relativePosition1.y * agent.radius) / distSq1,\n y: (relativePosition1.x * agent.radius + relativePosition1.y * leg1) / distSq1\n };\n rightLegDirection = {\n x: (relativePosition1.x * leg1 + relativePosition1.y * agent.radius) / distSq1,\n y: (-relativePosition1.x * agent.radius + relativePosition1.y * leg1) / distSq1\n };\n } else if (s > 1 && distSqLineToEdge <= radiusSq) {\n // @zh 从右顶点斜视\n // @en Obliquely viewed from right vertex\n if (!obstacle2.isConvex) continue;\n obs1 = obstacle2;\n\n const leg2 = Math.sqrt(Math.max(0, distSq2 - radiusSq));\n leftLegDirection = {\n x: (relativePosition2.x * leg2 - relativePosition2.y * agent.radius) / distSq2,\n y: (relativePosition2.x * agent.radius + relativePosition2.y * leg2) / distSq2\n };\n rightLegDirection = {\n x: (relativePosition2.x * leg2 + relativePosition2.y * agent.radius) / distSq2,\n y: (-relativePosition2.x * agent.radius + relativePosition2.y * leg2) / distSq2\n };\n } else {\n // @zh 正常情况\n // @en Normal case\n if (obstacle1.isConvex) {\n const leg1 = Math.sqrt(Math.max(0, distSq1 - radiusSq));\n leftLegDirection = {\n x: (relativePosition1.x * leg1 - relativePosition1.y * agent.radius) / distSq1,\n y: (relativePosition1.x * agent.radius + relativePosition1.y * leg1) / distSq1\n };\n } else {\n leftLegDirection = { x: -obstacle1.direction.x, y: -obstacle1.direction.y };\n }\n\n if (obstacle2.isConvex) {\n const leg2 = Math.sqrt(Math.max(0, distSq2 - radiusSq));\n rightLegDirection = {\n x: (relativePosition2.x * leg2 + relativePosition2.y * agent.radius) / distSq2,\n y: (-relativePosition2.x * agent.radius + relativePosition2.y * leg2) / distSq2\n };\n } else {\n rightLegDirection = { x: obstacle1.direction.x, y: obstacle1.direction.y };\n }\n }\n\n // @zh 检查外部腿\n // @en Check for foreign legs\n const leftNeighbor = obs1.previous;\n let isLeftLegForeign = false;\n let isRightLegForeign = false;\n\n if (obs1.isConvex) {\n const negLeftNeighborDir = { x: -leftNeighbor.direction.x, y: -leftNeighbor.direction.y };\n if (det(leftLegDirection, negLeftNeighborDir) >= 0) {\n leftLegDirection = negLeftNeighborDir;\n isLeftLegForeign = true;\n }\n }\n\n if (obs2.isConvex) {\n if (det(rightLegDirection, obs2.direction) <= 0) {\n rightLegDirection = { x: obs2.direction.x, y: obs2.direction.y };\n isRightLegForeign = true;\n }\n }\n\n // @zh 计算截止中心点\n // @en Compute cut-off centers\n const leftCutoff: IVector2 = {\n x: invTimeHorizonObst * (obs1.point.x - agent.position.x),\n y: invTimeHorizonObst * (obs1.point.y - agent.position.y)\n };\n const rightCutoff: IVector2 = {\n x: invTimeHorizonObst * (obs2.point.x - agent.position.x),\n y: invTimeHorizonObst * (obs2.point.y - agent.position.y)\n };\n const cutoffVector: IVector2 = {\n x: rightCutoff.x - leftCutoff.x,\n y: rightCutoff.y - leftCutoff.y\n };\n\n const sameVertex = obs1 === obs2;\n const cutoffVectorSq = lengthSq(cutoffVector);\n const t = sameVertex\n ? 0.5\n : (cutoffVectorSq > EPSILON\n ? dot({ x: agent.velocity.x - leftCutoff.x, y: agent.velocity.y - leftCutoff.y }, cutoffVector) / cutoffVectorSq\n : 0.5);\n\n const tLeft = dot({ x: agent.velocity.x - leftCutoff.x, y: agent.velocity.y - leftCutoff.y }, leftLegDirection);\n const tRight = dot({ x: agent.velocity.x - rightCutoff.x, y: agent.velocity.y - rightCutoff.y }, rightLegDirection);\n\n // @zh 投影到左截止圆\n // @en Project on left cut-off circle\n if ((t < 0 && tLeft < 0) || (sameVertex && tLeft < 0 && tRight < 0)) {\n const unitW = normalize({ x: agent.velocity.x - leftCutoff.x, y: agent.velocity.y - leftCutoff.y });\n line.direction = { x: unitW.y, y: -unitW.x };\n line.point = {\n x: leftCutoff.x + agent.radius * invTimeHorizonObst * unitW.x,\n y: leftCutoff.y + agent.radius * invTimeHorizonObst * unitW.y\n };\n orcaLines.push(line);\n numObstLines++;\n continue;\n }\n\n // @zh 投影到右截止圆\n // @en Project on right cut-off circle\n if (t > 1 && tRight < 0) {\n const unitW = normalize({ x: agent.velocity.x - rightCutoff.x, y: agent.velocity.y - rightCutoff.y });\n line.direction = { x: unitW.y, y: -unitW.x };\n line.point = {\n x: rightCutoff.x + agent.radius * invTimeHorizonObst * unitW.x,\n y: rightCutoff.y + agent.radius * invTimeHorizonObst * unitW.y\n };\n orcaLines.push(line);\n numObstLines++;\n continue;\n }\n\n // @zh 计算投影距离\n // @en Compute projection distances\n const distSqCutoff = (t < 0 || t > 1 || sameVertex)\n ? Infinity\n : lengthSq({\n x: agent.velocity.x - (leftCutoff.x + t * cutoffVector.x),\n y: agent.velocity.y - (leftCutoff.y + t * cutoffVector.y)\n });\n\n const distSqLeft = tLeft < 0\n ? Infinity\n : lengthSq({\n x: agent.velocity.x - (leftCutoff.x + tLeft * leftLegDirection.x),\n y: agent.velocity.y - (leftCutoff.y + tLeft * leftLegDirection.y)\n });\n\n const distSqRight = tRight < 0\n ? Infinity\n : lengthSq({\n x: agent.velocity.x - (rightCutoff.x + tRight * rightLegDirection.x),\n y: agent.velocity.y - (rightCutoff.y + tRight * rightLegDirection.y)\n });\n\n // @zh 投影到截止线\n // @en Project on cut-off line\n if (distSqCutoff <= distSqLeft && distSqCutoff <= distSqRight) {\n line.direction = { x: -obs1.direction.x, y: -obs1.direction.y };\n line.point = {\n x: leftCutoff.x + agent.radius * invTimeHorizonObst * (-line.direction.y),\n y: leftCutoff.y + agent.radius * invTimeHorizonObst * line.direction.x\n };\n orcaLines.push(line);\n numObstLines++;\n continue;\n }\n\n // @zh 投影到左腿\n // @en Project on left leg\n if (distSqLeft <= distSqRight) {\n if (isLeftLegForeign) {\n continue;\n }\n\n line.direction = { x: leftLegDirection.x, y: leftLegDirection.y };\n line.point = {\n x: leftCutoff.x + agent.radius * invTimeHorizonObst * (-line.direction.y),\n y: leftCutoff.y + agent.radius * invTimeHorizonObst * line.direction.x\n };\n orcaLines.push(line);\n numObstLines++;\n continue;\n }\n\n // @zh 投影到右腿\n // @en Project on right leg\n if (isRightLegForeign) {\n continue;\n }\n\n line.direction = { x: -rightLegDirection.x, y: -rightLegDirection.y };\n line.point = {\n x: rightCutoff.x + agent.radius * invTimeHorizonObst * (-line.direction.y),\n y: rightCutoff.y + agent.radius * invTimeHorizonObst * line.direction.x\n };\n orcaLines.push(line);\n numObstLines++;\n }\n\n return numObstLines;\n }\n}\n\n/**\n * @zh 创建 ORCA 求解器\n * @en Create ORCA solver\n *\n * @param config - @zh 可选配置参数 @en Optional configuration parameters\n * @returns @zh ORCA 求解器实例 @en ORCA solver instance\n */\nexport function createORCASolver(config?: IORCASolverConfig): ORCASolver {\n return new ORCASolver(config);\n}\n","/**\n * @zh KD-Tree 空间索引\n * @en KD-Tree Spatial Index\n *\n * @zh 用于快速查询指定范围内的邻近代理\n * @en Used for fast neighbor queries within specified range\n */\n\nimport type { IVector2 } from '@esengine/ecs-framework-math';\nimport type { IAvoidanceAgent, ISpatialIndex, INeighborResult } from './ILocalAvoidance';\n\n// =============================================================================\n// KD-Tree 节点 | KD-Tree Node\n// =============================================================================\n\n/**\n * @zh KD-Tree 节点\n * @en KD-Tree node\n */\ninterface KDTreeNode {\n /**\n * @zh 代理索引(叶节点)或分割维度(内部节点)\n * @en Agent index (leaf) or split dimension (internal node)\n */\n agentIndex: number;\n\n /**\n * @zh 分割值\n * @en Split value\n */\n splitValue: number;\n\n /**\n * @zh 左子节点索引\n * @en Left child index\n */\n left: number;\n\n /**\n * @zh 右子节点索引\n * @en Right child index\n */\n right: number;\n\n /**\n * @zh 子树中代理索引的起始位置\n * @en Start index of agents in subtree\n */\n begin: number;\n\n /**\n * @zh 子树中代理索引的结束位置\n * @en End index of agents in subtree\n */\n end: number;\n\n /**\n * @zh 边界框最小值\n * @en Bounding box minimum\n */\n minX: number;\n minY: number;\n\n /**\n * @zh 边界框最大值\n * @en Bounding box maximum\n */\n maxX: number;\n maxY: number;\n}\n\n// =============================================================================\n// KD-Tree 实现 | KD-Tree Implementation\n// =============================================================================\n\n/**\n * @zh KD-Tree 空间索引\n * @en KD-Tree spatial index\n *\n * @zh 每帧重建,支持高效的范围查询\n * @en Rebuilt every frame, supports efficient range queries\n */\nexport class KDTree implements ISpatialIndex {\n private agents: IAvoidanceAgent[] = [];\n private agentIndices: number[] = [];\n private nodes: KDTreeNode[] = [];\n\n /**\n * @zh 最大叶节点大小\n * @en Maximum leaf size\n */\n private readonly maxLeafSize = 10;\n\n /**\n * @zh 构建 KD-Tree\n * @en Build KD-Tree\n */\n build(agents: readonly IAvoidanceAgent[]): void {\n this.agents = agents as IAvoidanceAgent[];\n this.agentIndices = [];\n this.nodes = [];\n\n if (agents.length === 0) {\n return;\n }\n\n // 初始化代理索引数组\n for (let i = 0; i < agents.length; i++) {\n this.agentIndices.push(i);\n }\n\n // 递归构建树\n this.buildRecursive(0, agents.length, 0);\n }\n\n /**\n * @zh 递归构建 KD-Tree\n * @en Recursively build KD-Tree\n */\n private buildRecursive(begin: number, end: number, depth: number): number {\n const nodeIndex = this.nodes.length;\n\n const node: KDTreeNode = {\n agentIndex: -1,\n splitValue: 0,\n left: -1,\n right: -1,\n begin,\n end,\n minX: Infinity,\n minY: Infinity,\n maxX: -Infinity,\n maxY: -Infinity\n };\n\n this.nodes.push(node);\n\n // 计算边界框\n for (let i = begin; i < end; i++) {\n const agent = this.agents[this.agentIndices[i]!]!;\n node.minX = Math.min(node.minX, agent.position.x);\n node.minY = Math.min(node.minY, agent.position.y);\n node.maxX = Math.max(node.maxX, agent.position.x);\n node.maxY = Math.max(node.maxY, agent.position.y);\n }\n\n const count = end - begin;\n\n if (count <= this.maxLeafSize) {\n // 叶节点\n return nodeIndex;\n }\n\n // 选择分割维度(交替使用 x 和 y)\n const splitDim = depth % 2;\n\n // 按分割维度排序\n if (splitDim === 0) {\n this.sortByX(begin, end);\n } else {\n this.sortByY(begin, end);\n }\n\n // 找到中点\n const mid = Math.floor((begin + end) / 2);\n const midAgent = this.agents[this.agentIndices[mid]!]!;\n node.splitValue = splitDim === 0 ? midAgent.position.x : midAgent.position.y;\n\n // 递归构建子树\n node.left = this.buildRecursive(begin, mid, depth + 1);\n node.right = this.buildRecursive(mid, end, depth + 1);\n\n return nodeIndex;\n }\n\n /**\n * @zh 按 X 坐标排序\n * @en Sort by X coordinate\n */\n private sortByX(begin: number, end: number): void {\n const indices = this.agentIndices;\n const agents = this.agents;\n\n for (let i = begin + 1; i < end; i++) {\n const key = indices[i]!;\n const keyX = agents[key]!.position.x;\n let j = i - 1;\n\n while (j >= begin && agents[indices[j]!]!.position.x > keyX) {\n indices[j + 1] = indices[j]!;\n j--;\n }\n indices[j + 1] = key;\n }\n }\n\n /**\n * @zh 按 Y 坐标排序\n * @en Sort by Y coordinate\n */\n private sortByY(begin: number, end: number): void {\n const indices = this.agentIndices;\n const agents = this.agents;\n\n for (let i = begin + 1; i < end; i++) {\n const key = indices[i]!;\n const keyY = agents[key]!.position.y;\n let j = i - 1;\n\n while (j >= begin && agents[indices[j]!]!.position.y > keyY) {\n indices[j + 1] = indices[j]!;\n j--;\n }\n indices[j + 1] = key;\n }\n }\n\n /**\n * @zh 查询邻居\n * @en Query neighbors\n */\n queryNeighbors(\n position: IVector2,\n radius: number,\n maxResults: number,\n excludeId?: number\n ): INeighborResult[] {\n const results: INeighborResult[] = [];\n const radiusSq = radius * radius;\n\n if (this.nodes.length === 0) {\n return results;\n }\n\n this.queryRecursive(0, position, radiusSq, maxResults, excludeId, results);\n\n // 按距离排序\n results.sort((a, b) => a.distanceSq - b.distanceSq);\n\n // 截取最大数量\n if (results.length > maxResults) {\n results.length = maxResults;\n }\n\n return results;\n }\n\n /**\n * @zh 递归查询\n * @en Recursive query\n */\n private queryRecursive(\n nodeIndex: number,\n position: IVector2,\n radiusSq: number,\n maxResults: number,\n excludeId: number | undefined,\n results: INeighborResult[]\n ): void {\n const node = this.nodes[nodeIndex];\n if (!node) return;\n\n // 检查边界框是否与查询圆相交\n const closestX = Math.max(node.minX, Math.min(position.x, node.maxX));\n const closestY = Math.max(node.minY, Math.min(position.y, node.maxY));\n const dx = position.x - closestX;\n const dy = position.y - closestY;\n const distSqToBBox = dx * dx + dy * dy;\n\n if (distSqToBBox > radiusSq) {\n return;\n }\n\n // 叶节点:检查所有代理\n if (node.left === -1 && node.right === -1) {\n for (let i = node.begin; i < node.end; i++) {\n const agentIndex = this.agentIndices[i]!;\n const agent = this.agents[agentIndex]!;\n\n if (excludeId !== undefined && agent.id === excludeId) {\n continue;\n }\n\n const adx = position.x - agent.position.x;\n const ady = position.y - agent.position.y;\n const distSq = adx * adx + ady * ady;\n\n if (distSq < radiusSq) {\n results.push({ agent, distanceSq: distSq });\n }\n }\n return;\n }\n\n // 递归查询子节点\n if (node.left !== -1) {\n this.queryRecursive(node.left, position, radiusSq, maxResults, excludeId, results);\n }\n if (node.right !== -1) {\n this.queryRecursive(node.right, position, radiusSq, maxResults, excludeId, results);\n }\n }\n\n /**\n * @zh 清空索引\n * @en Clear the index\n */\n clear(): void {\n this.agents = [];\n this.agentIndices = [];\n this.nodes = [];\n }\n\n /**\n * @zh 获取代理数量\n * @en Get agent count\n */\n get agentCount(): number {\n return this.agents.length;\n }\n}\n\n/**\n * @zh 创建 KD-Tree\n * @en Create KD-Tree\n */\nexport function createKDTree(): KDTree {\n return new KDTree();\n}\n"],"mappings":";;;;;;AAgVO,IAAMA,sBAAmD;EAC5DC,oBAAoB;EACpBC,wBAAwB;EACxBC,UAAU,IAAI;EACdC,SAAS;AACb;AAMO,IAAMC,uBAAuB;EAChCC,QAAQ;EACRC,UAAU;EACVC,cAAc;EACdC,cAAc;EACdC,aAAa;EACbC,iBAAiB;AACrB;;;AC1VA,SAASC,eAA8B;AAWvC,IAAMC,UAAU;AAEhB,IAAM,EAAEC,KAAKC,KAAKC,SAAQ,IAAKC;AAqB/B,SAASC,eACLC,OACAC,QACAC,QACAC,aACAC,cACAC,QAAe;AAEf,QAAMC,OAAON,MAAMC,MAAAA;AACnB,QAAMM,aAAaZ,IAAIW,KAAKE,OAAOF,KAAKG,SAAS;AACjD,QAAMC,eAAeH,aAAaA,aAAaL,SAASA,SAASL,SAASS,KAAKE,KAAK;AAEpF,MAAIE,eAAe,GAAG;AAClB,WAAO;EACX;AAEA,QAAMC,mBAAmBC,KAAKC,KAAKH,YAAAA;AACnC,MAAII,QAAQ,CAACP,aAAaI;AAC1B,MAAII,SAAS,CAACR,aAAaI;AAE3B,WAASK,IAAI,GAAGA,IAAIf,QAAQe,KAAK;AAC7B,UAAMC,aAAajB,MAAMgB,CAAAA;AACzB,UAAME,cAActB,IAAIU,KAAKG,WAAWQ,WAAWR,SAAS;AAC5D,UAAMU,YAAYvB,IAAIqB,WAAWR,WAAW;MACxCW,GAAGd,KAAKE,MAAMY,IAAIH,WAAWT,MAAMY;MACnCC,GAAGf,KAAKE,MAAMa,IAAIJ,WAAWT,MAAMa;IACvC,CAAA;AAEA,QAAIT,KAAKU,IAAIJ,WAAAA,KAAgBxB,SAAS;AAClC,UAAIyB,YAAY,GAAG;AACf,eAAO;MACX;AACA;IACJ;AAEA,UAAMI,KAAIJ,YAAYD;AAEtB,QAAIA,eAAe,GAAG;AAClBH,eAASH,KAAKY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,SAASE,IAAI0B;AACxB,UAAMG,eAAeF,KAAKA,KAAKC,KAAKA;AAEpC,QAAIC,eAAeV,UAAU;AACzB;IACJ;AAGA,QAAIlC,KAAKG,SAAS,MAAMH,KAAKI,UAAU,IAAI;AACvC,eAASX,IAAIO,KAAKJ,OAAOH,IAAIO,KAAKH,KAAKJ,KAAK;AACxC,cAAMQ,aAAa,KAAKb,aAAaK,CAAAA;AACrC,cAAMiB,QAAQ,KAAKvB,OAAOc,UAAAA;AAE1B,YAAI+B,cAAca,UAAanC,MAAMoC,OAAOd,WAAW;AACnD;QACJ;AAEA,cAAMe,MAAMlC,SAASC,IAAIJ,MAAMG,SAASC;AACxC,cAAMkC,MAAMnC,SAASE,IAAIL,MAAMG,SAASE;AACxC,cAAMkC,SAASF,MAAMA,MAAMC,MAAMA;AAEjC,YAAIC,SAASf,UAAU;AACnBD,kBAAQvC,KAAK;YAAEgB;YAAO6B,YAAYU;UAAO,CAAA;QAC7C;MACJ;AACA;IACJ;AAGA,QAAIjD,KAAKG,SAAS,IAAI;AAClB,WAAKgC,eAAenC,KAAKG,MAAMU,UAAUqB,UAAUH,YAAYC,WAAWC,OAAAA;IAC9E;AACA,QAAIjC,KAAKI,UAAU,IAAI;AACnB,WAAK+B,eAAenC,KAAKI,OAAOS,UAAUqB,UAAUH,YAAYC,WAAWC,OAAAA;IAC/E;EACJ;;;;;EAMAiB,QAAc;AACV,SAAK/D,SAAS,CAAA;AACd,SAAKC,eAAe,CAAA;AACpB,SAAKC,QAAQ,CAAA;EACjB;;;;;EAMA,IAAI8D,aAAqB;AACrB,WAAO,KAAKhE,OAAOK;EACvB;AACJ;AA9OaN;AAAN,IAAMA,SAAN;AAoPA,SAASkE,eAAAA;AACZ,SAAO,IAAIlE,OAAAA;AACf;AAFgBkE;","names":["DEFAULT_ORCA_CONFIG","defaultTimeHorizon","defaultTimeHorizonObst","timeStep","epsilon","DEFAULT_AGENT_PARAMS","radius","maxSpeed","neighborDist","maxNeighbors","timeHorizon","timeHorizonObst","Vector2","EPSILON","dot","det","lengthSq","Vector2","linearProgram1","lines","lineNo","radius","optVelocity","directionOpt","result","line","dotProduct","point","direction","discriminant","sqrtDiscriminant","Math","sqrt","tLeft","tRight","i","constraint","denominator","numerator","x","y","abs","t","min","max","linearProgram2","len","length","detVal","tempResult","clone","copy","linearProgram3","numObstLines","beginLine","distance","projLines","j","push","line1","line2","newLine","determinant","diff","dirDiff","dirLen","solveORCALinearProgram","maxSpeed","preferredVelocity","lineFail","EPSILON","leftOf","p1","p2","p3","x","y","createObstacleVertices","vertices","startId","n","length","obstacleVertices","i","push","point","direction","next","previous","isConvex","id","curr","prev","dx","dy","edgeLen","Math","sqrt","buildObstacleVertices","obstacles","allVertices","nextId","obstacle","ensureCCW","yAxisDown","signedArea","isCCW","reverse","Vector2","EPSILON","det","dot","lengthSq","len","Vector2","normalize","v","length","x","y","ORCASolver","config","DEFAULT_ORCA_CONFIG","computeNewVelocity","agent","neighbors","obstacles","deltaTime","orcaLines","obstacleVertices","buildObstacleVertices","numObstLines","createObstacleORCALines","createAgentORCALines","solveORCALinearProgram","maxSpeed","preferredVelocity","invTimeHorizon","timeHorizon","other","id","relativePosition","position","relativeVelocity","velocity","distSq","combinedRadius","radius","combinedRadiusSq","line","point","direction","u","w","wLengthSq","dotProduct1","wLength","Math","sqrt","unitW","leg","dotProduct2","invTimeStep","push","invTimeHorizonObst","timeHorizonObst","radiusSq","obstacle1","obstacle2","next","relativePosition1","relativePosition2","obstacleVector","signedDistToEdge","alreadyCovered","existingLine","scaledRelPos1","scaledRelPos2","distSq1","distSq2","obstacleVectorSq","s","distSqLineToEdge","isConvex","obs1","obs2","leftLegDirection","rightLegDirection","leg1","max","leg2","leftNeighbor","previous","isLeftLegForeign","isRightLegForeign","negLeftNeighborDir","leftCutoff","rightCutoff","cutoffVector","sameVertex","cutoffVectorSq","t","tLeft","tRight","distSqCutoff","Infinity","distSqLeft","distSqRight","createORCASolver","KDTree","agents","agentIndices","nodes","maxLeafSize","build","length","i","push","buildRecursive","begin","end","depth","nodeIndex","node","agentIndex","splitValue","left","right","minX","Infinity","minY","maxX","maxY","agent","Math","min","position","x","y","max","count","splitDim","sortByX","sortByY","mid","floor","midAgent","indices","key","keyX","j","keyY","queryNeighbors","radius","maxResults","excludeId","results","radiusSq","queryRecursive","sort","a","b","distanceSq","closestX","closestY","dx","dy","distSqToBBox","undefined","id","adx","ady","distSq","clear","agentCount","createKDTree"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-KEYTX37K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
__name,
|
|
8
|
+
__publicField
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=chunk-T626JPC7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|