Comments (4)
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.
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.
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.
I believe the issues here have generally been solved.
from dimensioned.
Related Issues (20)
- Add a dimension of "information" HOT 6
- Add support for absolute values HOT 2
- Implement various functions on primitives.
- Use #[rustc_on_unimplemented] HOT 1
- travis fails to build HOT 2
- Re-add rustfmt and clippy to TravisCI build HOT 1
- Update `approx` dependency
- Validate and ideally repace uses of `mem::transmute`
- Typo in UCUM: MH20
- http://paholg.com/dimensioned/ is a 404 HOT 3
- Question: accepting generic dimension for calculation in specific units HOT 11
- Question: working with nalgebra HOT 7
- Feature request: Celsius HOT 5
- support std::iter::Sum. HOT 1
- Any good idea how to integrate with `ordered_float`? HOT 3
- Use conventional letter case HOT 1
- Support f256 via the qd github repo HOT 15
- fmt String as Joules instead of MKS HOT 2
- has_units() -> bool HOT 2
- Implement `max` and `min` functions for primitive types that have them HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dimensioned.