< Summary

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

Metrics

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

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
 4213  public LaunchAngleInterpolatorBase(IAgent agent) : base(agent) {}
 14
 15  // Calculate the optimal launch angle in degrees and the time-to-target in seconds.
 016  public override LaunchAngleOutput Plan(in LaunchAngleInput input) {
 017    if (_interpolator == null) {
 018      InitInterpolator();
 019    }
 20
 021    Interpolator2DDataPoint interpolatedDataPoint =
 22        _interpolator.Interpolate(input.Distance, input.Altitude);
 023    if (interpolatedDataPoint == null || interpolatedDataPoint.Data == null ||
 024        interpolatedDataPoint.Data.Count < 2) {
 025      throw new InvalidOperationException("Interpolator returned invalid data.");
 26    }
 27
 028    return new LaunchAngleOutput { LaunchAngle = interpolatedDataPoint.Data[0],
 29                                   TimeToPosition = interpolatedDataPoint.Data[1] };
 030  }
 31
 32  // Return the absolute intercept position given the absolute target position.
 033  public override Vector3 InterceptPosition(in Vector3 targetPosition) {
 034    if (_interpolator == null) {
 035      InitInterpolator();
 036    }
 37
 038    Direction direction = ConvertToRelativeDirection(targetPosition);
 039    Interpolator2DDataPoint interpolatedDataPoint =
 40        _interpolator.Interpolate(direction.Distance, direction.Altitude);
 041    if (interpolatedDataPoint == null || interpolatedDataPoint.Data == null ||
 042        interpolatedDataPoint.Data.Count < 2) {
 043      throw new InvalidOperationException("Interpolator returned invalid data.");
 44    }
 45
 046    Vector3 relativePosition = targetPosition - Agent.Position;
 047    Vector3 cylindricalRelativePosition =
 48        Coordinates3.ConvertCartesianToCylindrical(relativePosition);
 049    return Coordinates3.ConvertCylindricalToCartesian(
 50               r: interpolatedDataPoint.Coordinates[0], azimuth: cylindricalRelativePosition.y,
 51               height: interpolatedDataPoint.Coordinates[1]) +
 52           Agent.Position;
 053  }
 54
 55  // Initialize the interpolator.
 56  protected abstract void InitInterpolator();
 57}