< Summary

Class:TimeEscapeDetector
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Escape/TimeEscapeDetector.cs
Covered lines:16
Uncovered lines:1
Coverable lines:17
Total lines:42
Line coverage:94.1% (16 of 17)
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
TimeEscapeDetector(...)0%110100%
IsEscaping(...)0%6.046089.47%

File(s)

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

#LineLine coverage
 1using UnityEngine;
 2
 3// Time escape detector.
 4//
 5// The time escape detector checks whether the agent reaches the target before the target reaches
 6// its target based on the current respective speeds.
 7public class TimeEscapeDetector : EscapeDetectorBase {
 8  // Minimum speed to prevent division by zero.
 9  private const float _minimumSpeed = 1e-6f;
 10
 3611  public TimeEscapeDetector(IAgent agent) : base(agent) {}
 12
 1213  public override bool IsEscaping(IHierarchical target) {
 1314    if (target == null) {
 115      return false;
 16    }
 17
 1118    Transformation agentToTargetTransformation = Agent.GetRelativeTransformation(target);
 19
 20    // Check if the target has a target of its own.
 1921    if (target.Target != null && !target.Target.IsTerminated) {
 822      Vector3 targetRelativePositionToTarget = target.Target.Position - target.Position;
 23      // Check whether the agent is moving head-on towards the target.
 824      if (Vector3.Dot(-agentToTargetTransformation.Position.Cartesian,
 525                      targetRelativePositionToTarget) > 0) {
 26        // Check the time-to-hit for the agent and the target.
 527        if (target.Speed < _minimumSpeed) {
 028          return false;
 29        }
 530        float targetTimeToHit = targetRelativePositionToTarget.magnitude / target.Speed;
 531        float agentTimeToHit = agentToTargetTransformation.Position.Range / Agent.Speed;
 532        return targetTimeToHit < agentTimeToHit;
 33      }
 34      // If the agent is chasing the tail of the target, check whether its speed is greater than the
 35      // target's speed.
 336      return target.Speed > Agent.Speed;
 37    }
 38
 39    // Fall back to checking the relative velocity.
 340    return agentToTargetTransformation.Velocity.Range < 0;
 1241  }
 42}