< Summary

Class:GeometricEscapeDetector
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Escape/GeometricEscapeDetector.cs
Covered lines:10
Uncovered lines:0
Coverable lines:10
Total lines:35
Line coverage:100% (10 of 10)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:2
Method coverage:100% (2 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GeometricEscapeDetector(...)0%110100%
IsEscaping(...)0%550100%

File(s)

/github/workspace/Assets/Scripts/Escape/GeometricEscapeDetector.cs

#LineLine coverage
 1using UnityEngine;
 2
 3// Geometric escape detector.
 4//
 5// The geometric escape detector checks whether the agent is between the threat and its target.
 6public class GeometricEscapeDetector : EscapeDetectorBase {
 7  // The range buffer factor allows the interceptor to be slightly further away from the target than
 8  // the target is to its target before declaring an escape.
 9  private const float _rangeBufferFactor = 1.1f;
 10
 2711  public GeometricEscapeDetector(IAgent agent) : base(agent) {}
 12
 913  public override bool IsEscaping(IHierarchical target) {
 1014    if (target == null) {
 115      return false;
 16    }
 17
 818    Transformation agentToTargetTransformation = Agent.GetRelativeTransformation(target);
 19
 20    // Check if the target has a target of its own.
 1321    if (target.Target != null && !target.Target.IsTerminated) {
 522      Vector3 targetRelativePositionToTarget = target.Target.Position - target.Position;
 23      // The target is escaping if the distance from the agent to the target is greater than the
 24      // distance from the target to its target or if the agent is geometrically behind the target
 25      // relative the target's own target.
 526      return agentToTargetTransformation.Position.Range >
 27                 targetRelativePositionToTarget.magnitude * _rangeBufferFactor ||
 28             Vector3.Dot(-agentToTargetTransformation.Position.Cartesian,
 29                         targetRelativePositionToTarget) < 0;
 30    }
 31
 32    // Fall back to checking the relative velocity.
 333    return agentToTargetTransformation.Velocity.Range < 0;
 934  }
 35}