Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit request: LinearEnergyDensity #501

Open
Titaniumtown opened this issue Jan 19, 2025 · 1 comment
Open

Unit request: LinearEnergyDensity #501

Titaniumtown opened this issue Jan 19, 2025 · 1 comment

Comments

@Titaniumtown
Copy link

Titaniumtown commented Jan 19, 2025

I mentioned in this issue: #357 (comment) my need for a LinearEnergyDensity type. My use case would include a wh/mi representation and such. Can anyone guide me through how to create such a unit? I'm a bit lost. Thanks!

I created this as a stop-gap:

pub struct LinearEnergyDensity<T: uom::si::length::Conversion<f32>> {
    energy: Energy,
    _base_unit: T,
}

impl<T: uom::si::length::Conversion<f32>> LinearEnergyDensity<T> {
    pub const fn new(energy: Energy, base_unit: T) -> Self {
        Self {
            energy,
            _base_unit: base_unit,
        }
    }
}

impl<T: uom::si::length::Conversion<f32>> Mul<Length> for LinearEnergyDensity<T> {
    type Output = Energy;

    fn mul(self, rhs: Length) -> Self::Output {
        let conv_length = rhs.get::<T>();
        self.energy * conv_length
    }
}
@Titaniumtown
Copy link
Author

Titaniumtown commented Jan 21, 2025

I figured this out, using type expansion:

use uom::si::{Dimension, Quantity};
use uom::typenum::{NInt, PInt, UInt, UTerm, B0, B1, Z0};
use uom::Kind;
pub type LinearEnergyDensity = Quantity<
    (dyn Dimension<
        I = Z0,
        J = Z0,
        Kind = (dyn Kind + 'static),
        L = PInt<UInt<UTerm, B1>>,
        M = PInt<UInt<UTerm, B1>>,
        N = Z0,
        T = NInt<UInt<UInt<UTerm, B1>, B0>>,
        Th = Z0,
    > + 'static),
    dyn uom::si::Units<
        f32,
        amount_of_substance = uom::si::amount_of_substance::mole,
        electric_current = uom::si::electric_current::ampere,
        length = uom::si::length::meter,
        luminous_intensity = uom::si::luminous_intensity::candela,
        mass = uom::si::mass::kilogram,
        thermodynamic_temperature = uom::si::thermodynamic_temperature::kelvin,
        time = uom::si::time::second,
    >,
    f32,
>;

There should really be a macro to create this. Like create_unit!(Energy / Length). As I have no idea what the type actually means by just reading it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant