< Summary

Class:NearestNeighborInterpolator2D
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Utils/NearestNeighborInterpolator2D.cs
Covered lines:15
Uncovered lines:0
Coverable lines:15
Total lines:29
Line coverage:100% (15 of 15)
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
NearestNeighborInterpolator2D(...)0%220100%
NearestNeighborInterpolator2D(...)0%220100%
Interpolate(...)0%220100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4// The 2D nearest neighbor interpolator class interpolates values on a 2D grid using nearest
 5// neighbor interpolation.
 6public class NearestNeighborInterpolator2D : Interpolator2DBase {
 7  // K-D tree for nearest neighbor interpolation.
 8  private KDTree<Interpolator2DDataPoint> _tree;
 9
 2410  public NearestNeighborInterpolator2D(IEnumerable<Interpolator2DDataPoint> data) : base(data) {
 1211    _tree = new KDTree<Interpolator2DDataPoint>(
 23012        _data, (Interpolator2DDataPoint point) => point.Coordinates);
 1213  }
 2414  public NearestNeighborInterpolator2D(string[] csvLines) : base(csvLines) {
 1215    _tree = new KDTree<Interpolator2DDataPoint>(
 350416        _data, (Interpolator2DDataPoint point) => point.Coordinates);
 1217  }
 18
 19  // Interpolate the value using nearest neighbor interpolation.
 4320  public override Interpolator2DDataPoint Interpolate(float x, float y) {
 4321    Interpolator2DDataPoint closestPoint = _tree.NearestNeighbor(new Vector2(x, y));
 4522    if (closestPoint == null) {
 223      Debug.LogError("No data points available for interpolation.");
 224      return new Interpolator2DDataPoint { Coordinates = new Vector2(x, y),
 25                                           Data = new List<float>() };
 26    }
 4127    return closestPoint;
 4328  }
 29}