< Summary

Class:LaunchAngleInterpolatorBase
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Algorithms/Planning/LaunchAngleInterpolatorBase.cs
Covered lines:22
Uncovered lines:2
Coverable lines:24
Total lines:57
Line coverage:91.6% (22 of 24)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:3
Method coverage:100% (3 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LaunchAngleInterpolatorBase(...)0%110100%
Plan(...)0%550100%
InterceptPosition(...)0%5.075085.71%

File(s)

/github/workspace/Assets/Scripts/Algorithms/Planning/LaunchAngleInterpolatorBase.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5// Base implementation of a launch angle interpolator.
 6//
 7// The interpolator determines the optimal launch angle and the time-to-target given the horizontal
 8// distance and altitude of the target.
 9public abstract class LaunchAngleInterpolatorBase : LaunchAnglePlannerBase {
 10  // Launch angle data interpolator.
 11  protected IInterpolator2D _interpolator;
 12
 6313  public LaunchAngleInterpolatorBase(IAgent agent) : base(agent) {}
 14
 15  // Calculate the optimal launch angle in degrees and the time-to-target in seconds.
 2016  public override LaunchAngleOutput Plan(in LaunchAngleInput input) {
 3517    if (_interpolator == null) {
 1518      InitInterpolator();
 1419    }
 20
 1921    Interpolator2DDataPoint interpolatedDataPoint =
 22        _interpolator.Interpolate(input.Distance, input.Altitude);
 1923    if (interpolatedDataPoint == null || interpolatedDataPoint.Data == null ||
 124        interpolatedDataPoint.Data.Count < 2) {
 125      throw new InvalidOperationException("Interpolator returned invalid data.");
 26    }
 27
 1828    return new LaunchAngleOutput { LaunchAngle = interpolatedDataPoint.Data[0],
 29                                   TimeToPosition = interpolatedDataPoint.Data[1] };
 1830  }
 31
 32  // Return the absolute intercept position given the absolute target position.
 1833  public override Vector3 InterceptPosition(in Vector3 targetPosition) {
 2234    if (_interpolator == null) {
 435      InitInterpolator();
 436    }
 37
 1838    Direction direction = ConvertToRelativeDirection(targetPosition);
 1839    Interpolator2DDataPoint interpolatedDataPoint =
 40        _interpolator.Interpolate(direction.Distance, direction.Altitude);
 1841    if (interpolatedDataPoint == null || interpolatedDataPoint.Data == null ||
 042        interpolatedDataPoint.Data.Count < 2) {
 043      throw new InvalidOperationException("Interpolator returned invalid data.");
 44    }
 45
 1846    Vector3 relativePosition = targetPosition - Agent.Position;
 1847    Vector3 cylindricalRelativePosition =
 48        Coordinates3.ConvertCartesianToCylindrical(relativePosition);
 1849    return Coordinates3.ConvertCylindricalToCartesian(
 50               r: interpolatedDataPoint.Coordinates[0], azimuth: cylindricalRelativePosition.y,
 51               height: interpolatedDataPoint.Coordinates[1]) +
 52           Agent.Position;
 1853  }
 54
 55  // Initialize the interpolator.
 56  protected abstract void InitInterpolator();
 57}