@esengine/pathfinding 13.2.0 → 13.3.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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { I as IPathfinder, a as IPathfindingMap, b as IPathfindingOptions, c as IPathResult, H as HeuristicFunction, d as IPathNode, e as IPoint, f as IIncrementalPathfinder, g as IIncrementalPathfindingOptions, h as IPathRequest, i as IPathProgress, j as IIncrementalPathResult, k as IPathValidator, l as IPathValidationResult, m as IPathSmoother } from './IIncrementalPathfinding-3qs7e_pO.js';
2
- export { D as DEFAULT_PATHFINDING_OPTIONS, t as DEFAULT_REPLANNING_CONFIG, E as EMPTY_PATH_RESULT, u as EMPTY_PROGRESS, s as IReplanningConfig, L as LineOfSightCheck, P as PathfindingState, q as chebyshevDistance, n as createPoint, p as euclideanDistance, o as manhattanDistance, r as octileDistance } from './IIncrementalPathfinding-3qs7e_pO.js';
3
- 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, b as IObstacle, g as ISpatialIndex, K as KDTree, O as ORCASolver, j as createKDTree, i as createORCASolver } from './KDTree-2rs2EXvm.js';
4
- export { s as solveORCALinearProgram } from './LinearProgram-DyD3pI6v.js';
1
+ import { I as IPathfinder, a as IPathfindingMap, b as IPathfindingOptions, c as IPathResult, H as HeuristicFunction, d as IPathNode, e as IPoint, f as IPathValidator, g as IPathValidationResult, h as IPathSmoother } from './FlowController-Dc3nuLq5.js';
2
+ export { ap as CollisionResolverAdapter, ab as DEFAULT_FLOW_CONTROLLER_CONFIG, p as DEFAULT_HPA_CONFIG, ao as DEFAULT_ORCA_PARAMS, D as DEFAULT_PATHFINDING_OPTIONS, r as DEFAULT_PATH_CACHE_CONFIG, C as DEFAULT_REPLANNING_CONFIG, a9 as EMPTY_COLLISION_RESULT, E as EMPTY_PATH_RESULT, a8 as EMPTY_PLAN_RESULT, F as EMPTY_PROGRESS, ar as FlowController, ag as GridPathfinderAdapter, l as HPAPathfinder, Z as IAvoidanceAgentData, $ as IAvoidanceResult, a2 as ICollisionResolver, a3 as ICongestionZone, N as IDynamicObstacle, a4 as IFlowAgentData, a5 as IFlowControlResult, a7 as IFlowController, a6 as IFlowControllerConfig, au as IGridPathfinderAdapterConfig, t as IHPAConfig, av as IIncrementalGridPathPlannerConfig, W as IIncrementalPathPlanner, X as IIncrementalPathRequest, w as IIncrementalPathResult, x as IIncrementalPathfinder, z as IIncrementalPathfinderConfig, y as IIncrementalPathfindingOptions, a0 as ILocalAvoidance, a1 as INavCollisionResult, Y as INavPathProgress, K as INavPolygon, S as INavVector2, at as IORCAParams, _ as IObstacleData, s as IPathCacheConfig, U as IPathPlanOptions, T as IPathPlanResult, V as IPathPlanner, v as IPathProgress, u as IPathRequest, M as IPortal, A as IReplanningConfig, G as IncrementalAStarPathfinder, ak as IncrementalGridPathPlannerAdapter, L as LineOfSightCheck, Q as NavMesh, ae as NavMeshPathPlannerAdapter, am as ORCALocalAvoidanceAdapter, O as ObstacleType, aa as PassPermission, P as PathCache, ac as PathPlanState, B as PathfindingState, k as chebyshevDistance, ah as createAStarPlanner, aq as createDefaultCollisionResolver, as as createFlowController, n as createHPAPathfinder, aj as createHPAPlanner, J as createIncrementalAStarPathfinder, al as createIncrementalAStarPlanner, ai as createJPSPlanner, R as createNavMesh, af as createNavMeshPathPlanner, an as createORCAAvoidance, q as createPathCache, i as createPoint, j as euclideanDistance, ad as isIncrementalPlanner, m as manhattanDistance, o as octileDistance } from './FlowController-Dc3nuLq5.js';
3
+ 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, b as IObstacle, g as ISpatialIndex, l as createCollisionResolver } from './CollisionResolver-CSgWsegP.js';
4
+ export { K as KDTree, O as ORCASolver, a as createKDTree, c as createORCASolver, s as solveORCALinearProgram } from './KDTree-BRpn7O8K.js';
5
5
  export { IVector2 } from '@esengine/ecs-framework-math';
6
6
 
7
7
  /**
@@ -456,322 +456,6 @@ declare class GridPathfinder implements IPathfinder {
456
456
  */
457
457
  declare function createGridPathfinder(map: GridMap, config?: IGridPathfinderConfig): GridPathfinder;
458
458
 
459
- /**
460
- * @zh 路径缓存模块
461
- * @en Path Cache Module
462
- *
463
- * @zh 缓存已计算的路径,避免重复计算相同起点终点的路径
464
- * @en Cache computed paths to avoid recalculating paths with the same start and end points
465
- */
466
-
467
- /**
468
- * @zh 缓存配置
469
- * @en Cache configuration
470
- */
471
- interface IPathCacheConfig {
472
- /**
473
- * @zh 最大缓存条目数
474
- * @en Maximum number of cache entries
475
- */
476
- maxEntries: number;
477
- /**
478
- * @zh 缓存过期时间(毫秒),0 表示不过期
479
- * @en Cache expiration time in milliseconds, 0 means no expiration
480
- */
481
- ttlMs: number;
482
- /**
483
- * @zh 是否启用近似匹配(在一定范围内的起点/终点视为相同)
484
- * @en Whether to enable approximate matching (start/end within range considered same)
485
- */
486
- enableApproximateMatch: boolean;
487
- /**
488
- * @zh 近似匹配范围
489
- * @en Approximate matching range
490
- */
491
- approximateRange: number;
492
- }
493
- /**
494
- * @zh 默认缓存配置
495
- * @en Default cache configuration
496
- */
497
- declare const DEFAULT_PATH_CACHE_CONFIG: IPathCacheConfig;
498
- /**
499
- * @zh 路径缓存
500
- * @en Path Cache
501
- *
502
- * @zh 缓存已计算的路径,支持 LRU 淘汰策略和 TTL 过期
503
- * @en Cache computed paths with LRU eviction and TTL expiration
504
- *
505
- * @example
506
- * ```typescript
507
- * const cache = new PathCache({ maxEntries: 500 });
508
- * const cached = cache.get(0, 0, 10, 10, mapVersion);
509
- * if (!cached) {
510
- * const result = pathfinder.findPath(0, 0, 10, 10);
511
- * cache.set(0, 0, 10, 10, result, mapVersion);
512
- * }
513
- * ```
514
- */
515
- declare class PathCache {
516
- private readonly config;
517
- private readonly cache;
518
- private readonly accessOrder;
519
- constructor(config?: Partial<IPathCacheConfig>);
520
- /**
521
- * @zh 获取缓存的路径
522
- * @en Get cached path
523
- *
524
- * @param startX - @zh 起点 X 坐标 @en Start X coordinate
525
- * @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
526
- * @param endX - @zh 终点 X 坐标 @en End X coordinate
527
- * @param endY - @zh 终点 Y 坐标 @en End Y coordinate
528
- * @param mapVersion - @zh 地图版本号 @en Map version number
529
- * @returns @zh 缓存的路径结果或 null @en Cached path result or null
530
- */
531
- get(startX: number, startY: number, endX: number, endY: number, mapVersion: number): IPathResult | null;
532
- /**
533
- * @zh 设置缓存路径
534
- * @en Set cached path
535
- *
536
- * @param startX - @zh 起点 X 坐标 @en Start X coordinate
537
- * @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
538
- * @param endX - @zh 终点 X 坐标 @en End X coordinate
539
- * @param endY - @zh 终点 Y 坐标 @en End Y coordinate
540
- * @param result - @zh 路径结果 @en Path result
541
- * @param mapVersion - @zh 地图版本号 @en Map version number
542
- */
543
- set(startX: number, startY: number, endX: number, endY: number, result: IPathResult, mapVersion: number): void;
544
- /**
545
- * @zh 使所有缓存失效
546
- * @en Invalidate all cache
547
- */
548
- invalidateAll(): void;
549
- /**
550
- * @zh 使指定区域的缓存失效
551
- * @en Invalidate cache for specified region
552
- *
553
- * @param minX - @zh 最小 X 坐标 @en Minimum X coordinate
554
- * @param minY - @zh 最小 Y 坐标 @en Minimum Y coordinate
555
- * @param maxX - @zh 最大 X 坐标 @en Maximum X coordinate
556
- * @param maxY - @zh 最大 Y 坐标 @en Maximum Y coordinate
557
- */
558
- invalidateRegion(minX: number, minY: number, maxX: number, maxY: number): void;
559
- /**
560
- * @zh 获取缓存统计信息
561
- * @en Get cache statistics
562
- */
563
- getStats(): {
564
- size: number;
565
- maxSize: number;
566
- hitRate?: number;
567
- };
568
- /**
569
- * @zh 清理过期条目
570
- * @en Clean up expired entries
571
- */
572
- cleanup(): void;
573
- private generateKey;
574
- private isValid;
575
- private getApproximate;
576
- private adjustPathForApproximate;
577
- private updateAccessOrder;
578
- private removeFromAccessOrder;
579
- private evictLRU;
580
- }
581
- /**
582
- * @zh 创建路径缓存
583
- * @en Create path cache
584
- *
585
- * @param config - @zh 缓存配置 @en Cache configuration
586
- * @returns @zh 路径缓存实例 @en Path cache instance
587
- */
588
- declare function createPathCache(config?: Partial<IPathCacheConfig>): PathCache;
589
-
590
- /**
591
- * @zh 增量 A* 寻路算法实现
592
- * @en Incremental A* Pathfinding Algorithm Implementation
593
- */
594
-
595
- /**
596
- * @zh 增量寻路器配置
597
- * @en Incremental pathfinder configuration
598
- */
599
- interface IIncrementalPathfinderConfig {
600
- /**
601
- * @zh 是否启用路径缓存
602
- * @en Whether to enable path caching
603
- */
604
- enableCache?: boolean;
605
- /**
606
- * @zh 缓存配置
607
- * @en Cache configuration
608
- */
609
- cacheConfig?: Partial<IPathCacheConfig>;
610
- }
611
- /**
612
- * @zh 增量 A* 寻路器
613
- * @en Incremental A* Pathfinder
614
- *
615
- * @zh 支持时间切片的 A* 算法实现,可跨多帧执行搜索
616
- * @en A* algorithm implementation with time slicing, can execute search across multiple frames
617
- *
618
- * @example
619
- * ```typescript
620
- * const map = createGridMap(100, 100);
621
- * const pathfinder = createIncrementalAStarPathfinder(map);
622
- *
623
- * // Request path (non-blocking)
624
- * const request = pathfinder.requestPath(0, 0, 99, 99);
625
- *
626
- * // Process over multiple frames
627
- * function gameLoop() {
628
- * const progress = pathfinder.step(request.id, 100);
629
- *
630
- * if (progress.state === PathfindingState.Completed) {
631
- * const result = pathfinder.getResult(request.id);
632
- * console.log('Path found:', result?.path);
633
- * } else if (progress.state === PathfindingState.InProgress) {
634
- * requestAnimationFrame(gameLoop);
635
- * }
636
- * }
637
- * gameLoop();
638
- * ```
639
- */
640
- declare class IncrementalAStarPathfinder implements IIncrementalPathfinder {
641
- private readonly map;
642
- private readonly sessions;
643
- private nextRequestId;
644
- private readonly affectedRegions;
645
- private readonly maxRegionAge;
646
- private readonly cache;
647
- private readonly enableCache;
648
- private mapVersion;
649
- private cacheHits;
650
- private cacheMisses;
651
- /**
652
- * @zh 创建增量 A* 寻路器
653
- * @en Create incremental A* pathfinder
654
- *
655
- * @param map - @zh 寻路地图实例 @en Pathfinding map instance
656
- * @param config - @zh 配置选项 @en Configuration options
657
- */
658
- constructor(map: IPathfindingMap, config?: IIncrementalPathfinderConfig);
659
- /**
660
- * @zh 请求寻路(非阻塞)
661
- * @en Request pathfinding (non-blocking)
662
- */
663
- requestPath(startX: number, startY: number, endX: number, endY: number, options?: IIncrementalPathfindingOptions): IPathRequest;
664
- /**
665
- * @zh 执行一步搜索
666
- * @en Execute one step of search
667
- */
668
- step(requestId: number, maxIterations: number): IPathProgress;
669
- /**
670
- * @zh 暂停寻路
671
- * @en Pause pathfinding
672
- */
673
- pause(requestId: number): void;
674
- /**
675
- * @zh 恢复寻路
676
- * @en Resume pathfinding
677
- */
678
- resume(requestId: number): void;
679
- /**
680
- * @zh 取消寻路
681
- * @en Cancel pathfinding
682
- */
683
- cancel(requestId: number): void;
684
- /**
685
- * @zh 获取寻路结果
686
- * @en Get pathfinding result
687
- */
688
- getResult(requestId: number): IIncrementalPathResult | null;
689
- /**
690
- * @zh 获取当前进度
691
- * @en Get current progress
692
- */
693
- getProgress(requestId: number): IPathProgress | null;
694
- /**
695
- * @zh 清理已完成的请求
696
- * @en Clean up completed request
697
- */
698
- cleanup(requestId: number): void;
699
- /**
700
- * @zh 通知障碍物变化
701
- * @en Notify obstacle change
702
- */
703
- notifyObstacleChange(minX: number, minY: number, maxX: number, maxY: number): void;
704
- /**
705
- * @zh 清理所有请求
706
- * @en Clear all requests
707
- */
708
- clear(): void;
709
- /**
710
- * @zh 清空路径缓存
711
- * @en Clear path cache
712
- */
713
- clearCache(): void;
714
- /**
715
- * @zh 获取缓存统计信息
716
- * @en Get cache statistics
717
- */
718
- getCacheStats(): {
719
- enabled: boolean;
720
- hits: number;
721
- misses: number;
722
- hitRate: number;
723
- size: number;
724
- };
725
- /**
726
- * @zh 检查会话是否被障碍物变化影响
727
- * @en Check if session is affected by obstacle change
728
- */
729
- isAffectedByChange(requestId: number): boolean;
730
- /**
731
- * @zh 清除会话的变化标记
732
- * @en Clear session's change flag
733
- */
734
- clearChangeFlag(requestId: number): void;
735
- /**
736
- * @zh 展开邻居节点
737
- * @en Expand neighbor nodes
738
- */
739
- private expandNeighbors;
740
- /**
741
- * @zh 创建进度对象
742
- * @en Create progress object
743
- */
744
- private createProgress;
745
- /**
746
- * @zh 构建路径结果
747
- * @en Build path result
748
- */
749
- private buildResult;
750
- /**
751
- * @zh 创建空结果
752
- * @en Create empty result
753
- */
754
- private createEmptyResult;
755
- /**
756
- * @zh 检查会话是否被区域影响
757
- * @en Check if session is affected by region
758
- */
759
- private sessionAffectedByRegion;
760
- /**
761
- * @zh 清理过期的变化区域
762
- * @en Clean up expired change regions
763
- */
764
- private cleanupOldRegions;
765
- }
766
- /**
767
- * @zh 创建增量 A* 寻路器
768
- * @en Create incremental A* pathfinder
769
- *
770
- * @param map - @zh 寻路地图实例 @en Pathfinding map instance
771
- * @returns @zh 增量 A* 寻路器实例 @en Incremental A* pathfinder instance
772
- */
773
- declare function createIncrementalAStarPathfinder(map: IPathfindingMap): IncrementalAStarPathfinder;
774
-
775
459
  /**
776
460
  * @zh 路径验证器
777
461
  * @en Path Validator
@@ -1069,396 +753,6 @@ declare class JPSPathfinder implements IPathfinder {
1069
753
  */
1070
754
  declare function createJPSPathfinder(map: IPathfindingMap): JPSPathfinder;
1071
755
 
1072
- /**
1073
- * @zh HPA* (Hierarchical Pathfinding A*) 寻路算法实现
1074
- * @en HPA* (Hierarchical Pathfinding A*) Pathfinding Algorithm Implementation
1075
- *
1076
- * @zh HPA* 是一种分层寻路算法,适用于超大地图 (1000x1000+)
1077
- * @en HPA* is a hierarchical pathfinding algorithm suitable for very large maps (1000x1000+)
1078
- *
1079
- * @zh 工作原理:
1080
- * 1. 将地图划分为集群 (clusters)
1081
- * 2. 在集群边界检测入口点 (entrances)
1082
- * 3. 构建抽象图 (abstract graph) 连接入口点
1083
- * 4. 预计算集群内入口点之间的真实路径代价
1084
- * 5. 先在抽象图上寻路,再利用缓存细化为详细路径
1085
- *
1086
- * @en How it works:
1087
- * 1. Divide map into clusters
1088
- * 2. Detect entrances at cluster boundaries
1089
- * 3. Build abstract graph connecting entrances
1090
- * 4. Precompute actual path costs between entrances within clusters
1091
- * 5. First find path on abstract graph, then refine using cached paths
1092
- */
1093
-
1094
- /**
1095
- * @zh HPA* 配置
1096
- * @en HPA* Configuration
1097
- */
1098
- interface IHPAConfig {
1099
- /**
1100
- * @zh 集群大小(边长)
1101
- * @en Cluster size (side length)
1102
- */
1103
- clusterSize: number;
1104
- /**
1105
- * @zh 最大入口宽度(超过此宽度会拆分或使用端点策略)
1106
- * @en Maximum entrance width (entrances wider than this will be split or use endpoint strategy)
1107
- */
1108
- maxEntranceWidth: number;
1109
- /**
1110
- * @zh 是否启用内部路径缓存
1111
- * @en Whether to enable internal path caching
1112
- */
1113
- cacheInternalPaths: boolean;
1114
- /**
1115
- * @zh 入口策略:'middle' 在中间放节点,'end' 在宽入口两端各放节点
1116
- * @en Entrance strategy: 'middle' places node at center, 'end' places nodes at both ends for wide entrances
1117
- */
1118
- entranceStrategy?: 'middle' | 'end';
1119
- /**
1120
- * @zh 是否延迟计算 intra-edges(大幅加速预处理,首次查询时计算真实路径)
1121
- * @en Whether to lazily compute intra-edges (greatly speeds up preprocessing, computes actual paths on first query)
1122
- */
1123
- lazyIntraEdges?: boolean;
1124
- }
1125
- /**
1126
- * @zh 默认 HPA* 配置
1127
- * @en Default HPA* configuration
1128
- */
1129
- declare const DEFAULT_HPA_CONFIG: IHPAConfig;
1130
- /**
1131
- * @zh HPA* 寻路器
1132
- * @en HPA* Pathfinder
1133
- *
1134
- * @zh 适用于超大地图的分层寻路算法
1135
- * @en Hierarchical pathfinding algorithm for very large maps
1136
- *
1137
- * @example
1138
- * ```typescript
1139
- * const map = createGridMap(1000, 1000);
1140
- * const pathfinder = new HPAPathfinder(map, { clusterSize: 20 });
1141
- *
1142
- * // Preprocess (do once after map changes)
1143
- * pathfinder.preprocess();
1144
- *
1145
- * // Find path
1146
- * const result = pathfinder.findPath(0, 0, 999, 999);
1147
- * ```
1148
- */
1149
- declare class HPAPathfinder implements IPathfinder {
1150
- private readonly map;
1151
- private readonly config;
1152
- private readonly mapWidth;
1153
- private readonly mapHeight;
1154
- private clusters;
1155
- private clusterGrid;
1156
- private clustersX;
1157
- private clustersY;
1158
- private abstractNodes;
1159
- private nodesByCluster;
1160
- private nextNodeId;
1161
- private entranceCount;
1162
- private readonly localPathfinder;
1163
- private readonly pathCache;
1164
- private mapVersion;
1165
- private preprocessed;
1166
- constructor(map: IPathfindingMap, config?: Partial<IHPAConfig>);
1167
- /**
1168
- * @zh 预处理地图(构建抽象图)
1169
- * @en Preprocess map (build abstract graph)
1170
- */
1171
- preprocess(): void;
1172
- /**
1173
- * @zh 寻找路径
1174
- * @en Find path
1175
- */
1176
- findPath(startX: number, startY: number, endX: number, endY: number, options?: Partial<IPathfindingOptions>): IPathResult;
1177
- /**
1178
- * @zh 清理状态
1179
- * @en Clear state
1180
- */
1181
- clear(): void;
1182
- /**
1183
- * @zh 通知地图区域变化
1184
- * @en Notify map region change
1185
- */
1186
- notifyRegionChange(minX: number, minY: number, maxX: number, maxY: number): void;
1187
- /**
1188
- * @zh 获取预处理统计信息
1189
- * @en Get preprocessing statistics
1190
- */
1191
- getStats(): {
1192
- clusters: number;
1193
- entrances: number;
1194
- abstractNodes: number;
1195
- cacheSize: number;
1196
- };
1197
- private getMapBounds;
1198
- /**
1199
- * @zh 构建集群
1200
- * @en Build clusters
1201
- */
1202
- private buildClusters;
1203
- /**
1204
- * @zh 检测入口并创建抽象节点
1205
- * @en Detect entrances and create abstract nodes
1206
- */
1207
- private buildEntrances;
1208
- /**
1209
- * @zh 检测并创建两个相邻集群之间的入口
1210
- * @en Detect and create entrances between two adjacent clusters
1211
- */
1212
- private detectAndCreateEntrances;
1213
- /**
1214
- * @zh 检测边界上的连续可通行区间
1215
- * @en Detect continuous walkable spans on boundary
1216
- */
1217
- private detectEntranceSpans;
1218
- /**
1219
- * @zh 为入口区间创建抽象节点
1220
- * @en Create abstract nodes for entrance span
1221
- */
1222
- private createEntranceNodes;
1223
- /**
1224
- * @zh 创建抽象节点
1225
- * @en Create abstract node
1226
- */
1227
- private createAbstractNode;
1228
- /**
1229
- * @zh 构建所有集群的 intra-edges
1230
- * @en Build intra-edges for all clusters
1231
- */
1232
- private buildIntraEdges;
1233
- /**
1234
- * @zh 构建单个集群的 intra-edges
1235
- * @en Build intra-edges for single cluster
1236
- */
1237
- private buildClusterIntraEdges;
1238
- /**
1239
- * @zh 延迟构建 intra-edges(只用启发式距离)
1240
- * @en Build lazy intra-edges (using heuristic distance only)
1241
- */
1242
- private buildLazyIntraEdges;
1243
- /**
1244
- * @zh 立即构建 intra-edges(计算真实路径)
1245
- * @en Build eager intra-edges (compute actual paths)
1246
- */
1247
- private buildEagerIntraEdges;
1248
- /**
1249
- * @zh 按需计算 intra-edge 的真实路径
1250
- * @en Compute actual path for intra-edge on demand
1251
- */
1252
- private computeIntraEdgePath;
1253
- /**
1254
- * @zh 获取指定位置的集群
1255
- * @en Get cluster at position
1256
- */
1257
- private getClusterAt;
1258
- /**
1259
- * @zh 获取受影响的集群
1260
- * @en Get affected clusters
1261
- */
1262
- private getAffectedClusters;
1263
- /**
1264
- * @zh 插入临时节点
1265
- * @en Insert temporary node
1266
- */
1267
- private insertTempNode;
1268
- /**
1269
- * @zh 移除临时节点
1270
- * @en Remove temporary node
1271
- */
1272
- private removeTempNode;
1273
- /**
1274
- * @zh 在抽象图上进行 A* 搜索
1275
- * @en Perform A* search on abstract graph
1276
- */
1277
- private abstractSearch;
1278
- /**
1279
- * @zh 重建抽象路径
1280
- * @en Reconstruct abstract path
1281
- */
1282
- private reconstructPath;
1283
- /**
1284
- * @zh 细化抽象路径为具体路径
1285
- * @en Refine abstract path to concrete path
1286
- */
1287
- private refinePath;
1288
- /**
1289
- * @zh 追加路径(避免重复点)
1290
- * @en Append path (avoid duplicate points)
1291
- */
1292
- private appendPath;
1293
- /**
1294
- * @zh 局部寻路
1295
- * @en Local pathfinding
1296
- */
1297
- private findLocalPath;
1298
- /**
1299
- * @zh 启发式函数(Octile 距离)
1300
- * @en Heuristic function (Octile distance)
1301
- */
1302
- private heuristic;
1303
- }
1304
- /**
1305
- * @zh 创建 HPA* 寻路器
1306
- * @en Create HPA* pathfinder
1307
- *
1308
- * @param map - @zh 寻路地图实例 @en Pathfinding map instance
1309
- * @param config - @zh HPA* 配置 @en HPA* configuration
1310
- * @returns @zh HPA* 寻路器实例 @en HPA* pathfinder instance
1311
- */
1312
- declare function createHPAPathfinder(map: IPathfindingMap, config?: Partial<IHPAConfig>): HPAPathfinder;
1313
-
1314
- /**
1315
- * @zh 导航网格实现
1316
- * @en NavMesh Implementation
1317
- */
1318
-
1319
- /**
1320
- * @zh 导航多边形
1321
- * @en Navigation polygon
1322
- */
1323
- interface INavPolygon {
1324
- /** @zh 多边形ID @en Polygon ID */
1325
- readonly id: number;
1326
- /** @zh 顶点列表 @en Vertex list */
1327
- readonly vertices: readonly IPoint[];
1328
- /** @zh 中心点 @en Center point */
1329
- readonly center: IPoint;
1330
- /** @zh 邻居多边形ID @en Neighbor polygon IDs */
1331
- readonly neighbors: readonly number[];
1332
- /** @zh 到邻居的共享边 @en Shared edges to neighbors */
1333
- readonly portals: ReadonlyMap<number, IPortal>;
1334
- }
1335
- /**
1336
- * @zh 入口(两个多边形之间的共享边)
1337
- * @en Portal (shared edge between two polygons)
1338
- */
1339
- interface IPortal {
1340
- /** @zh 边的左端点 @en Left endpoint of edge */
1341
- readonly left: IPoint;
1342
- /** @zh 边的右端点 @en Right endpoint of edge */
1343
- readonly right: IPoint;
1344
- }
1345
- /**
1346
- * @zh 导航网格
1347
- * @en Navigation Mesh
1348
- *
1349
- * @zh 使用凸多边形网格进行高效寻路,适合复杂地形
1350
- * @en Uses convex polygon mesh for efficient pathfinding, suitable for complex terrain
1351
- *
1352
- * @example
1353
- * ```typescript
1354
- * const navmesh = new NavMesh();
1355
- *
1356
- * // Add polygons
1357
- * navmesh.addPolygon([
1358
- * { x: 0, y: 0 }, { x: 10, y: 0 },
1359
- * { x: 10, y: 10 }, { x: 0, y: 10 }
1360
- * ]);
1361
- *
1362
- * // Build connections
1363
- * navmesh.build();
1364
- *
1365
- * // Find path
1366
- * const result = navmesh.findPath(1, 1, 8, 8);
1367
- * ```
1368
- */
1369
- declare class NavMesh implements IPathfindingMap {
1370
- private polygons;
1371
- private nodes;
1372
- private nextId;
1373
- /**
1374
- * @zh 添加导航多边形
1375
- * @en Add navigation polygon
1376
- *
1377
- * @returns @zh 多边形ID @en Polygon ID
1378
- */
1379
- addPolygon(vertices: IPoint[], neighbors?: number[]): number;
1380
- /**
1381
- * @zh 设置两个多边形之间的连接
1382
- * @en Set connection between two polygons
1383
- */
1384
- setConnection(polyA: number, polyB: number, portal: IPortal): void;
1385
- /**
1386
- * @zh 自动检测并建立相邻多边形的连接
1387
- * @en Auto-detect and build connections between adjacent polygons
1388
- */
1389
- build(): void;
1390
- /**
1391
- * @zh 查找两个多边形的共享边
1392
- * @en Find shared edge between two polygons
1393
- */
1394
- private findSharedEdge;
1395
- /**
1396
- * @zh 计算多边形中心
1397
- * @en Calculate polygon center
1398
- */
1399
- private calculateCenter;
1400
- /**
1401
- * @zh 查找包含点的多边形
1402
- * @en Find polygon containing point
1403
- */
1404
- findPolygonAt(x: number, y: number): INavPolygon | null;
1405
- /**
1406
- * @zh 检查点是否在多边形内
1407
- * @en Check if point is inside polygon
1408
- */
1409
- private isPointInPolygon;
1410
- getNodeAt(x: number, y: number): IPathNode | null;
1411
- getNeighbors(node: IPathNode): IPathNode[];
1412
- heuristic(a: IPoint, b: IPoint): number;
1413
- getMovementCost(from: IPathNode, to: IPathNode): number;
1414
- isWalkable(x: number, y: number): boolean;
1415
- /**
1416
- * @zh 在导航网格上寻路
1417
- * @en Find path on navigation mesh
1418
- */
1419
- findPath(startX: number, startY: number, endX: number, endY: number, options?: IPathfindingOptions): IPathResult;
1420
- /**
1421
- * @zh 在多边形图上寻路
1422
- * @en Find path on polygon graph
1423
- */
1424
- private findPolygonPath;
1425
- /**
1426
- * @zh 使用漏斗算法优化路径
1427
- * @en Optimize path using funnel algorithm
1428
- */
1429
- private funnelPath;
1430
- /**
1431
- * @zh 计算三角形面积的两倍(用于判断点的相对位置)
1432
- * @en Calculate twice the triangle area (for point relative position)
1433
- */
1434
- private triArea2;
1435
- /**
1436
- * @zh 计算路径总长度
1437
- * @en Calculate total path length
1438
- */
1439
- private calculatePathLength;
1440
- /**
1441
- * @zh 清空导航网格
1442
- * @en Clear navigation mesh
1443
- */
1444
- clear(): void;
1445
- /**
1446
- * @zh 获取所有多边形
1447
- * @en Get all polygons
1448
- */
1449
- getPolygons(): INavPolygon[];
1450
- /**
1451
- * @zh 获取多边形数量
1452
- * @en Get polygon count
1453
- */
1454
- get polygonCount(): number;
1455
- }
1456
- /**
1457
- * @zh 创建导航网格
1458
- * @en Create navigation mesh
1459
- */
1460
- declare function createNavMesh(): NavMesh;
1461
-
1462
756
  /**
1463
757
  * @zh 路径平滑算法
1464
758
  * @en Path Smoothing Algorithms
@@ -1534,4 +828,152 @@ declare function createCatmullRomSmoother(segments?: number, tension?: number):
1534
828
  */
1535
829
  declare function createCombinedSmoother(curveSegments?: number, tension?: number): CombinedSmoother;
1536
830
 
1537
- export { AStarPathfinder, BinaryHeap, CatmullRomSmoother, CombinedSmoother, DEFAULT_GRID_OPTIONS, DEFAULT_HPA_CONFIG, DEFAULT_PATH_CACHE_CONFIG, DIRECTIONS_4, DIRECTIONS_8, GridMap, GridNode, GridPathfinder, type GridPathfinderMode, HPAPathfinder, HeuristicFunction, type IChangeRegion, type IGridMapOptions, type IGridPathfinderConfig, type IHPAConfig, type IHeapIndexable, IIncrementalPathResult, IIncrementalPathfinder, type IIncrementalPathfinderConfig, IIncrementalPathfindingOptions, type INavPolygon, type IObstacleChange, type IPathCacheConfig, IPathNode, IPathProgress, IPathRequest, IPathResult, IPathSmoother, IPathValidationResult, IPathValidator, IPathfinder, IPathfindingMap, IPathfindingOptions, IPoint, type IPortal, IncrementalAStarPathfinder, IndexedBinaryHeap, JPSPathfinder, LineOfSightSmoother, NavMesh, ObstacleChangeManager, PathCache, PathValidator, bresenhamLineOfSight, createAStarPathfinder, createCatmullRomSmoother, createCombinedSmoother, createGridMap, createGridPathfinder, createHPAPathfinder, createIncrementalAStarPathfinder, createJPSPathfinder, createLineOfSightSmoother, createNavMesh, createObstacleChangeManager, createPathCache, createPathValidator, raycastLineOfSight };
831
+ /**
832
+ * @zh 半径感知路径平滑器
833
+ * @en Radius-Aware Path Smoother
834
+ *
835
+ * @zh 通用的路径后处理器,确保路径与障碍物保持安全距离
836
+ * @en Generic path post-processor that ensures paths maintain safe distance from obstacles
837
+ */
838
+
839
+ /**
840
+ * @zh 半径感知平滑器配置
841
+ * @en Radius-aware smoother configuration
842
+ */
843
+ interface IRadiusAwareSmootherConfig {
844
+ /**
845
+ * @zh 代理半径
846
+ * @en Agent radius
847
+ */
848
+ agentRadius: number;
849
+ /**
850
+ * @zh 额外安全边距
851
+ * @en Extra safety margin
852
+ * @default 0.1
853
+ */
854
+ safetyMargin?: number;
855
+ /**
856
+ * @zh 采样方向数量(用于检测周围障碍物)
857
+ * @en Number of sample directions (for detecting nearby obstacles)
858
+ * @default 8
859
+ */
860
+ sampleDirections?: number;
861
+ /**
862
+ * @zh 最大偏移尝试次数
863
+ * @en Maximum offset attempts
864
+ * @default 8
865
+ */
866
+ maxOffsetAttempts?: number;
867
+ /**
868
+ * @zh 是否处理拐点(角落)
869
+ * @en Whether to process turning points (corners)
870
+ * @default true
871
+ */
872
+ processCorners?: boolean;
873
+ }
874
+ /**
875
+ * @zh 半径感知路径平滑器
876
+ * @en Radius-Aware Path Smoother
877
+ *
878
+ * @zh 对任意寻路算法输出的路径进行后处理,确保路径点与障碍物保持足够距离
879
+ * @en Post-processes paths from any pathfinding algorithm to ensure path points maintain sufficient distance from obstacles
880
+ *
881
+ * @example
882
+ * ```typescript
883
+ * // 创建平滑器
884
+ * const smoother = new RadiusAwarePathSmoother({ agentRadius: 0.5 });
885
+ *
886
+ * // 处理路径
887
+ * const safePath = smoother.smooth(rawPath, map);
888
+ *
889
+ * // 与其他平滑器组合使用
890
+ * const combined = new CombinedRadiusAwareSmoother(
891
+ * new LineOfSightSmoother(),
892
+ * { agentRadius: 0.5 }
893
+ * );
894
+ * ```
895
+ */
896
+ declare class RadiusAwarePathSmoother implements IPathSmoother {
897
+ private readonly config;
898
+ private readonly sampleAngles;
899
+ constructor(config: IRadiusAwareSmootherConfig);
900
+ /**
901
+ * @zh 平滑路径,确保与障碍物保持安全距离
902
+ * @en Smooth path, ensuring safe distance from obstacles
903
+ *
904
+ * @param path - @zh 原始路径 @en Original path
905
+ * @param map - @zh 地图 @en Map
906
+ * @returns @zh 处理后的安全路径 @en Processed safe path
907
+ */
908
+ smooth(path: readonly IPoint[], map: IPathfindingMap): IPoint[];
909
+ /**
910
+ * @zh 将点从障碍物偏移
911
+ * @en Offset point away from obstacles
912
+ */
913
+ private offsetPointFromObstacles;
914
+ /**
915
+ * @zh 偏移拐点(角落)
916
+ * @en Offset corner point
917
+ */
918
+ private offsetCornerPoint;
919
+ /**
920
+ * @zh 检测附近的障碍物方向
921
+ * @en Detect nearby obstacle directions
922
+ */
923
+ private detectNearbyObstacles;
924
+ }
925
+ /**
926
+ * @zh 组合半径感知平滑器
927
+ * @en Combined radius-aware smoother
928
+ *
929
+ * @zh 先使用其他平滑器(如 LOS、Catmull-Rom),再应用半径感知处理
930
+ * @en First applies other smoother (like LOS, Catmull-Rom), then applies radius-aware processing
931
+ *
932
+ * @example
933
+ * ```typescript
934
+ * const smoother = new CombinedRadiusAwareSmoother(
935
+ * new LineOfSightSmoother(),
936
+ * { agentRadius: 0.5 }
937
+ * );
938
+ * const path = smoother.smooth(rawPath, map);
939
+ * ```
940
+ */
941
+ declare class CombinedRadiusAwareSmoother implements IPathSmoother {
942
+ private readonly baseSmoother;
943
+ private readonly radiusAwareSmoother;
944
+ constructor(baseSmoother: IPathSmoother, config: IRadiusAwareSmootherConfig);
945
+ smooth(path: readonly IPoint[], map: IPathfindingMap): IPoint[];
946
+ }
947
+ /**
948
+ * @zh 创建半径感知平滑器
949
+ * @en Create radius-aware smoother
950
+ *
951
+ * @param agentRadius - @zh 代理半径 @en Agent radius
952
+ * @param options - @zh 额外配置 @en Additional options
953
+ *
954
+ * @example
955
+ * ```typescript
956
+ * const smoother = createRadiusAwareSmoother(0.5);
957
+ * const safePath = smoother.smooth(path, map);
958
+ * ```
959
+ */
960
+ declare function createRadiusAwareSmoother(agentRadius: number, options?: Omit<IRadiusAwareSmootherConfig, 'agentRadius'>): RadiusAwarePathSmoother;
961
+ /**
962
+ * @zh 创建组合半径感知平滑器
963
+ * @en Create combined radius-aware smoother
964
+ *
965
+ * @param baseSmoother - @zh 基础平滑器 @en Base smoother
966
+ * @param agentRadius - @zh 代理半径 @en Agent radius
967
+ * @param options - @zh 额外配置 @en Additional options
968
+ *
969
+ * @example
970
+ * ```typescript
971
+ * const smoother = createCombinedRadiusAwareSmoother(
972
+ * new LineOfSightSmoother(),
973
+ * 0.5
974
+ * );
975
+ * ```
976
+ */
977
+ declare function createCombinedRadiusAwareSmoother(baseSmoother: IPathSmoother, agentRadius: number, options?: Omit<IRadiusAwareSmootherConfig, 'agentRadius'>): CombinedRadiusAwareSmoother;
978
+
979
+ export { AStarPathfinder, BinaryHeap, CatmullRomSmoother, CombinedRadiusAwareSmoother, CombinedSmoother, DEFAULT_GRID_OPTIONS, DIRECTIONS_4, DIRECTIONS_8, GridMap, GridNode, GridPathfinder, type GridPathfinderMode, HeuristicFunction, type IChangeRegion, type IGridMapOptions, type IGridPathfinderConfig, type IHeapIndexable, type IObstacleChange, IPathNode, IPathResult, IPathSmoother, IPathValidationResult, IPathValidator, IPathfinder, IPathfindingMap, IPathfindingOptions, IPoint, type IRadiusAwareSmootherConfig, IndexedBinaryHeap, JPSPathfinder, LineOfSightSmoother, ObstacleChangeManager, PathValidator, RadiusAwarePathSmoother, bresenhamLineOfSight, createAStarPathfinder, createCatmullRomSmoother, createCombinedRadiusAwareSmoother, createCombinedSmoother, createGridMap, createGridPathfinder, createJPSPathfinder, createLineOfSightSmoother, createObstacleChangeManager, createPathValidator, createRadiusAwareSmoother, raycastLineOfSight };