< Summary

Class:FractionalSpeed
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Utils/FractionalSpeed.cs
Covered lines:10
Uncovered lines:0
Coverable lines:10
Total lines:27
Line coverage:100% (10 of 10)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:1
Method coverage:100% (1 of 1)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Calculate(...)0%990100%

File(s)

/github/workspace/Assets/Scripts/Utils/FractionalSpeed.cs

#LineLine coverage
 1using UnityEngine;
 2
 3public static class FractionalSpeed {
 4  // Calculate the estimated fractional speed for the given hierarchical object to reach the given
 5  // target position.
 396  public static float Calculate(IAgent agent, in Vector3 targetPosition) {
 7    // The speed decays exponentially with the traveled distance and with the bearing change.
 398    float distanceTimeConstant = 2 * (agent.StaticConfig.BodyConfig?.Mass ?? 1) /
 9                                 (Constants.CalculateAirDensityAtAltitude(agent.Position.y) *
 10                                  (agent.StaticConfig.LiftDragConfig?.DragCoefficient ?? 0) *
 11                                  (agent.StaticConfig.BodyConfig?.CrossSectionalArea ?? 0));
 3912    float angleTimeConstant =
 13        agent.StaticConfig.LiftDragConfig?.LiftDragRatio ?? float.PositiveInfinity;
 14    // During the turn, the minimum radius dictates the minimum distance needed to make the turn.
 3915    float minTurningRadius = agent.Velocity.sqrMagnitude / agent.MaxNormalAcceleration();
 16
 3917    Vector3 directionToTarget = targetPosition - agent.Position;
 3918    float distanceToTarget = directionToTarget.magnitude;
 3919    float angleToTarget = Vector3.Angle(agent.Velocity, directionToTarget) * Mathf.Deg2Rad;
 20    // The fractional speed is the product of the fractional speed after traveling the distance and
 21    // of the fractional speed after turning.
 3922    float fractionalSpeed =
 23        Mathf.Exp(-((distanceToTarget + angleToTarget * minTurningRadius) / distanceTimeConstant +
 24                    angleToTarget / angleTimeConstant));
 3925    return fractionalSpeed;
 3926  }
 27}