pub enum Scale {
Linear,
Decibel(Decibel),
Ratio {
factor: f64,
},
}Expand description
What a column of numbers means: base units, decibels against a reference, or a bare decibel difference.
A ratio is what a subtraction of two decibel columns leaves — a margin against a limit, say — and it has no reference, so it can never be converted back to base units. Keeping that in the type is what stops a margin from being read as a measurement.
Variants§
Linear
Base units, as measured.
Decibel(Decibel)
Decibels against the stated reference.
Ratio
A decibel difference, carrying only the factor it was taken at.
Implementations§
Source§impl Scale
impl Scale
Sourcepub fn reference(&self) -> Option<f64>
pub fn reference(&self) -> Option<f64>
The reference, if this scale has one to convert against.
Sourcepub fn is_compatible(&self, other: &Self) -> bool
pub fn is_compatible(&self, other: &Self) -> bool
Whether values in these two scales may be combined at all.
Sourcepub fn sum(&self, other: &Self) -> Option<Self>
pub fn sum(&self, other: &Self) -> Option<Self>
The scale a sum of these two lands in, when the sum means anything.
Adding a ratio back to a measurement restores the measurement’s scale — a margin added to a limit is a level again.
Sourcepub fn difference(&self, other: &Self) -> Option<Self>
pub fn difference(&self, other: &Self) -> Option<Self>
The scale a difference of these two lands in, when it means anything.
Two levels differ by a ratio, and the references cancel: that is the
margin calculation, and why Scale::Ratio exists.