< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TimeEscapeDetector(...)0%2100%
IsEscaping(...)0%42600%

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
 011  public TimeEscapeDetector(IAgent agent) : base(agent) {}
 12
 013  public override bool IsEscaping(IHierarchical target) {
 014    if (target == null) {
 015      return false;
 16    }
 17
 018    Transformation agentToTargetTransformation = Agent.GetRelativeTransformation(target);
 19
 20    // Check if the target has a target of its own.
 021    if (target.Target != null && !target.Target.IsTerminated) {
 022      Vector3 targetRelativePositionToTarget = target.Target.Position - target.Position;
 23      // Check whether the agent is moving head-on towards the target.
 024      if (Vector3.Dot(-agentToTargetTransformation.Position.Cartesian,
 025                      targetRelativePositionToTarget) > 0) {
 26        // Check the time-to-hit for the agent and the target.
 027        if (target.Speed < _minimumSpeed) {
 028          return false;
 29        }
 030        float targetTimeToHit = targetRelativePositionToTarget.magnitude / target.Speed;
 031        float agentTimeToHit = agentToTargetTransformation.Position.Range / Agent.Speed;
 032        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.
 036      return target.Speed > Agent.Speed;
 37    }
 38
 39    // Fall back to checking the relative velocity.
 040    return agentToTargetTransformation.Velocity.Range < 0;
 041  }
 42}