Remove unneccesary derefs

This commit is contained in:
Brendan Zabarauskas 2013-07-14 00:55:46 +10:00
parent 6a9d690c79
commit d19e874b76
3 changed files with 83 additions and 83 deletions

View file

@ -41,17 +41,17 @@ impl<T:FloatChannel> Color<T> for HSV<T> {
/// Clamps the components of the color to the range `(lo,hi)`. /// Clamps the components of the color to the range `(lo,hi)`.
#[inline] #[inline]
pub fn clamp(&self, lo: T, hi: T) -> HSV<T> { pub fn clamp(&self, lo: T, hi: T) -> HSV<T> {
HSV::new((*self).h.clamp(&lo, &hi), // Should the hue component be clamped? HSV::new(self.h.clamp(&lo, &hi), // Should the hue component be clamped?
(*self).s.clamp(&lo, &hi), self.s.clamp(&lo, &hi),
(*self).v.clamp(&lo, &hi)) self.v.clamp(&lo, &hi))
} }
/// Inverts the color. /// Inverts the color.
#[inline] #[inline]
pub fn inverse(&self) -> HSV<T> { pub fn inverse(&self) -> HSV<T> {
HSV::new((*self).h.invert_degrees(), HSV::new(self.h.invert_degrees(),
(*self).s.invert_channel(), self.s.invert_channel(),
(*self).v.invert_channel()) self.v.invert_channel())
} }
} }
@ -60,9 +60,9 @@ impl<T:FloatChannel> FloatColor<T> for HSV<T> {
/// `h` component, and `s` and `v` are clamped to the range `(0,1)`. /// `h` component, and `s` and `v` are clamped to the range `(0,1)`.
#[inline] #[inline]
pub fn normalize(&self) -> HSV<T> { pub fn normalize(&self) -> HSV<T> {
HSV::new((*self).h.normalize_degrees(), HSV::new(self.h.normalize_degrees(),
(*self).s.normalize_channel(), self.s.normalize_channel(),
(*self).v.normalize_channel()) self.v.normalize_channel())
} }
} }
@ -87,9 +87,9 @@ impl ToHSV for u64 {
impl<T:Clone + FloatChannel> ToHSV for HSV<T> { impl<T:Clone + FloatChannel> ToHSV for HSV<T> {
#[inline] #[inline]
pub fn to_hsv<U:FloatChannel>(&self) -> HSV<U> { pub fn to_hsv<U:FloatChannel>(&self) -> HSV<U> {
HSV::new((*self).h.to_channel(), HSV::new(self.h.to_channel(),
(*self).s.to_channel(), self.s.to_channel(),
(*self).v.to_channel()) self.v.to_channel())
} }
} }
@ -98,8 +98,8 @@ impl<T:Clone + FloatChannel> ToRGB for HSV<T> {
// 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
let chr = (*self).v * (*self).s; let chr = self.v * self.s;
let h = (*self).h / num::cast(60); let h = self.h / num::cast(60);
// the 2nd largest component // the 2nd largest component
let x = chr * (one!(T) - ((h % two!(T)) - one!(T)).abs()); let x = chr * (one!(T) - ((h % two!(T)) - one!(T)).abs());
@ -115,7 +115,7 @@ impl<T:Clone + FloatChannel> ToRGB for HSV<T> {
); );
// match the value by adding the same amount to each component // match the value by adding the same amount to each component
let mn = (*self).v - chr; let mn = self.v - chr;
rgb.r = rgb.r + mn; rgb.r = rgb.r + mn;
rgb.g = rgb.g + mn; rgb.g = rgb.g + mn;
@ -160,19 +160,19 @@ impl<T:FloatChannel> Color<T> for HSVA<T> {
/// Clamps the components of the color to the range `(lo,hi)`. /// Clamps the components of the color to the range `(lo,hi)`.
#[inline] #[inline]
pub fn clamp(&self, lo: T, hi: T) -> HSVA<T> { pub fn clamp(&self, lo: T, hi: T) -> HSVA<T> {
HSVA::new((*self).h.clamp(&lo, &hi), // Should the hue component be clamped? HSVA::new(self.h.clamp(&lo, &hi), // Should the hue component be clamped?
(*self).s.clamp(&lo, &hi), self.s.clamp(&lo, &hi),
(*self).v.clamp(&lo, &hi), self.v.clamp(&lo, &hi),
(*self).a.clamp(&lo, &hi)) self.a.clamp(&lo, &hi))
} }
/// Inverts the color. /// Inverts the color.
#[inline] #[inline]
pub fn inverse(&self) -> HSVA<T> { pub fn inverse(&self) -> HSVA<T> {
HSVA::new((*self).h.invert_degrees(), HSVA::new(self.h.invert_degrees(),
(*self).s.invert_channel(), self.s.invert_channel(),
(*self).v.invert_channel(), self.v.invert_channel(),
(*self).a.invert_channel()) self.a.invert_channel())
} }
} }
@ -181,10 +181,10 @@ impl<T:FloatChannel> FloatColor<T> for HSVA<T> {
/// `h` component, and `s`, `v` and `a` are clamped to the range `(0,1)`. /// `h` component, and `s`, `v` and `a` are clamped to the range `(0,1)`.
#[inline] #[inline]
pub fn normalize(&self) -> HSVA<T> { pub fn normalize(&self) -> HSVA<T> {
HSVA::new((*self).h.normalize_degrees(), HSVA::new(self.h.normalize_degrees(),
(*self).s.normalize_channel(), self.s.normalize_channel(),
(*self).v.normalize_channel(), self.v.normalize_channel(),
(*self).a.normalize_channel()) self.a.normalize_channel())
} }
} }
@ -220,17 +220,17 @@ impl<C: ToHSV, T:Clone + FloatChannel> ToHSVA for (C, T) {
impl<T:Clone + FloatChannel> ToHSVA for HSVA<T> { impl<T:Clone + FloatChannel> ToHSVA for HSVA<T> {
#[inline] #[inline]
pub fn to_hsva<U:FloatChannel>(&self) -> HSVA<U> { pub fn to_hsva<U:FloatChannel>(&self) -> HSVA<U> {
HSVA::new((*self).h.to_channel(), HSVA::new(self.h.to_channel(),
(*self).s.to_channel(), self.s.to_channel(),
(*self).v.to_channel(), self.v.to_channel(),
(*self).a.to_channel()) self.a.to_channel())
} }
} }
impl<T:Clone + FloatChannel> ToRGBA for HSVA<T> { impl<T:Clone + FloatChannel> ToRGBA for HSVA<T> {
#[inline] #[inline]
pub fn to_rgba<U:Channel>(&self) -> RGBA<U> { pub fn to_rgba<U:Channel>(&self) -> RGBA<U> {
RGBA::from_rgb_a(self.hsv().to_rgb(), (*self).a.to_channel()) RGBA::from_rgb_a(self.hsv().to_rgb(), self.a.to_channel())
} }
} }

View file

@ -42,17 +42,17 @@ impl<T:Channel> Color<T> for RGB<T> {
/// Clamps the components of the color to the range `(lo,hi)`. /// Clamps the components of the color to the range `(lo,hi)`.
#[inline] #[inline]
pub fn clamp(&self, lo: T, hi: T) -> RGB<T> { pub fn clamp(&self, lo: T, hi: T) -> RGB<T> {
RGB::new((*self).r.clamp(&lo, &hi), RGB::new(self.r.clamp(&lo, &hi),
(*self).g.clamp(&lo, &hi), self.g.clamp(&lo, &hi),
(*self).b.clamp(&lo, &hi)) self.b.clamp(&lo, &hi))
} }
/// Inverts the color. /// Inverts the color.
#[inline] #[inline]
pub fn inverse(&self) -> RGB<T> { pub fn inverse(&self) -> RGB<T> {
RGB::new((*self).r.invert_channel(), RGB::new(self.r.invert_channel(),
(*self).g.invert_channel(), self.g.invert_channel(),
(*self).b.invert_channel()) self.b.invert_channel())
} }
} }
@ -60,9 +60,9 @@ impl<T:FloatChannel> FloatColor<T> for RGB<T> {
/// Normalizes the components of the color by clamping them to the range `(0,1)`. /// Normalizes the components of the color by clamping them to the range `(0,1)`.
#[inline] #[inline]
pub fn normalize(&self) -> RGB<T> { pub fn normalize(&self) -> RGB<T> {
RGB::new((*self).r.normalize_channel(), RGB::new(self.r.normalize_channel(),
(*self).g.normalize_channel(), self.g.normalize_channel(),
(*self).b.normalize_channel()) self.b.normalize_channel())
} }
} }
@ -87,9 +87,9 @@ impl ToRGB for u64 {
impl<T:Clone + Channel> ToRGB for RGB<T> { impl<T:Clone + Channel> ToRGB for RGB<T> {
#[inline] #[inline]
pub fn to_rgb<U:Channel>(&self) -> RGB<U> { pub fn to_rgb<U:Channel>(&self) -> RGB<U> {
RGB::new((*self).r.to_channel(), RGB::new(self.r.to_channel(),
(*self).g.to_channel(), self.g.to_channel(),
(*self).b.to_channel()) self.b.to_channel())
} }
} }
@ -157,19 +157,19 @@ impl<T:Channel> Color<T> for RGBA<T> {
/// Clamps the components of the color to the range `(lo,hi)`. /// Clamps the components of the color to the range `(lo,hi)`.
#[inline] #[inline]
pub fn clamp(&self, lo: T, hi: T) -> RGBA<T> { pub fn clamp(&self, lo: T, hi: T) -> RGBA<T> {
RGBA::new((*self).r.clamp(&lo, &hi), RGBA::new(self.r.clamp(&lo, &hi),
(*self).g.clamp(&lo, &hi), self.g.clamp(&lo, &hi),
(*self).b.clamp(&lo, &hi), self.b.clamp(&lo, &hi),
(*self).a.clamp(&lo, &hi)) self.a.clamp(&lo, &hi))
} }
/// Inverts the color. /// Inverts the color.
#[inline] #[inline]
pub fn inverse(&self) -> RGBA<T> { pub fn inverse(&self) -> RGBA<T> {
RGBA::new((*self).r.invert_channel(), RGBA::new(self.r.invert_channel(),
(*self).g.invert_channel(), self.g.invert_channel(),
(*self).b.invert_channel(), self.b.invert_channel(),
(*self).a.invert_channel()) self.a.invert_channel())
} }
} }
@ -177,10 +177,10 @@ impl<T:FloatChannel> FloatColor<T> for RGBA<T> {
/// Normalizes the components of the color by clamping them to the range `(0,1)`. /// Normalizes the components of the color by clamping them to the range `(0,1)`.
#[inline] #[inline]
pub fn normalize(&self) -> RGBA<T> { pub fn normalize(&self) -> RGBA<T> {
RGBA::new((*self).r.normalize_channel(), RGBA::new(self.r.normalize_channel(),
(*self).g.normalize_channel(), self.g.normalize_channel(),
(*self).b.normalize_channel(), self.b.normalize_channel(),
(*self).a.normalize_channel()) self.a.normalize_channel())
} }
} }
@ -216,17 +216,17 @@ impl<C: ToRGB, T:Clone + Channel> ToRGBA for (C, T) {
impl<T:Clone + Channel> ToRGBA for RGBA<T> { impl<T:Clone + Channel> ToRGBA for RGBA<T> {
#[inline] #[inline]
pub fn to_rgba<U:Channel>(&self) -> RGBA<U> { pub fn to_rgba<U:Channel>(&self) -> RGBA<U> {
RGBA::new((*self).r.to_channel(), RGBA::new(self.r.to_channel(),
(*self).g.to_channel(), self.g.to_channel(),
(*self).b.to_channel(), self.b.to_channel(),
(*self).a.to_channel()) self.a.to_channel())
} }
} }
impl<T:Clone + Channel> ToHSVA for RGBA<T> { impl<T:Clone + Channel> ToHSVA for RGBA<T> {
#[inline] #[inline]
pub fn to_hsva<U:FloatChannel>(&self) -> HSVA<U> { pub fn to_hsva<U:FloatChannel>(&self) -> HSVA<U> {
HSVA::from_hsv_a(self.rgb().to_hsv(), (*self).a.to_channel()) HSVA::from_hsv_a(self.rgb().to_hsv(), self.a.to_channel())
} }
} }

View file

@ -91,8 +91,8 @@ impl<T:Clone + Num> ToVec3<T> for Point2<T> {
/// `[x, y] -> [x, y, 1]` /// `[x, y] -> [x, y, 1]`
#[inline] #[inline]
pub fn to_vec3(&self) -> Vec3<T> { pub fn to_vec3(&self) -> Vec3<T> {
Vec3::new((*self).x.clone(), Vec3::new(self.x.clone(),
(*self).y.clone(), self.y.clone(),
one!(T)) one!(T))
} }
} }
@ -100,8 +100,8 @@ impl<T:Clone + Num> ToVec3<T> for Point2<T> {
impl<T:Clone + Float> Point2<T> { impl<T:Clone + Float> Point2<T> {
#[inline] #[inline]
pub fn rotate_t(&self, radians: &T) -> Point2<T> { pub fn rotate_t(&self, radians: &T) -> Point2<T> {
Point2::new((*self).x.cos() * (*radians), Point2::new(self.x.cos() * (*radians),
(*self).y.sin() * (*radians)) self.y.sin() * (*radians))
} }
#[inline] #[inline]
@ -147,22 +147,22 @@ impl<T:Clone + Float> Point<T, Vec2<T>, Ray2<T>> for Point2<T> {
impl<T:Num> Add<Vec2<T>, Point2<T>> for Point2<T> { impl<T:Num> Add<Vec2<T>, Point2<T>> for Point2<T> {
fn add(&self, other: &Vec2<T>) -> Point2<T> { fn add(&self, other: &Vec2<T>) -> Point2<T> {
Point2::new((*self).x + (*other).x, Point2::new(self.x + other.x,
(*self).y + (*other).y) self.y + other.y)
} }
} }
impl<T:Num> Sub<Point2<T>, Vec2<T>> for Point2<T> { impl<T:Num> Sub<Point2<T>, Vec2<T>> for Point2<T> {
fn sub(&self, other: &Point2<T>) -> Vec2<T> { fn sub(&self, other: &Point2<T>) -> Vec2<T> {
Vec2::new((*self).x - (*other).x, Vec2::new(self.x - other.x,
(*self).y - (*other).y) self.y - other.y)
} }
} }
impl<T:Num> Mul<Vec2<T>, Point2<T>> for Point2<T> { impl<T:Num> Mul<Vec2<T>, Point2<T>> for Point2<T> {
fn mul(&self, scale: &Vec2<T>) -> Point2<T> { fn mul(&self, scale: &Vec2<T>) -> Point2<T> {
Point2::new((*self).x * (*scale).x, Point2::new(self.x * scale.x,
(*self).y * (*scale).y) self.y * scale.y)
} }
} }
@ -231,9 +231,9 @@ impl<T:Clone + Num> ToVec4<T> for Point3<T> {
/// `[x, y, z] -> [x, y, z, 1]` /// `[x, y, z] -> [x, y, z, 1]`
#[inline] #[inline]
pub fn to_vec4(&self) -> Vec4<T> { pub fn to_vec4(&self) -> Vec4<T> {
Vec4::new((*self).x.clone(), Vec4::new(self.x.clone(),
(*self).y.clone(), self.y.clone(),
(*self).z.clone(), self.z.clone(),
one!(T)) one!(T))
} }
} }
@ -287,25 +287,25 @@ impl<T:Clone + Float> Point<T, Vec3<T>, Ray3<T>> for Point3<T> {
impl<T:Num> Add<Vec3<T>, Point3<T>> for Point3<T> { impl<T:Num> Add<Vec3<T>, Point3<T>> for Point3<T> {
fn add(&self, other: &Vec3<T>) -> Point3<T> { fn add(&self, other: &Vec3<T>) -> Point3<T> {
Point3::new((*self).x + (*other).x, Point3::new(self.x + other.x,
(*self).y + (*other).y, self.y + other.y,
(*self).z + (*other).z) self.z + other.z)
} }
} }
impl<T:Num> Sub<Point3<T>, Vec3<T>> for Point3<T> { impl<T:Num> Sub<Point3<T>, Vec3<T>> for Point3<T> {
fn sub(&self, other: &Point3<T>) -> Vec3<T> { fn sub(&self, other: &Point3<T>) -> Vec3<T> {
Vec3::new((*self).x - (*other).x, Vec3::new(self.x - other.x,
(*self).y - (*other).y, self.y - other.y,
(*self).z - (*other).z) self.z - other.z)
} }
} }
impl<T:Num> Mul<Vec3<T>, Point3<T>> for Point3<T> { impl<T:Num> Mul<Vec3<T>, Point3<T>> for Point3<T> {
fn mul(&self, scale: &Vec3<T>) -> Point3<T> { fn mul(&self, scale: &Vec3<T>) -> Point3<T> {
Point3::new((*self).x * (*scale).x, Point3::new(self.x * scale.x,
(*self).y * (*scale).y, self.y * scale.y,
(*self).z * (*scale).z) self.z * scale.z)
} }
} }