From 1810444a0abf24b79f15bbedd868a6e37593b745 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 14 Jul 2013 13:22:45 +1000 Subject: [PATCH] Rename Dimensioned and Swap traits --- src/bounds/frustum.rs | 4 ++-- src/color/channel.rs | 18 ++++++++++++------ src/color/hsv.rs | 8 ++++---- src/color/rgb.rs | 8 ++++---- src/color/srgb.rs | 8 ++++---- src/color/ycbcr.rs | 4 ++-- src/math/macros.rs | 8 ++++---- src/math/mat.rs | 13 +++++++------ src/math/math.rs | 4 ++-- src/math/point.rs | 10 +++++----- src/math/quat.rs | 6 +++--- src/math/vec.rs | 17 +++++++++-------- 12 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/bounds/frustum.rs b/src/bounds/frustum.rs index 2dc97aa..d6ae3a3 100644 --- a/src/bounds/frustum.rs +++ b/src/bounds/frustum.rs @@ -27,7 +27,7 @@ pub struct Frustum { far: Plane3, } -impl_dimensional!(Frustum, Plane3, 6) +impl_dimensioned!(Frustum, Plane3, 6) impl_approx!(Frustum { left, right, top, bottom, @@ -46,7 +46,7 @@ pub struct FrustumPoints { far_bottom_right: Point3, } -impl_dimensional!(FrustumPoints, Point3, 8) +impl_dimensioned!(FrustumPoints, Point3, 8) impl_approx!(FrustumPoints { near_top_left, near_top_right, diff --git a/src/color/channel.rs b/src/color/channel.rs index 8db4b17..1eba93a 100644 --- a/src/color/channel.rs +++ b/src/color/channel.rs @@ -77,11 +77,13 @@ pub trait FloatChannel: Float + Channel { } impl FloatChannel for f32 { - #[inline] pub fn normalize_channel(&self) -> f32 { + #[inline] + pub fn normalize_channel(&self) -> f32 { self.clamp(&0.0, &1.0) } - #[inline] pub fn normalize_degrees(&self) -> f32 { + #[inline] + pub fn normalize_degrees(&self) -> f32 { if (*self) < 0.0 { (*self + 360.0) % 360.0 } else { @@ -89,17 +91,20 @@ impl FloatChannel for f32 { } } - #[inline] pub fn invert_degrees(&self) -> f32 { + #[inline] + pub fn invert_degrees(&self) -> f32 { (*self + 180.0).normalize_degrees() } } impl FloatChannel for f64 { - #[inline] pub fn normalize_channel(&self) -> f64 { + #[inline] + pub fn normalize_channel(&self) -> f64 { self.clamp(&0.0, &1.0) } - #[inline] pub fn normalize_degrees(&self) -> f64 { + #[inline] + pub fn normalize_degrees(&self) -> f64 { if (*self) < 0.0 { (*self + 360.0) % 360.0 } else { @@ -107,7 +112,8 @@ impl FloatChannel for f64 { } } - #[inline] pub fn invert_degrees(&self) -> f64 { + #[inline] + pub fn invert_degrees(&self) -> f64 { (*self + 180.0).normalize_degrees() } } diff --git a/src/color/hsv.rs b/src/color/hsv.rs index 66c3a83..035c31d 100644 --- a/src/color/hsv.rs +++ b/src/color/hsv.rs @@ -25,10 +25,10 @@ use color::{RGB, ToRGB, RGBA, ToRGBA}; #[deriving(Clone, Eq)] pub struct HSV { h: T, s: T, v: T } -impl_dimensional!(HSV, T, 3) +impl_dimensioned!(HSV, T, 3) impl_to_vec!(HSV, 3) impl_as_vec!(HSV, 3) -impl_swap!(HSV) +impl_swap_components!(HSV) impl_approx!(HSV { h, s, v }) impl HSV { @@ -128,10 +128,10 @@ impl ToRGB for HSV { #[deriving(Clone, Eq)] pub struct HSVA { h: T, s: T, v: T, a: T } -impl_dimensional!(HSVA, T, 4) +impl_dimensioned!(HSVA, T, 4) impl_to_vec!(HSVA, 4) impl_as_vec!(HSVA, 4) -impl_swap!(HSVA) +impl_swap_components!(HSVA) impl_approx!(HSVA { h, s, v, a }) impl HSVA { diff --git a/src/color/rgb.rs b/src/color/rgb.rs index 7a96458..689173f 100644 --- a/src/color/rgb.rs +++ b/src/color/rgb.rs @@ -25,10 +25,10 @@ use color::{HSV, ToHSV, HSVA, ToHSVA}; #[deriving(Clone, Eq)] pub struct RGB { r: T, g: T, b: T } -impl_dimensional!(RGB, T, 3) +impl_dimensioned!(RGB, T, 3) impl_to_vec!(RGB, 3) impl_as_vec!(RGB, 3) -impl_swap!(RGB) +impl_swap_components!(RGB) impl_approx!(RGB { r, g, b }) impl RGB { @@ -125,10 +125,10 @@ impl ToHSV for RGB { #[deriving(Clone, Eq)] pub struct RGBA { r: T, g: T, b: T, a: T } -impl_dimensional!(RGBA, T, 4) +impl_dimensioned!(RGBA, T, 4) impl_to_vec!(RGBA, 4) impl_as_vec!(RGBA, 4) -impl_swap!(RGBA) +impl_swap_components!(RGBA) impl_approx!(RGBA { r, g, b, a }) impl RGBA { diff --git a/src/color/srgb.rs b/src/color/srgb.rs index bd2d895..6272b94 100644 --- a/src/color/srgb.rs +++ b/src/color/srgb.rs @@ -25,19 +25,19 @@ impl SRGB { } } -impl_dimensional!(SRGB, T, 3) +impl_dimensioned!(SRGB, T, 3) impl_to_vec!(SRGB, 3) impl_as_vec!(SRGB, 3) -impl_swap!(SRGB) +impl_swap_components!(SRGB) impl_approx!(SRGB { r, g, b }) #[deriving(Clone, Eq)] pub struct SRGBA { r: T, g: T, b: T, a: T } -impl_dimensional!(SRGBA, T, 4) +impl_dimensioned!(SRGBA, T, 4) impl_to_vec!(SRGBA, 4) impl_as_vec!(SRGBA, 4) -impl_swap!(SRGBA) +impl_swap_components!(SRGBA) impl_approx!(SRGBA { r, g, b, a }) impl SRGBA { diff --git a/src/color/ycbcr.rs b/src/color/ycbcr.rs index c782ac5..c40636c 100644 --- a/src/color/ycbcr.rs +++ b/src/color/ycbcr.rs @@ -20,10 +20,10 @@ use math::*; #[deriving(Clone, Eq)] pub struct YCbCr { y: T, cb: T, cr: T } -impl_dimensional!(YCbCr, T, 3) +impl_dimensioned!(YCbCr, T, 3) impl_to_vec!(YCbCr, 3) impl_as_vec!(YCbCr, 3) -impl_swap!(YCbCr) +impl_swap_components!(YCbCr) impl_approx!(YCbCr { y, cb, cr }) impl YCbCr { diff --git a/src/math/macros.rs b/src/math/macros.rs index 1da1d9d..76dfe33 100644 --- a/src/math/macros.rs +++ b/src/math/macros.rs @@ -15,9 +15,9 @@ #[macro_escape]; -macro_rules! impl_dimensional( +macro_rules! impl_dimensioned( ($Self:ident, $T:ty, $n:expr) => ( - impl Dimensional<$T,[$T,..$n]> for $Self { + impl Dimensioned<$T,[$T,..$n]> for $Self { #[inline] pub fn index<'a>(&'a self, i: uint) -> &'a $T { &'a self.as_slice()[i] @@ -84,9 +84,9 @@ macro_rules! impl_as_vec_helper( ) ) -macro_rules! impl_swap( +macro_rules! impl_swap_components( ($Self:ident) => ( - impl Swap for $Self { + impl SwapComponents for $Self { #[inline] pub fn swap(&mut self, a: uint, b: uint) { let tmp = self.index(a).clone(); diff --git a/src/math/mat.rs b/src/math/mat.rs index 146f609..7b935dd 100644 --- a/src/math/mat.rs +++ b/src/math/mat.rs @@ -15,11 +15,12 @@ //! Matrix types -use math::{Dimensional, Swap}; +use math::{Dimensioned, SwapComponents}; use math::{Quat, ToQuat}; use math::{Vec2, Vec3, Vec4}; -pub trait Mat: Dimensional + Swap { +pub trait Mat: Dimensioned + + SwapComponents { pub fn col<'a>(&'a self, i: uint) -> &'a Vec; pub fn col_mut<'a>(&'a mut self, i: uint) -> &'a mut Vec; pub fn elem<'a>(&'a self, col: uint, row: uint) -> &'a T; @@ -73,7 +74,7 @@ pub type Mat2f = Mat2; pub type Mat2f32 = Mat2; pub type Mat2f64 = Mat2; -impl_dimensional!(Mat2, Vec2, 2) +impl_dimensioned!(Mat2, Vec2, 2) impl_approx!(Mat3 { x, y, z }) pub trait ToMat2 { @@ -534,7 +535,7 @@ pub type Mat3f = Mat3; pub type Mat3f32 = Mat3; pub type Mat3f64 = Mat3; -impl_dimensional!(Mat3, Vec3, 3) +impl_dimensioned!(Mat3, Vec3, 3) impl_approx!(Mat2 { x, y }) pub trait ToMat3 { @@ -1179,7 +1180,7 @@ pub type Mat4f = Mat4; pub type Mat4f32 = Mat4; pub type Mat4f64 = Mat4; -impl_dimensional!(Mat4, Vec4, 4) +impl_dimensioned!(Mat4, Vec4, 4) impl_approx!(Mat4 { x, y, z, w }) pub trait ToMat4 { @@ -1460,7 +1461,7 @@ impl FloatMat,[Vec4,..4]> for Mat4 { } } - // Swap columns i1 and j in A and I to + // SwapComponents columns i1 and j in A and I to // put pivot on diagonal A.swap_cols(i1, j); I.swap_cols(i1, j); diff --git a/src/math/math.rs b/src/math/math.rs index 7f16264..9159c72 100644 --- a/src/math/math.rs +++ b/src/math/math.rs @@ -40,14 +40,14 @@ pub mod plane; pub mod point; pub mod ray; -pub trait Dimensional { +pub trait Dimensioned { pub fn index<'a>(&'a self, i: uint) -> &'a T; pub fn index_mut<'a>(&'a mut self, i: uint) -> &'a mut T; pub fn as_slice<'a>(&'a self) -> &'a Slice; pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut Slice; } -pub trait Swap { +pub trait SwapComponents { pub fn swap(&mut self, a: uint, b: uint); } diff --git a/src/math/point.rs b/src/math/point.rs index 56fe160..6ac5807 100644 --- a/src/math/point.rs +++ b/src/math/point.rs @@ -22,7 +22,7 @@ use std::cast; -use math::{Dimensional, Swap}; +use math::{Dimensioned, SwapComponents}; use math::{Mat2, Mat3, Quat}; use math::{Ray2, Ray3}; use math::{Vec2, ToVec2, AsVec2}; @@ -48,10 +48,10 @@ pub trait Point: Eq #[deriving(Clone, Eq)] pub struct Point2 { x: T, y: T } -impl_dimensional!(Point2, T, 2) +impl_dimensioned!(Point2, T, 2) impl_to_vec!(Point2, 2) impl_as_vec!(Point2, 2) -impl_swap!(Point2) +impl_swap_components!(Point2) impl_approx!(Point2 { x, y }) pub trait AsPoint2 { @@ -188,10 +188,10 @@ mod test_point2 { #[deriving(Clone, Eq)] pub struct Point3 { x: T, y: T, z: T } -impl_dimensional!(Point3, T, 3) +impl_dimensioned!(Point3, T, 3) impl_to_vec!(Point3, 3) impl_as_vec!(Point3, 3) -impl_swap!(Point3) +impl_swap_components!(Point3) impl_approx!(Point3 { x, y, z }) pub trait AsPoint3 { diff --git a/src/math/quat.rs b/src/math/quat.rs index 65b6668..76221ac 100644 --- a/src/math/quat.rs +++ b/src/math/quat.rs @@ -15,7 +15,7 @@ //! Quaternion type -use math::{Dimensional, Swap}; +use math::{Dimensioned, SwapComponents}; use math::{Mat3, ToMat3}; use math::Vec3; @@ -34,8 +34,8 @@ pub type Quatf64 = Quat; #[deriving(Clone, Eq)] pub struct Quat { s: T, v: Vec3 } -impl_dimensional!(Quat, T, 4) -impl_swap!(Quat) +impl_dimensioned!(Quat, T, 4) +impl_swap_components!(Quat) impl_approx!(Quat { s, v }) pub trait ToQuat { diff --git a/src/math/vec.rs b/src/math/vec.rs index ba316d2..11a5004 100644 --- a/src/math/vec.rs +++ b/src/math/vec.rs @@ -15,9 +15,10 @@ //! Abstract vector types -use math::{Dimensional, Swap}; +use math::{Dimensioned, SwapComponents}; -pub trait Vec: Dimensional + Swap {} +pub trait Vec: Dimensioned + + SwapComponents {} /// Vectors with numeric components pub trait NumVec: Neg { @@ -119,8 +120,8 @@ pub trait AsVec2 { pub fn as_mut_vec2<'a>(&'a mut self) -> &'a mut Vec2; } -impl_dimensional!(Vec2, T, 2) -impl_swap!(Vec2) +impl_dimensioned!(Vec2, T, 2) +impl_swap_components!(Vec2) impl_approx!(Vec2 { x, y }) impl Vec2 { @@ -659,8 +660,8 @@ pub trait AsVec3 { pub fn as_mut_vec3<'a>(&'a mut self) -> &'a mut Vec3; } -impl_dimensional!(Vec3, T, 3) -impl_swap!(Vec3) +impl_dimensioned!(Vec3, T, 3) +impl_swap_components!(Vec3) impl_approx!(Vec3 { x, y, z }) impl Vec3 { @@ -1265,8 +1266,8 @@ pub trait AsVec4 { pub fn as_mut_vec4<'a>(&'a mut self) -> &'a mut Vec4; } -impl_dimensional!(Vec4, T, 4) -impl_swap!(Vec4) +impl_dimensioned!(Vec4, T, 4) +impl_swap_components!(Vec4) impl_approx!(Vec4 { x, y, z, w }) impl Vec4 {