Skip to main content

CompuMethod

Enum CompuMethod 

Source
pub enum CompuMethod {
    Identity,
    Linear {
        slope: f64,
        intercept: f64,
    },
    RatFunc {
        coeffs: [f64; 6],
    },
    Table {
        tab_ref: Option<String>,
        points: Vec<(f64, f64)>,
        interpolate: bool,
    },
}
Expand description

A raw ↔ physical conversion, driven by an A2L COMPU_METHOD.

Variants§

§

Identity

IDENTITY (also spelled IDENTICAL): f(x) = x.

§

Linear

LINEAR — f(x) = slope · x + intercept.

Fields

§slope: f64

Multiplicative term (COEFFS_LINEAR a).

§intercept: f64

Additive term (COEFFS_LINEAR b).

§

RatFunc

RAT_FUNC — f(x) = (a·x² + b·x + c) / (d·x² + e·x + f), the six COEFFS in the spec’s own notation. Reducible-linear forms (the common case, d = e = a = 0) are evaluated as written, which is both faster and free of any reduction’s rounding.

Fields

§coeffs: [f64; 6]

COEFFS a b c d e f.

§

Table

TABLE — a conversion through tabulated points. points are (raw, physical) pairs ascending by raw; interpolate is true for TAB_INTP (piecewise-linear, the ASAP2 default) and false for TAB_NOINTP/TAB_VERB (step lookup, nearest point wins).

Fields

§tab_ref: Option<String>

The COMPU_TAB_REF name, when the declaration carried one.

§points: Vec<(f64, f64)>

(raw, physical) points, ascending by raw.

§interpolate: bool

TAB_INTP interpolation (true) or step lookup (false).

Implementations§

Source§

impl CompuMethod

Source

pub const fn identity() -> Self

IDENTITY — the passthrough conversion.

Source

pub const fn linear(slope: f64, intercept: f64) -> Self

LINEAR — f(x) = slope · x + intercept.

Source

pub const fn rat_func(coeffs: [f64; 6]) -> Self

RAT_FUNC — f(x) = (a·x² + b·x + c) / (d·x² + e·x + f).

Source

pub fn tab_intp(points: Vec<(f64, f64)>) -> Self

TAB_INTP — an interpolated table conversion.

Source

pub fn tab_no_intp(points: Vec<(f64, f64)>) -> Self

TAB_NOINTP/TAB_VERB — a stepped table conversion.

Source

pub fn from_a2l(method: &CompuMethod) -> Self

Build the conversion carried by an a2l_parse::CompuMethod.

A TABLE declaration arrives with its COMPU_TAB_REF name and an empty point list; the points are registered on the project.

Source

pub const fn keyword(&self) -> &'static str

The A2L conversion-type keyword this method came from (LINEAR, RAT_FUNC, TABLE, IDENTITY).

Source

pub fn points(&self) -> &[(f64, f64)]

The tabulated points, empty for every non-TABLE method.

Source

pub fn tab_ref(&self) -> Option<&str>

The COMPU_TAB_REF name, when the declaration carried one.

Source

pub const fn is_identity(&self) -> bool

true for the passthrough conversion.

Source

pub fn set_points(&mut self, points: Vec<(f64, f64)>)

Replace the point list of a TABLE method (a no-op otherwise).

Source

pub fn resolved( &self, tables: &BTreeMap<String, Vec<(f64, f64)>>, ) -> Result<Self, CalError>

Fill in the points of a TABLE method from the project’s table registry when it carries none of its own.

§Errors

CalError::Unsupported when a TABLE conversion cannot be resolved: no points of its own and no registered COMPU_TAB_REF.

Source

pub fn apply(&self, raw: f64) -> f64

Evaluate the conversion: raw value in, physical value out.

Total — no input panics and every variant is a plain evaluation. A TABLE with no points evaluates as the identity; use CompuMethod::resolved first when completeness matters.

Source

pub fn invert( &self, name: &str, physical: f64, value_min: f64, value_max: f64, ) -> Result<f64, CalError>

Invert the conversion: physical value in, raw value out, bracketed by the deposit’s raw bounds value_min/value_max (in physical units, after sign extension).

  • IDENTITY and LINEAR are closed-form (a zero slope is not invertible and is reported as CalError::Unsupported).
  • RAT_FUNC is inverted by bisection over [value_min, value_max], which needs no derivative and is exact to well under one raw count across the whole 64-bit range.
  • TABLE inverts segment-wise, linearly for TAB_INTP and by nearest point for a stepped table.

name is the characteristic the inversion is for; it appears in the error so a session log says which parameter failed.

§Errors

CalError::Unsupported when the conversion is not invertible (zero slope, or a TABLE with no points), CalError::OutOfBounds when the physical value is not produced anywhere inside [value_min, value_max].

Trait Implementations§

Source§

impl Clone for CompuMethod

Source§

fn clone(&self) -> Self

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 Debug for CompuMethod

Source§

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

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

impl PartialEq for CompuMethod

Source§

fn eq(&self, other: &Self) -> bool

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CompuMethod

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.