Skip to content

Commit

Permalink
Beginning of conversion API
Browse files Browse the repository at this point in the history
  • Loading branch information
paholg committed Jul 24, 2016
1 parent f98c52f commit 1290955
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 132 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

This project follows semantic versioning.

### Unpublished
- `[added]` Unit conversion example
- `[changed]` Removed `Dimensioned` constraint for `D` in `Dim<D, V>`. This enables derived types to work properly. It is a temporary change only until the bug with Rust is fixed. See [issue #6](https://github.com/paholg/dimensioned/issues/6).

### 0.5.0 (2015-12-02)
- `[added]` This change log!
- `[changed]` **BREAKING** Use typenum instead of peano for faster and more complete type-level numbers. ([#3](https://github.com/paholg/dimensioned/pull/3))
- `[changed]` **BREAKING** Use typenum instead of peano for faster and more complete type-level numbers. ([PR #3](https://github.com/paholg/dimensioned/pull/3))
- `[added]` Re-export useful things from typenum so that crates downstream don't need to depend on it.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
name = "dimensioned"

[dependencies]
num = "0.1.28"
typenum = "1.1.0"
num = "0.1.34"
typenum = "1.3.2"
53 changes: 53 additions & 0 deletions examples/conversion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#[macro_use]
extern crate dimensioned as dim;
extern crate typenum;

use dim::{Dim};
use dim::cgs::{self, CGS, FromCGS};
use typenum::int::Integer;

use std::ops::{Mul, Div};

type Quot<A, B> = <A as Div<B>>::Output;


mod fps {
make_units_adv! {
FPS, Unitless, one, f64, 1.0;
base {
P2, Foot, ft, ft;
P2, Pound, lb, lb;
P1, Second, s, s;
}
derived {
}
}
pub trait FromFPS<Foot: Integer, Pound: Integer, Second: Integer, V> where Self: Sized {
fn from_fps(from: Dim<FPS<Foot, Pound, Second>, V>) -> Dim<Self, V>;
}
}

use fps::{FPS, FromFPS};

impl<Centimeter, Gram, Second, V> FromCGS<Centimeter, Gram, Second, V> for FPS<Centimeter, Gram, Second>
where V: Mul<f64, Output=V>, Centimeter: Integer, Gram: Integer, Second: Integer, {
fn from_cgs(from: Dim<CGS<Centimeter, Gram, Second>, V>) -> Dim<Self, V> {
Dim::new( from.0 * 0.0328084f64.sqrt().powi(Centimeter::to_i32()) * 0.00220462f64.sqrt().powi(Gram::to_i32()) )
}
}


fn main() {
let speed = 35.0 * cgs::cm / cgs::s;

let t2 = 10.0 * cgs::cm;
let t2f = FPS::from_cgs(t2);

println!("t2: {}, t2f: {}", t2, t2f);

// let speed2 = speed.convert_to();

// let speed2 = MKS::from_cgs(speedc);

// println!("I was going {}, which is {}. Boo: {}", speedc, speed2, speed2);
}
4 changes: 1 addition & 3 deletions examples/vector3b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ extern crate num;

use vector3b::{Vector3, Norm2, Cross};

use num::Float;

use dim::Sqrt;
use dim::si::{one, m, kg, s};

Expand Down Expand Up @@ -56,7 +54,7 @@ fn main() {
}

mod vector3b {
use num::traits::Float;
use num::Float;
use std::ops::{Add, Sub, Mul, Div};
use std::fmt::{self, Display};

Expand Down
19 changes: 0 additions & 19 deletions src/cgs.rs

This file was deleted.

Loading

0 comments on commit 1290955

Please # to comment.