pub struct LinearAxis<const N: usize> { /* private fields */ }Expand description
An axis of N stored knots located by a bounded forward scan.
It stores exactly what BinaryAxis stores and accepts
the same arbitrary spacing; it differs only in trading the halving loop for a
straight walk. On a three- or four-knot axis that walk is at most two or
three comparisons — comparable to the search it replaces, with less code
behind it. On a long axis it is the wrong choice, and the bound below says so
plainly.
§Cost
2*N stored bytes, no index, and at most N - 1 strategy-specific knot
comparisons after the endpoint checks. Unlike the binary strategy the count
is data-dependent: a coordinate near the first knot costs less than one near
the last.
§Examples
use ph_surfaces::{BilinearSurface, BinaryAxis, LinearAxis};
static X: [u16; 3] = [0, 30, 100];
static Y: [u16; 2] = [0, 10];
static VALUES: [[i32; 3]; 2] = [[0, 30, 100], [10, 40, 110]];
// A tiny X axis scans; the Y axis keeps the default strategy.
static SURFACE: BilinearSurface<3, 2, LinearAxis<3>, BinaryAxis<2>> =
BilinearSurface::from_axes(LinearAxis::new(&X), BinaryAxis::new(&Y), &VALUES);
// Same answers as the all-binary surface over the same tables.
static DEFAULT: BilinearSurface<3, 2> = BilinearSurface::new(&X, &Y, &VALUES);
assert_eq!(SURFACE.evaluate(65, 5), DEFAULT.evaluate(65, 5));
assert_eq!(SURFACE.evaluate(65, 5), Ok(70));An axis of fewer than two knots does not compile:
use ph_surfaces::LinearAxis;
static X: [u16; 1] = [7];
static AXIS: LinearAxis<1> = LinearAxis::new(&X);Implementations§
Source§impl<const N: usize> LinearAxis<N>
impl<const N: usize> LinearAxis<N>
Sourcepub const fn new(knots: &'static [u16; N]) -> Self
pub const fn new(knots: &'static [u16; N]) -> Self
Declares a scanned axis over static knots.
§Panics
Panics unless the axis declares at least two strictly increasing knots. In a constant or static definition that panic is a compile error.
Sourcepub const fn knots(&self) -> &'static [u16; N]
pub const fn knots(&self) -> &'static [u16; N]
Returns the declared knots.
The same array as KnotArray::knots, available in a constant context.
Trait Implementations§
Source§impl<const N: usize> AxisLookup<N> for LinearAxis<N>
impl<const N: usize> AxisLookup<N> for LinearAxis<N>
Source§const KNOT_BYTES: usize
const KNOT_BYTES: usize
Source§const INDEX_BYTES: usize = 0
const INDEX_BYTES: usize = 0
Source§const MAX_SEARCH_COMPARISONS: u32
const MAX_SEARCH_COMPARISONS: u32
Source§impl<const N: usize> Clone for LinearAxis<N>
impl<const N: usize> Clone for LinearAxis<N>
Source§fn clone(&self) -> LinearAxis<N>
fn clone(&self) -> LinearAxis<N>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more