pub struct Dimension { /* private fields */ }Expand description
A physical dimension represented as a sparse vector of rational exponents over base dimensions.
For example, Velocity = Length^1 * Time^-1 is represented as
{BaseDimId::Prelude("Length"): 1, BaseDimId::Prelude("Time"): -1}.
Only non-zero exponents are stored. An empty map represents the dimensionless dimension.
Implementations§
Source§impl Dimension
impl Dimension
Sourcepub const fn dimensionless() -> Self
pub const fn dimensionless() -> Self
The dimensionless dimension (empty exponent map).
pub fn is_dimensionless(&self) -> bool
Sourcepub fn get_exponent(&self, id: &BaseDimId) -> Rational
pub fn get_exponent(&self, id: &BaseDimId) -> Rational
Get the exponent for a specific base dimension (zero if absent).
Sourcepub fn iter(&self) -> impl Iterator<Item = (&BaseDimId, &Rational)>
pub fn iter(&self) -> impl Iterator<Item = (&BaseDimId, &Rational)>
Returns an iterator over the non-zero (BaseDimId, Rational) pairs.
Sourcepub fn pow(&self, exp: Rational) -> Result<Self, RationalError>
pub fn pow(&self, exp: Rational) -> Result<Self, RationalError>
Raise a dimension to a rational power (multiply all exponents).
Returns Err(RationalError::Overflow) if any exponent multiplication
produces a reduced value outside the i32 range.
Sourcepub fn pow_int(&self, n: i32) -> Result<Self, RationalError>
pub fn pow_int(&self, n: i32) -> Result<Self, RationalError>
Raise a dimension to an integer power.
Returns Err(RationalError::Overflow) if any exponent multiplication
overflows i32.
Sourcepub const fn display_with<'a>(
&'a self,
names: &'a BTreeMap<BaseDimId, String>,
) -> DimensionDisplay<'a>
pub const fn display_with<'a>( &'a self, names: &'a BTreeMap<BaseDimId, String>, ) -> DimensionDisplay<'a>
Format this dimension using named base dimensions for display.
The names map provides BaseDimId → name mappings.
Unknown IDs are displayed as D{id}.
Trait Implementations§
impl Eq for Dimension
impl StructuralPartialEq for Dimension
Auto Trait Implementations§
impl Freeze for Dimension
impl RefUnwindSafe for Dimension
impl Send for Dimension
impl Sync for Dimension
impl Unpin for Dimension
impl UnsafeUnpin for Dimension
impl UnwindSafe for Dimension
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.