diff --git a/src/angle.rs b/src/angle.rs index 5c0ae2d..fb47410 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -63,7 +63,7 @@ pub impl Radians: Angle { #[inline(always)] pure fn opposite(&self) -> Radians { - (self + Angle::half_turn()).wrap() // TODO: test! + (self + Angle::half_turn()).wrap() } } @@ -121,6 +121,13 @@ pub impl Radians: Ord { #[inline(always)] pure fn gt(&self, other: &Radians) -> bool { **self > **other } } +/** + * # Example + * + * ~~~ + * assert fmt!("%s", Radians(1).to_str()) == ~"1 rad"; + * ~~~ + */ pub impl Radians: ToStr { pure fn to_str() -> ~str { fmt!("%? rad", *self) } } @@ -157,7 +164,7 @@ pub impl Degrees: Angle { #[inline(always)] pure fn opposite(&self) -> Degrees { - (self + Angle::half_turn()).wrap() // TODO: test! + (self + Angle::half_turn()).wrap() } } @@ -215,6 +222,13 @@ pub impl Degrees: Ord { #[inline(always)] pure fn gt(&self, other: &Degrees) -> bool { **self > **other } } +/** + * # Example + * + * ~~~ + * assert fmt!("%s", Degrees(180.0).to_str()) == ~"180°"; + * ~~~ + */ pub impl Degrees: ToStr { pure fn to_str() -> ~str { fmt!("%?\xB0", *self) } } \ No newline at end of file diff --git a/src/color/channel.rs b/src/color/channel.rs index 99f101b..a7b5ab9 100644 --- a/src/color/channel.rs +++ b/src/color/channel.rs @@ -1,8 +1,24 @@ use num::kinds::Number; +/** + * A color channel + */ pub trait Channel: Number { + /** + * The maximum value used by the channel + */ static pure fn max() -> self; + /** + * Convert a channel to the enclosing type + * + * # Example + * + * ~~~ + * let chan: f32 = Channel::from(0xFFFFu16); + * assert chan == 1.0f32; + * ~~~ + */ static pure fn from(val: T) -> self; pure fn to_channel_u8(&self) -> u8; diff --git a/src/color/color.rs b/src/color/color.rs index 522556f..8f804d8 100644 --- a/src/color/color.rs +++ b/src/color/color.rs @@ -26,7 +26,7 @@ pub trait Color: Dimensional, ToPtr, Eq { * * # Returns * - * The color as a `RGB` color with components ranging from + * The color as a `RGB` color with components in the range of * `0x00u8` to `0xFFu8` */ pure fn to_rgb_u8(&self) -> RGB; @@ -36,7 +36,7 @@ pub trait Color: Dimensional, ToPtr, Eq { * * # Returns * - * The color as a `RGB` color with components ranging from + * The color as a `RGB` color with components in the range of * `0x0000u16` to `0xFFFFu16` */ pure fn to_rgb_u16(&self) -> RGB; @@ -46,7 +46,7 @@ pub trait Color: Dimensional, ToPtr, Eq { * * # Returns * - * The color as a `RGB` color with components ranging from + * The color as a `RGB` color with components in the range of * `0x0000_0000_u32` to `0xFFFF_FFFF_u32` */ pure fn to_rgb_u32(&self) -> RGB; @@ -56,7 +56,7 @@ pub trait Color: Dimensional, ToPtr, Eq { * * # Returns * - * The color as a `RGB` color with components ranging from + * The color as a `RGB` color with components in the range of * `0x0000_0000_u32` to `0xFFFF_FFFF_u32` */ pure fn to_rgb_u64(&self) -> RGB; @@ -66,7 +66,7 @@ pub trait Color: Dimensional, ToPtr, Eq { * * # Returns * - * The color as a `RGB` color with components ranging from + * The color as a `RGB` color with components in the range of * `0f32` to `1f32` */ pure fn to_rgb_f32(&self) -> RGB; @@ -76,7 +76,7 @@ pub trait Color: Dimensional, ToPtr, Eq { * * # Returns * - * The color as a `RGB` color with components ranging from + * The color as a `RGB` color with components in the range of * `0f64` to `1f64` */ pure fn to_rgb_f64(&self) -> RGB; @@ -87,8 +87,9 @@ pub trait Color: Dimensional, ToPtr, Eq { * * # Returns * - * The color as a `HSV` with the `h` component as a `f32` angle and - * saturation and value components ranging from `0f32` to `1f32` + * The color as a `HSV` with the `h` component as a `Degrees` + * angle type, and saturation and value components in the range of `0f32` + * to `1f32`. */ pure fn to_hsv_f32(&self) -> HSV; @@ -97,8 +98,9 @@ pub trait Color: Dimensional, ToPtr, Eq { * * # Returns * - * The color as a `HSV` with the `h` component as a `f64` angle and - * saturation and value components ranging from `0f64` to `1f64` + * The color as a `HSV` with the `h` component as a `Degrees` + * angle type, and saturation and value components in the range of `0f64` + * to `1f64`. */ pure fn to_hsv_f64(&self) -> HSV; } @@ -120,6 +122,9 @@ pub trait MutableColor: Color { fn invert_self(&mut self); } +/** + * A generic three-component color + */ pub trait Color3: Color { // TODO: documentation (bleh, so much writing) pure fn to_rgba_u8(&self, a: u8) -> RGBA; @@ -133,6 +138,9 @@ pub trait Color3: Color { pure fn to_hsva_f64(&self, a: f64) -> HSVA; } +/** + * A generic four-component color, the last component being an alpha channel + */ pub trait Color4: Color { // TODO: documentation (arrg...) pure fn to_rgba_u8(&self) -> RGBA; diff --git a/src/num/kinds.rs b/src/num/kinds.rs index f658032..0f356c9 100644 --- a/src/num/kinds.rs +++ b/src/num/kinds.rs @@ -6,15 +6,8 @@ use num::conv::NumConv; pub trait Number: Eq, Num, NumConv, Ord { /** - * Cast a number to the type surrounding the static method - * - * # Type parameters - * - * `T` - The type of the number which will be cast. - * - * # Return value - * - * `n` cast to the type surrounding the static method + * Construct a new number by casting a number the the static method's + * enclosing type * * # Example * @@ -25,8 +18,8 @@ pub trait Number: Eq, Num, NumConv, Ord { */ static pure fn from(n: T) -> self; - static pure fn zero() -> self; /// The additive identity of the number - static pure fn one() -> self; // The multiplicative identity of the number + static pure fn zero() -> self; /// The additive identity + static pure fn one() -> self; // The multiplicative identity } pub impl u8: Number {