Fixed NumCast and angles

This commit is contained in:
Dzmitry Malyshau 2015-04-04 21:32:12 -04:00
parent 8db429acae
commit b56ad542b3
5 changed files with 28 additions and 11 deletions

View file

@ -23,7 +23,7 @@ use std::ops::*;
use rand::{Rand, Rng};
use rand::distributions::range::SampleRange;
use rust_num::{One, Zero, one, zero};
use rust_num::{Float, One, Zero, one, zero};
use approx::ApproxEq;
use num::BaseFloat;
@ -52,11 +52,27 @@ pub trait ToDeg<S: BaseFloat> {
fn to_deg(&self) -> Deg<S>;
}
impl<S: BaseFloat> ToRad<S> for Rad<S> { #[inline] fn to_rad(&self) -> Rad<S> { self.clone() } }
impl<S: BaseFloat> ToRad<S> for Deg<S> { #[inline] fn to_rad(&self) -> Rad<S> { rad(self.s.to_radians()) } }
impl<S: BaseFloat> ToRad<S> for Rad<S> {
#[inline]
fn to_rad(&self) -> Rad<S> { self.clone() }
}
impl<S: BaseFloat> ToRad<S> for Deg<S> {
#[inline]
fn to_rad(&self) -> Rad<S> {
rad(self.s * cast(f64::consts::PI / 180.0).unwrap())
}
}
impl<S: BaseFloat> ToDeg<S> for Rad<S> { #[inline] fn to_deg(&self) -> Deg<S> { deg(self.s.to_degrees()) } }
impl<S: BaseFloat> ToDeg<S> for Deg<S> { #[inline] fn to_deg(&self) -> Deg<S> { self.clone() } }
impl<S: BaseFloat> ToDeg<S> for Rad<S> {
#[inline]
fn to_deg(&self) -> Deg<S> {
deg(self.s * cast(180.0 / f64::consts::PI).unwrap())
}
}
impl<S: BaseFloat> ToDeg<S> for Deg<S> {
#[inline]
fn to_deg(&self) -> Deg<S> { self.clone() }
}
/// Private utility functions for converting to/from scalars
trait ScalarConv<S> {

View file

@ -13,10 +13,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::num::cast;
use std::num::{NumCast, cast};
use rust_num::Float;
pub trait ApproxEq<T: Float>: Sized {
pub trait ApproxEq<T: NumCast + Float>: Sized {
fn approx_epsilon(_hack: Option<Self>) -> T {
cast(1.0e-5f64).unwrap()
}

View file

@ -15,7 +15,7 @@
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![feature(plugin, core, std_misc, custom_derive)]
#![feature(plugin, core, custom_derive)]
//! Computer graphics-centric math.
//!

View file

@ -17,9 +17,9 @@ use approx::ApproxEq;
use std::cmp;
use std::fmt;
use std::ops::*;
use std::num::NumCast;
use rust_num::{Float, Num, NumCast};
use rust_num::{Float, Num};
/// A trait providing a [partial ordering](http://mathworld.wolfram.com/PartialOrder.html).
pub trait PartialOrd {

View file

@ -98,11 +98,12 @@
use std::fmt;
use std::mem;
use std::num::NumCast;
use std::ops::*;
use rand::{Rand, Rng};
use rust_num::{NumCast, Zero, One, zero, one};
use rust_num::{Zero, One, zero, one};
use angle::{Rad, atan2, acos};
use approx::ApproxEq;