< Summary

Class:NearestNeighborInterpolator2D
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Utils/NearestNeighborInterpolator2D.cs
Covered lines:0
Uncovered lines:15
Coverable lines:15
Total lines:29
Line coverage:0% (0 of 15)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:3
Method coverage:0% (0 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NearestNeighborInterpolator2D(...)0%6200%
NearestNeighborInterpolator2D(...)0%6200%
Interpolate(...)0%6200%

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
 010  public NearestNeighborInterpolator2D(IEnumerable<Interpolator2DDataPoint> data) : base(data) {
 011    _tree = new KDTree<Interpolator2DDataPoint>(
 012        _data, (Interpolator2DDataPoint point) => point.Coordinates);
 013  }
 014  public NearestNeighborInterpolator2D(string[] csvLines) : base(csvLines) {
 015    _tree = new KDTree<Interpolator2DDataPoint>(
 016        _data, (Interpolator2DDataPoint point) => point.Coordinates);
 017  }
 18
 19  // Interpolate the value using nearest neighbor interpolation.
 020  public override Interpolator2DDataPoint Interpolate(float x, float y) {
 021    Interpolator2DDataPoint closestPoint = _tree.NearestNeighbor(new Vector2(x, y));
 022    if (closestPoint == null) {
 023      Debug.LogError("No data points available for interpolation.");
 024      return new Interpolator2DDataPoint { Coordinates = new Vector2(x, y),
 25                                           Data = new List<float>() };
 26    }
 027    return closestPoint;
 028  }
 29}