Skip to main content

LinearAxis

Struct LinearAxis 

Source
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>

Source

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.

Examples found in repository?
examples/firmware_cost_budget.rs (line 31)
30    static LINEAR: TinyLinear =
31        BilinearSurface::from_axes(LinearAxis::new(&X), LinearAxis::new(&Y), &VALUES);
Source

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>

Source§

const KNOT_BYTES: usize

Bytes of stored knots or descriptor this strategy references. Read more
Source§

const INDEX_BYTES: usize = 0

Bytes of auxiliary index this strategy references. Read more
Source§

const MAX_SEARCH_COMPARISONS: u32

The most strategy-specific knot comparisons needed to locate an in-domain coordinate, after the inclusive endpoint checks. Read more
Source§

fn first(&self) -> u16

Returns the first knot: the inclusive lower bound of the axis domain.
Source§

fn last(&self) -> u16

Returns the last knot: the inclusive upper bound of the axis domain.
Source§

fn knot(&self, index: usize) -> u16

Returns the knot at index. Read more
Source§

fn search(&self, coordinate: u16) -> (usize, u32)

Returns the greatest index whose knot is at or below coordinate, together with the number of knot comparisons it took. Read more
Source§

impl<const N: usize> Clone for LinearAxis<N>

Source§

fn clone(&self) -> LinearAxis<N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Copy for LinearAxis<N>

Source§

impl<const N: usize> Debug for LinearAxis<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Eq for LinearAxis<N>

Source§

impl<const N: usize> Hash for LinearAxis<N>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: usize> KnotArray<N> for LinearAxis<N>

Source§

fn knots(&self) -> &'static [u16; N]

Returns the declared knots, strictly increasing and at least two long.
Source§

impl<const N: usize> PartialEq for LinearAxis<N>

Source§

fn eq(&self, other: &LinearAxis<N>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<const N: usize> StructuralPartialEq for LinearAxis<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for LinearAxis<N>
where &'static [u16; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for LinearAxis<N>
where &'static [u16; N]: RefUnwindSafe,

§

impl<const N: usize> Send for LinearAxis<N>
where &'static [u16; N]: Send,

§

impl<const N: usize> Sync for LinearAxis<N>
where &'static [u16; N]: Sync,

§

impl<const N: usize> Unpin for LinearAxis<N>
where &'static [u16; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for LinearAxis<N>
where &'static [u16; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for LinearAxis<N>
where &'static [u16; N]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.