< Summary

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

Metrics

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

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.
 06  public static float Calculate(IAgent agent, in Vector3 targetPosition) {
 7    // The speed decays exponentially with the traveled distance and with the bearing change.
 08    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));
 012    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.
 015    float minTurningRadius = agent.Velocity.sqrMagnitude / agent.MaxNormalAcceleration();
 16
 017    Vector3 directionToTarget = targetPosition - agent.Position;
 018    float distanceToTarget = directionToTarget.magnitude;
 019    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.
 022    float fractionalSpeed =
 23        Mathf.Exp(-((distanceToTarget + angleToTarget * minTurningRadius) / distanceTimeConstant +
 24                    angleToTarget / angleTimeConstant));
 025    return fractionalSpeed;
 026  }
 27}