|
| 1 | +""" |
| 2 | +$(TYPEDEF) |
| 3 | +
|
| 4 | +Abstract interpolation method (trait). |
| 5 | +
|
| 6 | +Concrete subtypes (`Linear`, `Constant`) are singleton trait values carried as a type |
| 7 | +parameter of [`Interpolant`](@ref), so the call method is resolved statically. |
| 8 | +""" |
| 9 | +abstract type AbstractInterpolation end |
| 10 | + |
| 11 | +""" |
| 12 | +$(TYPEDEF) |
| 13 | +
|
| 14 | +Linear interpolation method (with flat extrapolation outside the node range). |
| 15 | +""" |
| 16 | +struct Linear <: AbstractInterpolation end |
| 17 | + |
| 18 | +""" |
| 19 | +$(TYPEDEF) |
| 20 | +
|
| 21 | +Piecewise-constant (right-continuous steppost) interpolation method. |
| 22 | +""" |
| 23 | +struct Constant <: AbstractInterpolation end |
| 24 | + |
| 25 | +""" |
| 26 | +$(TYPEDEF) |
| 27 | +
|
| 28 | +Callable interpolant of method `M` over nodes `x` with values `f`. |
| 29 | +
|
| 30 | +`Interpolant` subtypes `Function`: an instance `interp` is evaluated as `interp(t)`. The |
| 31 | +method `M` (a subtype of [`AbstractInterpolation`](@ref)) is a compile-time trait parameter |
| 32 | +that selects the evaluation rule, so the call is type-stable. |
| 33 | +
|
| 34 | +# Fields |
| 35 | +- `x::TX`: nodes at which the values are defined. |
| 36 | +- `f::TF`: values to interpolate. |
| 37 | +
|
| 38 | +# Construction |
| 39 | +Build instances through the factories [`ctinterpolate`](@ref) (linear) and |
| 40 | +[`ctinterpolate_constant`](@ref) (piecewise-constant), or directly via the aliases |
| 41 | +[`LinearInterpolant`](@ref) / [`ConstantInterpolant`](@ref). |
| 42 | +""" |
| 43 | +struct Interpolant{M<:AbstractInterpolation,TX,TF} <: Function |
| 44 | + x::TX |
| 45 | + f::TF |
| 46 | +end |
| 47 | + |
| 48 | +# Outer constructor: infer TX, TF from the arguments. |
| 49 | +function Interpolant{M}(x::TX, f::TF) where {M<:AbstractInterpolation,TX,TF} |
| 50 | + return Interpolant{M,TX,TF}(x, f) |
| 51 | +end |
| 52 | + |
| 53 | +""" |
| 54 | +Alias for a linear [`Interpolant`](@ref). |
| 55 | +""" |
| 56 | +const LinearInterpolant = Interpolant{Linear} |
| 57 | + |
| 58 | +""" |
| 59 | +Alias for a piecewise-constant [`Interpolant`](@ref). |
| 60 | +""" |
| 61 | +const ConstantInterpolant = Interpolant{Constant} |
| 62 | + |
| 63 | +""" |
| 64 | +$(TYPEDSIGNATURES) |
| 65 | +
|
| 66 | +Return the interpolation method (a subtype of [`AbstractInterpolation`](@ref)) of `interp`. |
| 67 | +""" |
| 68 | +method(::Interpolant{M}) where {M} = M |
0 commit comments