NearestGridSurface Class

Implements nearest-neighbor interpolation on a rectilinear N-dimensional grid.

Definition

Namespace: Numerics.NET.Curves.Surfaces
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
C#
public sealed class NearestGridSurface : GridSurface
Inheritance
Object  →  Surface  →  GridSurface  →  NearestGridSurface

Remarks

This surface performs nearest-neighbor interpolation by selecting the value at the closest grid point to the query point. The interpolated function is piecewise constant and discontinuous at cell boundaries.

Characteristics:

  • Continuity: Discontinuous (piecewise constant)
  • Smoothness: C-1 (no derivatives defined at boundaries)
  • Performance: Fastest grid interpolation method, O(log N) per query via binary search
  • Gradient: Zero everywhere except at measure-zero boundaries

When to use:

  • Categorical or discrete data: When interpolating classification labels, flags, or other discrete values where smooth interpolation is inappropriate.
  • Maximum performance: When speed is critical and smoothness is not required, such as fast lookups in large tabulated functions.
  • Visualization: For pixel-perfect rendering where each grid cell should have a uniform appearance (e.g., heatmaps with distinct cells).
  • Debugging: To verify grid coverage and identify regions with sparse data.

Alternatives:

Applications:

  • Image resampling with nearest-neighbor (pixel replication)
  • Voxel rendering in medical imaging or volumetric displays
  • Lookup tables for discrete states or categories
  • Real-time applications requiring minimal latency
  • Preserving exact integer or enum values during resampling

Creating instances: Use GridNearestInterpolator(IReadOnlyList<IReadOnlyList<Double>>, IReadOnlyList<Double>, ExtrapolationMode) factory methods to create instances of this class.

Properties

Dimension Gets the number of dimensions of the input space.
(Inherited from Surface)
Values Gets a read-only span containing the values of at the data points.
(Inherited from GridSurface)

Methods

EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Evaluate(Double[]) Evaluates the surface at the specified point.
(Inherited from Surface)
Evaluate(IReadOnlyList<Double>) Evaluates the surface at the specified point.
(Inherited from Surface)
Evaluate(ReadOnlySpan<Double>) Evaluates the surface at the specified point.
(Inherited from GridSurface)
Evaluate(IReadOnlyList<Vector<Double>>, Span<Double>) Evaluates the surface at multiple points specified by a list of vectors.
(Inherited from Surface)
Evaluate(ReadOnlySpan<Double>, ExtrapolationMode) Evaluates the surface at the specified point.
(Inherited from GridSurface)
Evaluate(ReadOnlySpan<Vector<Double>>, Span<Double>) Evaluates the surface at multiple points specified by a read-only span of vectors.
(Inherited from Surface)
Evaluate(Int32, ReadOnlySpan2D<Double>, Span<Double>) Evaluates the surface at multiple points stored in column-major layout.
(Inherited from Surface)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
Gradient(Vector<Double>) Computes the gradient of the surface at the specified point.
(Inherited from Surface)
Gradient(Double, Double) Computes the gradient of a 2D surface at the specified point.
(Inherited from Surface)
Gradient(ReadOnlySpan<Double>, Span<Double>) Computes the gradient of the scalar field at the specified point.
(Inherited from GridSurface)
Gradient(Vector<Double>, Vector<Double>) Computes the gradient of the surface at the specified point.
(Inherited from Surface)
Gradient(ReadOnlySpan<Double>, ExtrapolationMode, Span<Double>)
(Inherited from GridSurface)
Gradients(Matrix<Double>) Computes the gradients of the surface at multiple points.
(Inherited from Surface)
Gradients(Matrix<Double>, Matrix<Double>) Computes the gradients of the surface at multiple points.
(Inherited from Surface)
Hessian Computes the Hessian matrix of the surface at the specified point.
(Inherited from Surface)
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also