Skip to content

Rust Curve

rust
pub struct Curve<X: Scalar, C: Scalar>

An owning, dynamically sized one-axis lookup curve.

new

rust
pub fn new(x_axis: Vec<X>, cells: Vec<C>) -> Result<Self, Error>

Creates and validates a curve with one cell per X-axis point.

len

rust
pub fn len(&self) -> usize

Returns the number of X-axis points and cells.

is_empty

rust
pub fn is_empty(&self) -> bool

Returns whether the curve has no points.

Valid curves are never empty, but this complements Self::len.

x_axis

rust
pub fn x_axis(&self) -> &[X]

Returns the typed X-axis storage.

cells

rust
pub fn cells(&self) -> &[C]

Returns the typed cell storage.

validate

rust
pub fn validate(&self) -> Result<(), Error>

Revalidates all native table invariants.

lookup

rust
pub fn lookup(&self, x: f32) -> Result<f32, Error>

Performs a clamped linear lookup at x.

x

rust
pub fn x(&self, index: usize) -> Result<X, Error>

Reads one X-axis point through the native API.

cell

rust
pub fn cell(&self, index: usize) -> Result<C, Error>

Reads one curve cell through the native API.

set_x

rust
pub fn set_x(&mut self, index: usize, value: X) -> Result<(), Error>

Replaces one X-axis point while preserving strict ordering.

set_cell

rust
pub fn set_cell(&mut self, index: usize, value: C) -> Result<(), Error>

Replaces one curve cell.

replace

rust
pub fn replace(&mut self, x_axis: &[X], cells: &[C]) -> Result<(), Error>

Atomically validates and copies a complete same-sized curve snapshot.

Released under the MIT Licence.