From 2ecc99b6a72516f8673c50b97cbfdf8aa3e4d3c2 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 15 Jul 2013 12:03:03 +1000 Subject: [PATCH] Documentation work --- src/math/vec.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/math/vec.rs b/src/math/vec.rs index 03ebc0e..5c55ef7 100644 --- a/src/math/vec.rs +++ b/src/math/vec.rs @@ -17,6 +17,7 @@ use math::{Dimensioned, SwapComponents}; +/// Generic vector trait pub trait Vec: Dimensioned + SwapComponents {} @@ -243,48 +244,56 @@ impl NumVec for Vec2 { *self.index(1) % value) } + /// Returns the sum of the two vectors. #[inline] pub fn add_v(&self, other: &Vec2) -> Vec2 { Vec2::new(*self.index(0) + *other.index(0), *self.index(1) + *other.index(1)) } + /// Ruturns the result of subtrating `other` from the vector. #[inline] pub fn sub_v(&self, other: &Vec2) -> Vec2 { Vec2::new(*self.index(0) - *other.index(0), *self.index(1) - *other.index(1)) } + /// Returns the component-wise product of the vector and `other`. #[inline] pub fn mul_v(&self, other: &Vec2) -> Vec2 { Vec2::new(*self.index(0) * *other.index(0), *self.index(1) * *other.index(1)) } + /// Returns the component-wise quotient of the vectors. #[inline] pub fn div_v(&self, other: &Vec2) -> Vec2 { Vec2::new(*self.index(0) / *other.index(0), *self.index(1) / *other.index(1)) } + /// Returns the component-wise remainder of the vector divided by `other`. #[inline] pub fn rem_v(&self, other: &Vec2) -> Vec2 { Vec2::new(*self.index(0) % *other.index(0), *self.index(1) % *other.index(1)) } + /// Negates each component of the vector. #[inline] pub fn neg_self(&mut self) { *self.index_mut(0) = -*self.index(0); *self.index_mut(1) = -*self.index(1); } + /// Adds `value` to each component of the vector. #[inline] pub fn add_self_t(&mut self, value: T) { *self.index_mut(0) = *self.index(0) + value; *self.index_mut(1) = *self.index(1) + value; } + /// Subtracts `value` from each component of the vector. #[inline] pub fn sub_self_t(&mut self, value: T) { *self.index_mut(0) = *self.index(0) - value; @@ -875,6 +884,7 @@ impl NumVec for Vec3 { *self.index(2) % value) } + /// Returns the sum of the two vectors. #[inline] pub fn add_v(&self, other: &Vec3) -> Vec3 { Vec3::new(*self.index(0) + *other.index(0), @@ -882,6 +892,7 @@ impl NumVec for Vec3 { *self.index(2) + *other.index(2)) } + /// Ruturns the result of subtrating `other` from the vector. #[inline] pub fn sub_v(&self, other: &Vec3) -> Vec3 { Vec3::new(*self.index(0) - *other.index(0), @@ -889,6 +900,7 @@ impl NumVec for Vec3 { *self.index(2) - *other.index(2)) } + /// Returns the component-wise product of the vector and `other`. #[inline] pub fn mul_v(&self, other: &Vec3) -> Vec3 { Vec3::new(*self.index(0) * *other.index(0), @@ -896,6 +908,7 @@ impl NumVec for Vec3 { *self.index(2) * *other.index(2)) } + /// Returns the component-wise quotient of the vectors. #[inline] pub fn div_v(&self, other: &Vec3) -> Vec3 { Vec3::new(*self.index(0) / *other.index(0), @@ -903,6 +916,7 @@ impl NumVec for Vec3 { *self.index(2) / *other.index(2)) } + /// Returns the component-wise remainder of the vector divided by `other`. #[inline] pub fn rem_v(&self, other: &Vec3) -> Vec3 { Vec3::new(*self.index(0) % *other.index(0), @@ -910,6 +924,7 @@ impl NumVec for Vec3 { *self.index(2) % *other.index(2)) } + /// Negates each component of the vector. #[inline] pub fn neg_self(&mut self) { *self.index_mut(0) = -*self.index(0); @@ -917,6 +932,7 @@ impl NumVec for Vec3 { *self.index_mut(2) = -*self.index(2); } + /// Adds `value` to each component of the vector. #[inline] pub fn add_self_t(&mut self, value: T) { *self.index_mut(0) = *self.index(0) + value; @@ -924,6 +940,7 @@ impl NumVec for Vec3 { *self.index_mut(2) = *self.index(2) + value; } + /// Subtracts `value` from each component of the vector. #[inline] pub fn sub_self_t(&mut self, value: T) { *self.index_mut(0) = *self.index(0) - value; @@ -1541,6 +1558,7 @@ impl NumVec for Vec4 { *self.index(3) % value) } + /// Returns the sum of the two vectors. #[inline] pub fn add_v(&self, other: &Vec4) -> Vec4 { Vec4::new(*self.index(0) + *other.index(0), @@ -1549,6 +1567,7 @@ impl NumVec for Vec4 { *self.index(3) + *other.index(3)) } + /// Ruturns the result of subtrating `other` from the vector. #[inline] pub fn sub_v(&self, other: &Vec4) -> Vec4 { Vec4::new(*self.index(0) - *other.index(0), @@ -1557,6 +1576,7 @@ impl NumVec for Vec4 { *self.index(3) - *other.index(3)) } + /// Returns the component-wise product of the vector and `other`. #[inline] pub fn mul_v(&self, other: &Vec4) -> Vec4 { Vec4::new(*self.index(0) * *other.index(0), @@ -1565,6 +1585,7 @@ impl NumVec for Vec4 { *self.index(3) * *other.index(3)) } + /// Returns the component-wise quotient of the vectors. #[inline] pub fn div_v(&self, other: &Vec4) -> Vec4 { Vec4::new(*self.index(0) / *other.index(0), @@ -1573,6 +1594,7 @@ impl NumVec for Vec4 { *self.index(3) / *other.index(3)) } + /// Returns the component-wise remainder of the vector divided by `other`. #[inline] pub fn rem_v(&self, other: &Vec4) -> Vec4 { Vec4::new(*self.index(0) % *other.index(0), @@ -1581,6 +1603,7 @@ impl NumVec for Vec4 { *self.index(3) % *other.index(3)) } + /// Negates each component of the vector. #[inline] pub fn neg_self(&mut self) { *self.index_mut(0) = -*self.index(0); @@ -1589,6 +1612,7 @@ impl NumVec for Vec4 { *self.index_mut(3) = -*self.index(3); } + /// Adds `value` to each component of the vector. #[inline] pub fn add_self_t(&mut self, value: T) { *self.index_mut(0) = *self.index(0) + value; @@ -1597,6 +1621,7 @@ impl NumVec for Vec4 { *self.index_mut(3) = *self.index(3) + value; } + /// Subtracts `value` from each component of the vector. #[inline] pub fn sub_self_t(&mut self, value: T) { *self.index_mut(0) = *self.index(0) - value;