@esengine/pathfinding 13.2.0 → 13.3.1

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.
@@ -0,0 +1,216 @@
1
+ import { Vector2, IVector2 } from '@esengine/ecs-framework-math';
2
+ import { I as IORCALine, e as IORCASolver, c as IORCASolverConfig, a as IAvoidanceAgent, b as IObstacle, g as ISpatialIndex, f as INeighborResult } from './CollisionResolver-CSgWsegP.js';
3
+
4
+ /**
5
+ * @zh 2D 线性规划求解器
6
+ * @en 2D Linear Programming Solver
7
+ *
8
+ * @zh 用于 ORCA 算法中的速度优化求解
9
+ * @en Used for velocity optimization in ORCA algorithm
10
+ */
11
+
12
+ /**
13
+ * @zh 2D 线性规划
14
+ * @en 2D Linear Programming
15
+ *
16
+ * @zh 在多个半平面约束下找到最优速度
17
+ * @en Find optimal velocity under multiple half-plane constraints
18
+ *
19
+ * @param lines - @zh 约束线列表 @en List of constraint lines
20
+ * @param radius - @zh 最大速度(圆盘半径)@en Maximum speed (disk radius)
21
+ * @param optVelocity - @zh 首选速度 @en Preferred velocity
22
+ * @param directionOpt - @zh 是否优化方向 @en Whether to optimize direction
23
+ * @param result - @zh 结果向量(输出)@en Result vector (output)
24
+ * @returns @zh 第一个失败的约束索引,如果成功则返回 lines.length @en Index of first failed constraint, or lines.length if successful
25
+ */
26
+ declare function linearProgram2(lines: readonly IORCALine[], radius: number, optVelocity: IVector2, directionOpt: boolean, result: Vector2): number;
27
+ /**
28
+ * @zh 3D 线性规划(回退方案)
29
+ * @en 3D Linear Programming (fallback)
30
+ *
31
+ * @zh 当 2D 线性规划失败时,使用此方法找到最小穿透的速度
32
+ * @en When 2D LP fails, use this to find velocity with minimum penetration
33
+ *
34
+ * @zh 重要:障碍物约束线(前 numObstLines 条)具有最高优先级,绝不会被违反
35
+ * @en Important: Obstacle constraint lines (first numObstLines) have highest priority and are never violated
36
+ *
37
+ * @param lines - @zh 约束线列表 @en List of constraint lines
38
+ * @param numObstLines - @zh 障碍物约束线数量 @en Number of obstacle constraint lines
39
+ * @param beginLine - @zh 开始处理的线索引 @en Index of line to start processing
40
+ * @param radius - @zh 最大速度 @en Maximum speed
41
+ * @param result - @zh 结果向量(输入/输出)@en Result vector (input/output)
42
+ */
43
+ declare function linearProgram3(lines: IORCALine[], numObstLines: number, beginLine: number, radius: number, result: Vector2): void;
44
+ /**
45
+ * @zh ORCA 线性规划求解结果
46
+ * @en ORCA Linear Programming solve result
47
+ */
48
+ interface IORCALPResult {
49
+ /**
50
+ * @zh 计算得到的速度
51
+ * @en Computed velocity
52
+ */
53
+ velocity: Vector2;
54
+ /**
55
+ * @zh 是否找到可行解(满足所有约束)
56
+ * @en Whether a feasible solution was found (satisfies all constraints)
57
+ */
58
+ feasible: boolean;
59
+ /**
60
+ * @zh 违反的约束数量
61
+ * @en Number of violated constraints
62
+ */
63
+ violatedConstraints: number;
64
+ }
65
+ /**
66
+ * @zh 求解 ORCA 线性规划
67
+ * @en Solve ORCA Linear Programming
68
+ *
69
+ * @zh 综合使用 2D 和 3D 线性规划求解最优速度
70
+ * @en Use both 2D and 3D LP to solve for optimal velocity
71
+ *
72
+ * @zh 注意:此函数不包含回退逻辑,调用方应通过返回的 feasible 标志判断是否需要流量控制
73
+ * @en Note: This function does not include fallback logic, caller should check feasible flag for flow control
74
+ *
75
+ * @param lines - @zh ORCA 约束线列表 @en List of ORCA constraint lines
76
+ * @param numObstLines - @zh 障碍物约束线数量 @en Number of obstacle lines
77
+ * @param maxSpeed - @zh 最大速度 @en Maximum speed
78
+ * @param preferredVelocity - @zh 首选速度 @en Preferred velocity
79
+ * @returns @zh 求解结果,包含速度和可行性标志 @en Solve result with velocity and feasibility flag
80
+ */
81
+ declare function solveORCALinearProgram(lines: IORCALine[], numObstLines: number, maxSpeed: number, preferredVelocity: IVector2): IORCALPResult;
82
+
83
+ /**
84
+ * @zh ORCA 避让算法求解器
85
+ * @en ORCA Avoidance Algorithm Solver
86
+ *
87
+ * @zh 实现最优互惠碰撞避免(ORCA)算法,用于多代理局部避让
88
+ * @en Implements Optimal Reciprocal Collision Avoidance (ORCA) algorithm for multi-agent local avoidance
89
+ */
90
+
91
+ /**
92
+ * @zh ORCA 求解器实现
93
+ * @en ORCA Solver implementation
94
+ *
95
+ * @zh 实现最优互惠碰撞避免算法,计算代理的安全速度
96
+ * @en Implements Optimal Reciprocal Collision Avoidance algorithm to compute safe velocities for agents
97
+ */
98
+ declare class ORCASolver implements IORCASolver {
99
+ private readonly config;
100
+ constructor(config?: IORCASolverConfig);
101
+ /**
102
+ * @zh 计算代理的新速度
103
+ * @en Compute new velocity for agent
104
+ *
105
+ * @param agent - @zh 当前代理 @en Current agent
106
+ * @param neighbors - @zh 邻近代理列表 @en List of neighboring agents
107
+ * @param obstacles - @zh 障碍物列表 @en List of obstacles
108
+ * @param deltaTime - @zh 时间步长 @en Time step
109
+ * @returns @zh 计算得到的新速度 @en Computed new velocity
110
+ */
111
+ computeNewVelocity(agent: IAvoidanceAgent, neighbors: readonly IAvoidanceAgent[], obstacles: readonly IObstacle[], deltaTime: number): IVector2;
112
+ /**
113
+ * @zh 计算代理的新速度(带完整结果)
114
+ * @en Compute new velocity for agent (with full result)
115
+ *
116
+ * @param agent - @zh 当前代理 @en Current agent
117
+ * @param neighbors - @zh 邻近代理列表 @en List of neighboring agents
118
+ * @param obstacles - @zh 障碍物列表 @en List of obstacles
119
+ * @param deltaTime - @zh 时间步长 @en Time step
120
+ * @returns @zh 完整求解结果 @en Full solve result
121
+ */
122
+ computeNewVelocityWithResult(agent: IAvoidanceAgent, neighbors: readonly IAvoidanceAgent[], obstacles: readonly IObstacle[], deltaTime: number): IORCALPResult & {
123
+ numLines: number;
124
+ };
125
+ /**
126
+ * @zh 创建代理间的 ORCA 约束线
127
+ * @en Create ORCA constraint lines for agent-agent avoidance
128
+ */
129
+ private createAgentORCALines;
130
+ /**
131
+ * @zh 创建障碍物的 ORCA 约束线
132
+ * @en Create ORCA constraint lines for obstacle avoidance
133
+ */
134
+ private createObstacleORCALines;
135
+ }
136
+ /**
137
+ * @zh 创建 ORCA 求解器
138
+ * @en Create ORCA solver
139
+ *
140
+ * @param config - @zh 可选配置参数 @en Optional configuration parameters
141
+ * @returns @zh ORCA 求解器实例 @en ORCA solver instance
142
+ */
143
+ declare function createORCASolver(config?: IORCASolverConfig): ORCASolver;
144
+
145
+ /**
146
+ * @zh KD-Tree 空间索引
147
+ * @en KD-Tree Spatial Index
148
+ *
149
+ * @zh 用于快速查询指定范围内的邻近代理
150
+ * @en Used for fast neighbor queries within specified range
151
+ */
152
+
153
+ /**
154
+ * @zh KD-Tree 空间索引
155
+ * @en KD-Tree spatial index
156
+ *
157
+ * @zh 每帧重建,支持高效的范围查询
158
+ * @en Rebuilt every frame, supports efficient range queries
159
+ */
160
+ declare class KDTree implements ISpatialIndex {
161
+ private agents;
162
+ private agentIndices;
163
+ private nodes;
164
+ /**
165
+ * @zh 最大叶节点大小
166
+ * @en Maximum leaf size
167
+ */
168
+ private readonly maxLeafSize;
169
+ /**
170
+ * @zh 构建 KD-Tree
171
+ * @en Build KD-Tree
172
+ */
173
+ build(agents: readonly IAvoidanceAgent[]): void;
174
+ /**
175
+ * @zh 递归构建 KD-Tree
176
+ * @en Recursively build KD-Tree
177
+ */
178
+ private buildRecursive;
179
+ /**
180
+ * @zh 按 X 坐标排序
181
+ * @en Sort by X coordinate
182
+ */
183
+ private sortByX;
184
+ /**
185
+ * @zh 按 Y 坐标排序
186
+ * @en Sort by Y coordinate
187
+ */
188
+ private sortByY;
189
+ /**
190
+ * @zh 查询邻居
191
+ * @en Query neighbors
192
+ */
193
+ queryNeighbors(position: IVector2, radius: number, maxResults: number, excludeId?: number): INeighborResult[];
194
+ /**
195
+ * @zh 递归查询
196
+ * @en Recursive query
197
+ */
198
+ private queryRecursive;
199
+ /**
200
+ * @zh 清空索引
201
+ * @en Clear the index
202
+ */
203
+ clear(): void;
204
+ /**
205
+ * @zh 获取代理数量
206
+ * @en Get agent count
207
+ */
208
+ get agentCount(): number;
209
+ }
210
+ /**
211
+ * @zh 创建 KD-Tree
212
+ * @en Create KD-Tree
213
+ */
214
+ declare function createKDTree(): KDTree;
215
+
216
+ export { KDTree as K, ORCASolver as O, createKDTree as a, linearProgram3 as b, createORCASolver as c, linearProgram2 as l, solveORCALinearProgram as s };
@@ -1,6 +1,6 @@
1
- import { k as IObstacleVertex, b as IObstacle } from './KDTree-2rs2EXvm.js';
2
- export { h as DEFAULT_AGENT_PARAMS, D as DEFAULT_ORCA_CONFIG, a as IAvoidanceAgent, f as INeighborResult, I as IORCALine, d as IORCAResult, e as IORCASolver, c as IORCASolverConfig, g as ISpatialIndex, K as KDTree, O as ORCASolver, j as createKDTree, i as createORCASolver } from './KDTree-2rs2EXvm.js';
3
- export { l as linearProgram2, a as linearProgram3, s as solveORCALinearProgram } from './LinearProgram-DyD3pI6v.js';
1
+ import { m as IObstacleVertex, b as IObstacle } from './CollisionResolver-CSgWsegP.js';
2
+ export { C as CollisionResolver, j as DEFAULT_AGENT_PARAMS, k as DEFAULT_COLLISION_CONFIG, D as DEFAULT_ORCA_CONFIG, E as EMPTY_COLLISION, a as IAvoidanceAgent, i as ICollisionResolverConfig, h as ICollisionResult, f as INeighborResult, I as IORCALine, d as IORCAResult, e as IORCASolver, c as IORCASolverConfig, g as ISpatialIndex, l as createCollisionResolver } from './CollisionResolver-CSgWsegP.js';
3
+ export { K as KDTree, O as ORCASolver, a as createKDTree, c as createORCASolver, l as linearProgram2, b as linearProgram3, s as solveORCALinearProgram } from './KDTree-BRpn7O8K.js';
4
4
  import { IVector2 } from '@esengine/ecs-framework-math';
5
5
  export { IVector2 } from '@esengine/ecs-framework-math';
6
6
 
@@ -17,11 +17,33 @@ export { IVector2 } from '@esengine/ecs-framework-math';
17
17
  * @param startId - @zh 起始顶点 ID @en Starting vertex ID
18
18
  */
19
19
  declare function createObstacleVertices(vertices: readonly IVector2[], startId?: number): IObstacleVertex[];
20
+ /**
21
+ * @zh 构建障碍物顶点的选项
22
+ * @en Options for building obstacle vertices
23
+ */
24
+ interface IBuildObstacleOptions {
25
+ /**
26
+ * @zh 是否使用 Y 轴向下的坐标系(如 Canvas/屏幕坐标)
27
+ * @en Whether using Y-axis down coordinate system (like Canvas/screen coords)
28
+ *
29
+ * @zh 这会影响障碍物顶点顺序的判断
30
+ * @en This affects obstacle vertex order detection
31
+ *
32
+ * @default false
33
+ */
34
+ yAxisDown?: boolean;
35
+ }
20
36
  /**
21
37
  * @zh 从障碍物数组创建所有障碍物顶点
22
38
  * @en Create all obstacle vertices from obstacle array
39
+ *
40
+ * @zh 自动检测并纠正顶点顺序为 CCW(逆时针)
41
+ * @en Automatically detects and corrects vertex order to CCW (counter-clockwise)
42
+ *
43
+ * @param obstacles - @zh 障碍物数组 @en Array of obstacles
44
+ * @param options - @zh 构建选项 @en Build options
23
45
  */
24
- declare function buildObstacleVertices(obstacles: readonly IObstacle[]): IObstacleVertex[];
46
+ declare function buildObstacleVertices(obstacles: readonly IObstacle[], options?: IBuildObstacleOptions): IObstacleVertex[];
25
47
  /**
26
48
  * @zh 确保顶点按逆时针顺序排列
27
49
  * @en Ensure vertices are in counter-clockwise order
package/dist/avoidance.js CHANGED
@@ -1,10 +1,14 @@
1
- import "./chunk-KEYTX37K.js";
1
+ import "./chunk-H5EFZBBT.js";
2
2
  import {
3
+ CollisionResolver,
3
4
  DEFAULT_AGENT_PARAMS,
5
+ DEFAULT_COLLISION_CONFIG,
4
6
  DEFAULT_ORCA_CONFIG,
7
+ EMPTY_COLLISION,
5
8
  KDTree,
6
9
  ORCASolver,
7
10
  buildObstacleVertices,
11
+ createCollisionResolver,
8
12
  createKDTree,
9
13
  createORCASolver,
10
14
  createObstacleVertices,
@@ -12,14 +16,18 @@ import {
12
16
  linearProgram2,
13
17
  linearProgram3,
14
18
  solveORCALinearProgram
15
- } from "./chunk-JTZP55BJ.js";
19
+ } from "./chunk-3VEX32JO.js";
16
20
  import "./chunk-T626JPC7.js";
17
21
  export {
22
+ CollisionResolver,
18
23
  DEFAULT_AGENT_PARAMS,
24
+ DEFAULT_COLLISION_CONFIG,
19
25
  DEFAULT_ORCA_CONFIG,
26
+ EMPTY_COLLISION,
20
27
  KDTree,
21
28
  ORCASolver,
22
29
  buildObstacleVertices,
30
+ createCollisionResolver,
23
31
  createKDTree,
24
32
  createORCASolver,
25
33
  createObstacleVertices,