The OpenD Programming Language

mir.interpolate.generic

Members

Functions

atInterval (from mir.interpolate)
Tuple!(T, size_t) atInterval(T value, size_t intervalIndex) via public import mir.interpolate : atInterval;
generic
Generic!(X, F) generic(Slice!(RCI!(immutable X)) grid, Slice!(RCI!(const F)) values)

Constructs multivariate generic interpolant with nodes on rectilinear grid.

Structs

Generic
struct Generic(X, F)

Multivariate generic interpolant with nodes on rectilinear grid.

Examples

import mir.ndslice;
import mir.math.common: approxEqual;

struct PieceInterpolant
{
    int value;

    this()(int value)
    {
        this.value = value;
    }

    int opCall(uint derivative : 0, X)(int x0, int x1, X x) const
    {
        return value;
    }

    enum uint derivativeOrder = 0;
}

alias S = PieceInterpolant;
static immutable x = [0, 1, 2, 3]; // can be also an array of floating point numbers
static immutable y = [S(10), S(20), S(30)];

auto interpolant = generic(x.rcslice, y.rcslice!(const S));

assert(interpolant(-1) == 10);
assert(interpolant(0) == 10);
assert(interpolant(0.5) == 10);

assert(interpolant(1) == 20);
assert(interpolant(1.5) == 20);

assert(interpolant(2) == 30);
assert(interpolant(3) == 30);
assert(interpolant(3.4) == 30);
assert(interpolant(3) == 30);
assert(interpolant(4) == 30);

See Also

Meta

Authors

Ilia Ki