Skip to content

Commit

Permalink
Remove dependence on num
Browse files Browse the repository at this point in the history
  • Loading branch information
paholg committed Aug 27, 2016
1 parent 1adfd5f commit fc1eb6f
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 232 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
[lib]
name = "dimensioned"

[features]
no_std = []

[dependencies]
num = "0.1.34"
typenum = "1.3.2"
22 changes: 4 additions & 18 deletions examples/vector3b.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
extern crate dimensioned as dim;
extern crate num;

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

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

pub trait Norm {
type Output;
fn norm(self) -> Self::Output;
}

impl<N> Norm for Vector3<N> where Vector3<N>: Norm2, <Vector3<N> as Norm2>::Output: Sqrt {
type Output = <<Vector3<N> as Norm2>::Output as Sqrt>::Output;
#[inline]
fn norm(self) -> Self::Output { self.norm2().sqrt() }
}


fn main() {
let xhat = Vector3::new(one, 0.0*one, 0.0*one);
let yhat = Vector3::new(0.0*one, one, 0.0*one);
Expand Down Expand Up @@ -54,9 +40,9 @@ fn main() {
}

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

#[derive(Copy, Clone)]
pub struct Vector3<N> {
Expand Down Expand Up @@ -97,8 +83,8 @@ mod vector3b {
fn norm(self) -> Self::Output;
}

impl<N> Norm for Vector3<N> where Vector3<N>: Norm2, <Vector3<N> as Norm2>::Output: Float {
type Output = <Vector3<N> as Norm2>::Output;
impl<N> Norm for Vector3<N> where Vector3<N>: Norm2, <Vector3<N> as Norm2>::Output: Sqrt {
type Output = <<Vector3<N> as Norm2>::Output as Sqrt>::Output;
#[inline]
fn norm(self) -> Self::Output { self.norm2().sqrt() }
}
Expand Down
Loading

0 comments on commit fc1eb6f

Please # to comment.