Relax type bounds

This commit is contained in:
Brendan Zabarauskas 2013-07-09 17:05:19 +10:00
parent b9369247bf
commit 128e645a20
5 changed files with 16 additions and 14 deletions

View file

@ -15,7 +15,8 @@
use std::num; use std::num;
use color::{Channel, FloatChannel}; use color::{Channel, ToChannel};
use color::{FloatChannel, ToFloatChannel};
use color::{RGB, ToRGB}; use color::{RGB, ToRGB};
#[path = "../num_macros.rs"] #[path = "../num_macros.rs"]
@ -34,7 +35,7 @@ pub trait ToHSV {
pub fn to_hsv<U:Clone + FloatChannel>(&self) -> HSV<U>; pub fn to_hsv<U:Clone + FloatChannel>(&self) -> HSV<U>;
} }
impl<T:Clone + FloatChannel> ToHSV for HSV<T> { impl<T:Clone + ToFloatChannel> ToHSV for HSV<T> {
#[inline] #[inline]
pub fn to_hsv<U:Clone + FloatChannel>(&self) -> HSV<U> { pub fn to_hsv<U:Clone + FloatChannel>(&self) -> HSV<U> {
HSV::new(FloatChannel::from((*self).h.clone()), HSV::new(FloatChannel::from((*self).h.clone()),
@ -43,7 +44,7 @@ impl<T:Clone + FloatChannel> ToHSV for HSV<T> {
} }
} }
impl<T:Clone + FloatChannel> ToRGB for HSV<T> { impl<T:Clone + Float + ToChannel> ToRGB for HSV<T> {
pub fn to_rgb<U:Clone + Channel>(&self) -> RGB<U> { pub fn to_rgb<U:Clone + Channel>(&self) -> RGB<U> {
// Algorithm taken from the Wikipedia article on HSL and HSV: // Algorithm taken from the Wikipedia article on HSL and HSV:
// http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV // http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV

View file

@ -15,7 +15,8 @@
use std::cast; use std::cast;
use color::{Channel, FloatChannel}; use color::{Channel, ToChannel};
use color::{FloatChannel, ToFloatChannel};
use color::{HSV, ToHSV, RGB, ToRGB, RGBA, ToRGBA}; use color::{HSV, ToHSV, RGB, ToRGB, RGBA, ToRGBA};
#[path = "../num_macros.rs"] #[path = "../num_macros.rs"]
@ -35,20 +36,20 @@ pub trait ToHSVA {
pub fn to_hsva<U:Clone + FloatChannel>(&self) -> HSVA<U>; pub fn to_hsva<U:Clone + FloatChannel>(&self) -> HSVA<U>;
} }
impl<C: ToHSV, T:Clone + FloatChannel> ToHSVA for (C, T) { impl<C: ToHSV, T:Clone + ToFloatChannel> ToHSVA for (C, T) {
#[inline] #[inline]
pub fn to_hsva<U:Clone + FloatChannel>(&self) -> HSVA<U> { pub fn to_hsva<U:Clone + FloatChannel>(&self) -> HSVA<U> {
match *self { match *self {
(ref c, ref a) => unsafe { (ref c, ref a) => unsafe {
cast::transmute::<(HSV<U>, U), HSVA<U>>( cast::transmute::<(HSV<U>, U), HSVA<U>>(
(c.to_hsv::<U>(), Channel::from(a.clone())) (c.to_hsv::<U>(), FloatChannel::from(a.clone()))
) )
} }
} }
} }
} }
impl<T:Clone + FloatChannel> ToRGBA for HSVA<T> { impl<T:Clone + Float + ToChannel> ToRGBA for HSVA<T> {
#[inline] #[inline]
pub fn to_rgba<U:Clone + Channel>(&self) -> RGBA<U> { pub fn to_rgba<U:Clone + Channel>(&self) -> RGBA<U> {
match unsafe { match unsafe {

View file

@ -15,7 +15,7 @@
use std::num; use std::num;
use color::{Channel, FloatChannel}; use color::{Channel, ToChannel, FloatChannel};
use color::{HSV, ToHSV}; use color::{HSV, ToHSV};
#[path = "../num_macros.rs"] #[path = "../num_macros.rs"]
@ -35,7 +35,7 @@ pub trait ToRGB {
pub fn to_rgb<U:Clone + Channel>(&self) -> RGB<U>; pub fn to_rgb<U:Clone + Channel>(&self) -> RGB<U>;
} }
impl<T:Clone + Channel> ToRGB for RGB<T> { impl<T:Clone + ToChannel> ToRGB for RGB<T> {
#[inline] #[inline]
pub fn to_rgb<U:Clone + Channel>(&self) -> RGB<U> { pub fn to_rgb<U:Clone + Channel>(&self) -> RGB<U> {
RGB::new(Channel::from((*self).r.clone()), RGB::new(Channel::from((*self).r.clone()),
@ -44,7 +44,7 @@ impl<T:Clone + Channel> ToRGB for RGB<T> {
} }
} }
impl<T:Clone + Channel> ToHSV for RGB<T> { impl<T:Clone + ToChannel> ToHSV for RGB<T> {
#[inline] #[inline]
pub fn to_hsv<U:Clone + FloatChannel>(&self) -> HSV<U> { pub fn to_hsv<U:Clone + FloatChannel>(&self) -> HSV<U> {
// Algorithm taken from the Wikipedia article on HSL and HSV: // Algorithm taken from the Wikipedia article on HSL and HSV:

View file

@ -15,7 +15,7 @@
use std::cast; use std::cast;
use color::{Channel, FloatChannel}; use color::{Channel, ToChannel, FloatChannel};
use color::{RGB, ToRGB, HSV, ToHSV, HSVA, ToHSVA}; use color::{RGB, ToRGB, HSV, ToHSV, HSVA, ToHSVA};
#[path = "../num_macros.rs"] #[path = "../num_macros.rs"]
@ -35,7 +35,7 @@ pub trait ToRGBA {
pub fn to_rgba<U:Clone + Channel>(&self) -> RGBA<U>; pub fn to_rgba<U:Clone + Channel>(&self) -> RGBA<U>;
} }
impl<C: ToRGB, T:Clone + Channel> ToRGBA for (C, T) { impl<C: ToRGB, T:Clone + ToChannel> ToRGBA for (C, T) {
#[inline] #[inline]
pub fn to_rgba<U:Clone + Channel>(&self) -> RGBA<U> { pub fn to_rgba<U:Clone + Channel>(&self) -> RGBA<U> {
match *self { match *self {
@ -48,7 +48,7 @@ impl<C: ToRGB, T:Clone + Channel> ToRGBA for (C, T) {
} }
} }
impl<T:Clone + FloatChannel> ToHSVA for RGBA<T> { impl<T:Clone + ToChannel> ToHSVA for RGBA<T> {
#[inline] #[inline]
pub fn to_hsva<U:Clone + FloatChannel>(&self) -> HSVA<U> { pub fn to_hsva<U:Clone + FloatChannel>(&self) -> HSVA<U> {
match unsafe { match unsafe {