< Summary

Class:LaunchAngleCsvInterpolator
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Algorithms/Planning/LaunchAngleCsvInterpolator.cs
Covered lines:15
Uncovered lines:4
Coverable lines:19
Total lines:49
Line coverage:78.9% (15 of 19)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:3
Method coverage:66.6% (2 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LaunchAngleCsvInterpolator(...)0%2100%
LaunchAngleCsvInterpolator(...)0%110100%
InitInterpolator()0%4.414070.59%

File(s)

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

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Linq;
 4using UnityEngine;
 5
 6// The launch angle CSV interpolator loads launch angle data from a CSV file and provides
 7// interpolated values for arbitrary target positions.
 8public class LaunchAngleCsvInterpolator : LaunchAngleInterpolatorBase {
 9  // Path to the CSV file.
 10  // The first two columns of the CSV file specify the coordinates of each data point.
 11  // The third column denotes the launch angle in degrees, and the fourth column denotes the time to
 12  // reach the target position.
 13  private readonly string _relativePath;
 14
 15  // Delegate for loading the CSV file.
 16  public delegate string ConfigLoaderDelegate(string path);
 17  private readonly ConfigLoaderDelegate _configLoader;
 18
 19  public LaunchAngleCsvInterpolator(IAgent agent)
 020      : this(agent, path: Path.Combine("Planning", "hydra70_launch_angle.csv"),
 021             configLoader: ConfigLoader.LoadFromStreamingAssets) {}
 22  public LaunchAngleCsvInterpolator(IAgent agent, string path, ConfigLoaderDelegate configLoader)
 1823      : base(agent) {
 924    _relativePath = path;
 925    _configLoader = configLoader;
 926  }
 27
 28  // Initialize the interpolator.
 729  protected override void InitInterpolator() {
 730    string fileContent = _configLoader(_relativePath);
 831    if (string.IsNullOrEmpty(fileContent)) {
 132      throw new InvalidOperationException($"CSV file {_relativePath} is either null or empty.");
 33    }
 34
 635    string[] csvLines = fileContent.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
 57336    string[] dataLines = csvLines.Where(line => !string.IsNullOrWhiteSpace(line)).ToArray();
 637    if (dataLines.Length < 1) {
 038      throw new InvalidOperationException(
 39          $"No data points available for interpolation in {_relativePath}.");
 40    }
 41
 642    try {
 643      _interpolator = new NearestNeighborInterpolator2D(dataLines);
 644    } catch (Exception e) {
 045      throw new InvalidOperationException(
 46          $"Failed to initialize interpolator from {_relativePath}.", e);
 47    }
 648  }
 49}