Git Product home page Git Product logo

Comments (4)

iliekturtles avatar iliekturtles commented on May 24, 2024

I think changing the type aliases is a good idea. See my reply to #8. Derived units are going to need review whatever way they are defined. type Newton SI<P1, P1, N2> is as easy to mess up at derived!(Meter * Kilogram / Second / Second). If the most commonly used quantities are already defined within the library and are going through a code review process then ergonomics isn't as important since each library user wouldn't be asked to redefine Force/Newtons.

from dimensioned.

paholg avatar paholg commented on May 24, 2024

I'm working on the alias switch, and it's really nice for base units. You can even do things like

let x = Meter::new(3.0);

which I think is a big win.

The problem is it breaks down for derived units, due to Rust's issue of not normalizing associated types in time. Worst case scenario, we can go with a build script, but I'm gonna look into procedural macros and see if there's anything there that can save it.

from dimensioned.

paholg avatar paholg commented on May 24, 2024

I am restructuring dimensioned from the ground up. Most importantly, what used to be Dim<SI<Meter, Second, ...>, V> is now SI<A, V> where A is a type-level array of type-numbers.

This carries with it a few advantages.

One, when one defines a unit system, they are creating the outermost type, and so no one has to worry about orphan rules for unit systems they define. I consider this a big plus.

Two, it lets us use std::convert::From for conversions! I am very excited about this.

Here is an example of a conversion from a meter, kilogram, second system to a centimeter, gram, second system:

impl<V, Meter, Kilogram, Second> From<mks::MKS<V, tarr![Meter, Kilogram, Second]>>
    for CGS<Prod<V, f64>, tarr![Meter, Kilogram, Second]> where
    Meter: Integer, Kilogram: Integer, Second: Integer,
    V: Mul<f64>,
{
    fn from(other: mks::MKS<V, tarr![Meter, Kilogram, Second]>) -> Self {
        // Note we have to be a bit careful here because these unit systems are special and use
        // double the regular unit power, so that they can be represented with half integer
        // powers. E.g. The unit for area will really be `m^4`.
        let mfac = 100.0f64.powf(Meter::to_i32() as f64 / 2.0);
        let kgfac = 1000.0f64.powf(Meter::to_i32() as f64/ 2.0);
        // Both systems use seconds for time, so no need to do anything with it!
        // let sfac = 1.0f64.powi(Meter::to_i32());
        let fac = mfac * kgfac;

        CGS::new( other.value * fac )
    }
}

With the old system, I couldn't get any conversion to a level of usability that I was satisfied with. I can't think of any method of conversion that would be better than this way, so I see it as the biggest win from this restructuring.

The only real downside that I can think of is that pretty much the entire library is now contained in the make_units macro, which makes implementing it and will make maintaining it a bit more unpleasant. I don't see this as a big deal though.

You can see the current changes in the rmdim branch. You won't be able to run it, though, without local versions of typenum and generic-array, because it depends on an addition to typenum that hasn't yet been merged to master. That should happen soon, though.

Edit: fixed this!

from dimensioned.

paholg avatar paholg commented on May 24, 2024

I believe the issues here have generally been solved.

from dimensioned.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.