@esengine/pathfinding 12.1.2 → 13.0.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.
@@ -1,3 +1,5 @@
1
+ import { IVector2 } from '@esengine/ecs-framework-math';
2
+
1
3
  /**
2
4
  * @zh 寻路系统核心接口
3
5
  * @en Pathfinding System Core Interfaces
@@ -447,4 +449,372 @@ declare const DEFAULT_REPLANNING_CONFIG: IReplanningConfig;
447
449
  */
448
450
  declare const EMPTY_PROGRESS: IPathProgress;
449
451
 
450
- export { DEFAULT_PATHFINDING_OPTIONS as D, EMPTY_PATH_RESULT as E, type HeuristicFunction as H, type IPathfinder as I, type LineOfSightCheck as L, PathfindingState as P, type IPathfindingMap as a, type IPathfindingOptions as b, type IPathResult as c, type IPathNode as d, type IPoint as e, type IIncrementalPathfinder as f, type IIncrementalPathfindingOptions as g, type IPathRequest as h, type IPathProgress as i, type IIncrementalPathResult as j, type IPathValidator as k, type IPathValidationResult as l, type IPathSmoother as m, createPoint as n, manhattanDistance as o, euclideanDistance as p, chebyshevDistance as q, octileDistance as r, type IReplanningConfig as s, DEFAULT_REPLANNING_CONFIG as t, EMPTY_PROGRESS as u };
452
+ /**
453
+ * @zh ORCA 局部避让接口定义
454
+ * @en ORCA Local Avoidance Interface Definitions
455
+ */
456
+
457
+ /**
458
+ * @zh ORCA 约束线(半平面)
459
+ * @en ORCA constraint line (half-plane)
460
+ *
461
+ * @zh 约束线定义了一个半平面,代理的速度必须在允许的一侧
462
+ * @en A constraint line defines a half-plane, agent's velocity must be on the allowed side
463
+ */
464
+ interface IORCALine {
465
+ /**
466
+ * @zh 线上的一点
467
+ * @en A point on the line
468
+ */
469
+ point: IVector2;
470
+ /**
471
+ * @zh 线的方向向量(单位向量,允许区域在左侧)
472
+ * @en Direction vector of the line (unit vector, allowed region is on the left)
473
+ */
474
+ direction: IVector2;
475
+ }
476
+ /**
477
+ * @zh 避让代理数据
478
+ * @en Avoidance agent data
479
+ *
480
+ * @zh 包含计算 ORCA 所需的所有代理信息
481
+ * @en Contains all agent information needed for ORCA computation
482
+ */
483
+ interface IAvoidanceAgent {
484
+ /**
485
+ * @zh 代理唯一标识
486
+ * @en Unique identifier for the agent
487
+ */
488
+ id: number;
489
+ /**
490
+ * @zh 当前位置
491
+ * @en Current position
492
+ */
493
+ position: IVector2;
494
+ /**
495
+ * @zh 当前速度
496
+ * @en Current velocity
497
+ */
498
+ velocity: IVector2;
499
+ /**
500
+ * @zh 首选速度(通常指向目标方向)
501
+ * @en Preferred velocity (usually towards target)
502
+ */
503
+ preferredVelocity: IVector2;
504
+ /**
505
+ * @zh 代理半径
506
+ * @en Agent radius
507
+ */
508
+ radius: number;
509
+ /**
510
+ * @zh 最大速度
511
+ * @en Maximum speed
512
+ */
513
+ maxSpeed: number;
514
+ /**
515
+ * @zh 邻居检测距离
516
+ * @en Neighbor detection distance
517
+ */
518
+ neighborDist: number;
519
+ /**
520
+ * @zh 最大邻居数量
521
+ * @en Maximum number of neighbors to consider
522
+ */
523
+ maxNeighbors: number;
524
+ /**
525
+ * @zh 代理避让时间视野(秒)
526
+ * @en Time horizon for agent avoidance (seconds)
527
+ *
528
+ * @zh 更大的值会让代理更早开始避让
529
+ * @en Larger values make agents start avoiding earlier
530
+ */
531
+ timeHorizon: number;
532
+ /**
533
+ * @zh 障碍物避让时间视野(秒)
534
+ * @en Time horizon for obstacle avoidance (seconds)
535
+ */
536
+ timeHorizonObst: number;
537
+ }
538
+ /**
539
+ * @zh 静态障碍物(多边形)
540
+ * @en Static obstacle (polygon)
541
+ *
542
+ * @zh 重要:顶点必须按逆时针(CCW)顺序排列(在 Y 轴向上的坐标系中)
543
+ * @en Important: Vertices must be in counter-clockwise (CCW) order (in Y-axis up coordinate system)
544
+ *
545
+ * @zh 可以使用 math 库中的 Polygon.ensureCCW() 确保正确顺序
546
+ * @en Use Polygon.ensureCCW() from math library to ensure correct order
547
+ *
548
+ * @zh 在 Y 轴向下的坐标系(如 Canvas)中,视觉上的 CCW 需要传入 yAxisDown=true
549
+ * @en In Y-axis down coordinate system (like Canvas), use yAxisDown=true for visual CCW
550
+ *
551
+ * @example
552
+ * ```typescript
553
+ * import { Polygon } from '@esengine/ecs-framework-math';
554
+ *
555
+ * // 标准 Y 轴向上坐标系
556
+ * const obstacle: IObstacle = {
557
+ * vertices: Polygon.ensureCCW(myVertices)
558
+ * };
559
+ *
560
+ * // Canvas/屏幕坐标系(Y 轴向下)
561
+ * const obstacle: IObstacle = {
562
+ * vertices: Polygon.ensureCCW(myVertices, true)
563
+ * };
564
+ * ```
565
+ */
566
+ interface IObstacle {
567
+ /**
568
+ * @zh 顶点列表(逆时针顺序,Y 轴向上坐标系)
569
+ * @en Vertex list (counter-clockwise order in Y-axis up coordinate system)
570
+ */
571
+ vertices: IVector2[];
572
+ }
573
+ /**
574
+ * @zh ORCA 求解器配置
575
+ * @en ORCA solver configuration
576
+ */
577
+ interface IORCASolverConfig {
578
+ /**
579
+ * @zh 默认时间视野(代理)
580
+ * @en Default time horizon for agents
581
+ */
582
+ defaultTimeHorizon?: number;
583
+ /**
584
+ * @zh 默认时间视野(障碍物)
585
+ * @en Default time horizon for obstacles
586
+ */
587
+ defaultTimeHorizonObst?: number;
588
+ /**
589
+ * @zh 时间步长(用于碰撞响应)
590
+ * @en Time step (for collision response)
591
+ */
592
+ timeStep?: number;
593
+ /**
594
+ * @zh 数值精度阈值
595
+ * @en Numerical precision threshold
596
+ */
597
+ epsilon?: number;
598
+ }
599
+ /**
600
+ * @zh ORCA 求解结果
601
+ * @en ORCA solve result
602
+ */
603
+ interface IORCAResult {
604
+ /**
605
+ * @zh 计算得到的新速度
606
+ * @en Computed new velocity
607
+ */
608
+ velocity: IVector2;
609
+ /**
610
+ * @zh 是否找到可行解
611
+ * @en Whether a feasible solution was found
612
+ */
613
+ feasible: boolean;
614
+ /**
615
+ * @zh 生成的 ORCA 约束线数量
616
+ * @en Number of ORCA lines generated
617
+ */
618
+ numLines: number;
619
+ }
620
+ /**
621
+ * @zh ORCA 求解器接口
622
+ * @en ORCA solver interface
623
+ */
624
+ interface IORCASolver {
625
+ /**
626
+ * @zh 计算代理的新速度
627
+ * @en Compute new velocity for agent
628
+ *
629
+ * @param agent - @zh 当前代理 @en Current agent
630
+ * @param neighbors - @zh 邻近代理列表 @en List of neighbor agents
631
+ * @param obstacles - @zh 静态障碍物列表 @en List of static obstacles
632
+ * @param deltaTime - @zh 时间步长 @en Time step
633
+ * @returns @zh 新速度 @en New velocity
634
+ */
635
+ computeNewVelocity(agent: IAvoidanceAgent, neighbors: readonly IAvoidanceAgent[], obstacles: readonly IObstacle[], deltaTime: number): IVector2;
636
+ }
637
+ /**
638
+ * @zh 邻居查询结果
639
+ * @en Neighbor query result
640
+ */
641
+ interface INeighborResult {
642
+ /**
643
+ * @zh 代理数据
644
+ * @en Agent data
645
+ */
646
+ agent: IAvoidanceAgent;
647
+ /**
648
+ * @zh 距离的平方
649
+ * @en Squared distance
650
+ */
651
+ distanceSq: number;
652
+ }
653
+ /**
654
+ * @zh 空间索引接口(用于快速邻居查询)
655
+ * @en Spatial index interface (for fast neighbor queries)
656
+ */
657
+ interface ISpatialIndex {
658
+ /**
659
+ * @zh 构建空间索引
660
+ * @en Build spatial index
661
+ *
662
+ * @param agents - @zh 代理列表 @en List of agents
663
+ */
664
+ build(agents: readonly IAvoidanceAgent[]): void;
665
+ /**
666
+ * @zh 查询指定范围内的邻居
667
+ * @en Query neighbors within specified range
668
+ *
669
+ * @param position - @zh 查询位置 @en Query position
670
+ * @param radius - @zh 查询半径 @en Query radius
671
+ * @param maxResults - @zh 最大返回数量 @en Maximum number of results
672
+ * @param excludeId - @zh 排除的代理 ID @en Agent ID to exclude
673
+ * @returns @zh 邻居列表(按距离排序)@en List of neighbors (sorted by distance)
674
+ */
675
+ queryNeighbors(position: IVector2, radius: number, maxResults: number, excludeId?: number): INeighborResult[];
676
+ /**
677
+ * @zh 清空索引
678
+ * @en Clear the index
679
+ */
680
+ clear(): void;
681
+ }
682
+ /**
683
+ * @zh 默认 ORCA 求解器配置
684
+ * @en Default ORCA solver configuration
685
+ */
686
+ declare const DEFAULT_ORCA_CONFIG: Required<IORCASolverConfig>;
687
+ /**
688
+ * @zh 默认代理参数
689
+ * @en Default agent parameters
690
+ */
691
+ declare const DEFAULT_AGENT_PARAMS: {
692
+ radius: number;
693
+ maxSpeed: number;
694
+ neighborDist: number;
695
+ maxNeighbors: number;
696
+ timeHorizon: number;
697
+ timeHorizonObst: number;
698
+ };
699
+
700
+ /**
701
+ * @zh ORCA 避让算法求解器
702
+ * @en ORCA Avoidance Algorithm Solver
703
+ *
704
+ * @zh 实现最优互惠碰撞避免(ORCA)算法,用于多代理局部避让
705
+ * @en Implements Optimal Reciprocal Collision Avoidance (ORCA) algorithm for multi-agent local avoidance
706
+ */
707
+
708
+ /**
709
+ * @zh ORCA 求解器实现
710
+ * @en ORCA Solver implementation
711
+ *
712
+ * @zh 实现最优互惠碰撞避免算法,计算代理的安全速度
713
+ * @en Implements Optimal Reciprocal Collision Avoidance algorithm to compute safe velocities for agents
714
+ */
715
+ declare class ORCASolver implements IORCASolver {
716
+ private readonly config;
717
+ constructor(config?: IORCASolverConfig);
718
+ /**
719
+ * @zh 计算代理的新速度
720
+ * @en Compute new velocity for agent
721
+ *
722
+ * @param agent - @zh 当前代理 @en Current agent
723
+ * @param neighbors - @zh 邻近代理列表 @en List of neighboring agents
724
+ * @param obstacles - @zh 障碍物列表 @en List of obstacles
725
+ * @param deltaTime - @zh 时间步长 @en Time step
726
+ * @returns @zh 计算得到的新速度 @en Computed new velocity
727
+ */
728
+ computeNewVelocity(agent: IAvoidanceAgent, neighbors: readonly IAvoidanceAgent[], obstacles: readonly IObstacle[], deltaTime: number): IVector2;
729
+ /**
730
+ * @zh 创建代理间的 ORCA 约束线
731
+ * @en Create ORCA constraint lines for agent-agent avoidance
732
+ */
733
+ private createAgentORCALines;
734
+ /**
735
+ * @zh 创建障碍物的 ORCA 约束线
736
+ * @en Create ORCA constraint lines for obstacle avoidance
737
+ */
738
+ private createObstacleORCALines;
739
+ }
740
+ /**
741
+ * @zh 创建 ORCA 求解器
742
+ * @en Create ORCA solver
743
+ *
744
+ * @param config - @zh 可选配置参数 @en Optional configuration parameters
745
+ * @returns @zh ORCA 求解器实例 @en ORCA solver instance
746
+ */
747
+ declare function createORCASolver(config?: IORCASolverConfig): ORCASolver;
748
+
749
+ /**
750
+ * @zh KD-Tree 空间索引
751
+ * @en KD-Tree Spatial Index
752
+ *
753
+ * @zh 用于快速查询指定范围内的邻近代理
754
+ * @en Used for fast neighbor queries within specified range
755
+ */
756
+
757
+ /**
758
+ * @zh KD-Tree 空间索引
759
+ * @en KD-Tree spatial index
760
+ *
761
+ * @zh 每帧重建,支持高效的范围查询
762
+ * @en Rebuilt every frame, supports efficient range queries
763
+ */
764
+ declare class KDTree implements ISpatialIndex {
765
+ private agents;
766
+ private agentIndices;
767
+ private nodes;
768
+ /**
769
+ * @zh 最大叶节点大小
770
+ * @en Maximum leaf size
771
+ */
772
+ private readonly maxLeafSize;
773
+ /**
774
+ * @zh 构建 KD-Tree
775
+ * @en Build KD-Tree
776
+ */
777
+ build(agents: readonly IAvoidanceAgent[]): void;
778
+ /**
779
+ * @zh 递归构建 KD-Tree
780
+ * @en Recursively build KD-Tree
781
+ */
782
+ private buildRecursive;
783
+ /**
784
+ * @zh 按 X 坐标排序
785
+ * @en Sort by X coordinate
786
+ */
787
+ private sortByX;
788
+ /**
789
+ * @zh 按 Y 坐标排序
790
+ * @en Sort by Y coordinate
791
+ */
792
+ private sortByY;
793
+ /**
794
+ * @zh 查询邻居
795
+ * @en Query neighbors
796
+ */
797
+ queryNeighbors(position: IVector2, radius: number, maxResults: number, excludeId?: number): INeighborResult[];
798
+ /**
799
+ * @zh 递归查询
800
+ * @en Recursive query
801
+ */
802
+ private queryRecursive;
803
+ /**
804
+ * @zh 清空索引
805
+ * @en Clear the index
806
+ */
807
+ clear(): void;
808
+ /**
809
+ * @zh 获取代理数量
810
+ * @en Get agent count
811
+ */
812
+ get agentCount(): number;
813
+ }
814
+ /**
815
+ * @zh 创建 KD-Tree
816
+ * @en Create KD-Tree
817
+ */
818
+ declare function createKDTree(): KDTree;
819
+
820
+ export { type IORCASolver as A, type INeighborResult as B, type ISpatialIndex as C, DEFAULT_PATHFINDING_OPTIONS as D, EMPTY_PATH_RESULT as E, DEFAULT_ORCA_CONFIG as F, DEFAULT_AGENT_PARAMS as G, type HeuristicFunction as H, type IPathfinder as I, createORCASolver as J, KDTree as K, type LineOfSightCheck as L, createKDTree as M, ORCASolver as O, PathfindingState as P, type IPathfindingMap as a, type IPathfindingOptions as b, type IPathResult as c, type IPathNode as d, type IPoint as e, type IIncrementalPathfinder as f, type IIncrementalPathfindingOptions as g, type IPathRequest as h, type IPathProgress as i, type IIncrementalPathResult as j, type IPathValidator as k, type IPathValidationResult as l, type IPathSmoother as m, type IORCALine as n, createPoint as o, manhattanDistance as p, euclideanDistance as q, chebyshevDistance as r, octileDistance as s, type IReplanningConfig as t, DEFAULT_REPLANNING_CONFIG as u, EMPTY_PROGRESS as v, type IAvoidanceAgent as w, type IObstacle as x, type IORCASolverConfig as y, type IORCAResult as z };