Finished the Vector definition.

This complete what is needed for the definition of Vector2, Vector3, and Vector4.

This required a trigonometry section, fleshing out the rest of the Number, ToNumber,
and FromNumber section, correctly defining all the available function for the Real
trait, and defining several constants.
This commit is contained in:
Jason Travis Smith
2015-10-09 13:02:54 -04:00
parent e410e69e2f
commit 7ae702fd5c
13 changed files with 3158 additions and 198 deletions

61
src/bounded.rs Normal file
View File

@ -0,0 +1,61 @@
use std::{u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, f32, f64};
/// Primitive types that have upper and lower bounds.
pub trait Bounded
{
// TODO: I would love for this to be associated consts, but
// they are not currently working inside macros.
// It causes rust's stack to explode.
// Check this on later versions of rustc.
//
// Last version checked: rustc v1.3.0
/// The minimum value for this type.
//const MIN: Self;
fn min_value() -> Self;
/// The maximum value for this type.
//const MAX: Self;
fn max_value() -> Self;
}
/// A macro for making implementation of
/// the Bounded trait easier.
macro_rules! bounded_trait_impl
{
($T: ty, $minVal: expr, $maxVal: expr) =>
{
impl Bounded for $T
{
//const MIN: $T = $minVal;
fn min_value() -> $T
{
$minVal
}
//const MAX: $T = $maxVal;
fn max_value() -> $T
{
$maxVal
}
}
}
}
// Implement the Bounded for all the primitive types.
bounded_trait_impl!(u8, u8::MIN, u8::MAX);
bounded_trait_impl!(u16, u16::MIN, u16::MAX);
bounded_trait_impl!(u32, u32::MIN, u32::MAX);
bounded_trait_impl!(u64, u64::MIN, u64::MAX);
bounded_trait_impl!(usize, usize::MIN, usize::MAX);
bounded_trait_impl!(i8, i8::MIN, i8::MAX);
bounded_trait_impl!(i16, i16::MIN, i16::MAX);
bounded_trait_impl!(i32, i32::MIN, i32::MAX);
bounded_trait_impl!(i64, i64::MIN, i64::MAX);
bounded_trait_impl!(isize, isize::MIN, isize::MAX);
bounded_trait_impl!(f32, f32::MIN, f32::MAX);
bounded_trait_impl!(f64, f64::MIN, f64::MAX);