AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

hasEdge

描述

该函数用于检查两个节点之间是否存在一条边。

语法

graph.hasEdge(source, target);

参数

  • source:起始节点的标识符。
  • target:目标节点的标识符。

返回值

返回一个布尔值,表示两个节点之间是否存在一条边。若存在,则返回true;否则返回false

示例

const graph = new Yuka.Graph();

graph.addNode('A');
graph.addNode('B');
graph.addEdge('A', 'B');

console.log(graph.hasEdge('A', 'B')); // true
console.log(graph.hasEdge('B', 'A')); // false
console.log(graph.hasEdge('A', 'C')); // false

异常

  • sourcetarget参数不是有效的节点标识符,则会抛出一个Error异常。

注意事项

  • hasEdge函数只会检查一个方向的边。若需要检查反向的边,则需要调用函数两次,分别以不同的节点顺序作为参数。
  • hasEdge函数基于节点标识符进行匹配。若两个节点的标识符相同,则函数会判断它们之间存在一条自环边。