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
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.
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).
Implementations§
Source§impl CompuMethod
impl CompuMethod
Sourcepub const fn rat_func(coeffs: [f64; 6]) -> Self
pub const fn rat_func(coeffs: [f64; 6]) -> Self
RAT_FUNC — f(x) = (a·x² + b·x + c) / (d·x² + e·x + f).
Sourcepub fn tab_no_intp(points: Vec<(f64, f64)>) -> Self
pub fn tab_no_intp(points: Vec<(f64, f64)>) -> Self
TAB_NOINTP/TAB_VERB — a stepped table conversion.
Sourcepub fn from_a2l(method: &CompuMethod) -> Self
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.
Sourcepub const fn keyword(&self) -> &'static str
pub const fn keyword(&self) -> &'static str
The A2L conversion-type keyword this method came from
(LINEAR, RAT_FUNC, TABLE, IDENTITY).
Sourcepub fn tab_ref(&self) -> Option<&str>
pub fn tab_ref(&self) -> Option<&str>
The COMPU_TAB_REF name, when the declaration carried one.
Sourcepub const fn is_identity(&self) -> bool
pub const fn is_identity(&self) -> bool
true for the passthrough conversion.
Sourcepub fn set_points(&mut self, points: Vec<(f64, f64)>)
pub fn set_points(&mut self, points: Vec<(f64, f64)>)
Replace the point list of a TABLE method (a no-op otherwise).
Sourcepub fn resolved(
&self,
tables: &BTreeMap<String, Vec<(f64, f64)>>,
) -> Result<Self, CalError>
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.
Sourcepub fn apply(&self, raw: f64) -> f64
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.
Sourcepub fn invert(
&self,
name: &str,
physical: f64,
value_min: f64,
value_max: f64,
) -> Result<f64, CalError>
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).
IDENTITYandLINEARare closed-form (a zero slope is not invertible and is reported asCalError::Unsupported).RAT_FUNCis 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.TABLEinverts segment-wise, linearly forTAB_INTPand 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].