Rename comp_{add, mul} to {sum, product}

This commit is contained in:
Brendan Zabarauskas 2015-10-01 17:24:13 +10:00
parent 7bba6f77a9
commit af38e8a8be
4 changed files with 23 additions and 23 deletions

View file

@ -49,7 +49,7 @@ pub trait Aabb<S: BaseNum, V: Vector<S>, P: Point<S, V>>: Sized {
/// Return the volume this AABB encloses.
#[inline]
fn volume(&self) -> S { self.dim().comp_mul() }
fn volume(&self) -> S { self.dim().product() }
/// Return the center point of this AABB.
#[inline]

View file

@ -327,7 +327,7 @@ pub trait Matrix<S: BaseFloat, V: Vector<S> + 'static>: Array2<V, V, S> + Approx
/// Return the trace of this matrix. That is, the sum of the diagonal.
#[inline]
fn trace(&self) -> S { self.diagonal().comp_add() }
fn trace(&self) -> S { self.diagonal().sum() }
/// Invert this matrix, returning a new matrix. `m.mul_m(m.invert())` is
/// the identity matrix. Returns `None` if this matrix is not invertible

View file

@ -191,14 +191,14 @@ pub trait Vector<S: BaseNum>: Array1<S> + Clone // where
/// Take the remainder of this vector by another, in-place.
fn rem_self_v(&mut self, v: &Self);
/// The sum of each component of the vector.
fn comp_add(&self) -> S;
/// The product of each component of the vector.
fn comp_mul(&self) -> S;
/// The sum of the components of the vector.
fn sum(&self) -> S;
/// The product of the components of the vector.
fn product(&self) -> S;
/// Vector dot product.
#[inline]
fn dot(&self, v: &Self) -> S { self.mul_v(v).comp_add() }
fn dot(&self, v: &Self) -> S { self.mul_v(v).sum() }
/// The minimum component of the vector.
fn comp_min(&self) -> S;
@ -274,8 +274,8 @@ macro_rules! vec {
#[inline] fn div_self_v(&mut self, v: &$Self_<S>) { *self = &*self / v; }
#[inline] fn rem_self_v(&mut self, v: &$Self_<S>) { *self = &*self % v; }
#[inline] fn comp_add(&self) -> S { fold!(add, { $(self.$field),+ }) }
#[inline] fn comp_mul(&self) -> S { fold!(mul, { $(self.$field),+ }) }
#[inline] fn sum(&self) -> S { fold!(add, { $(self.$field),+ }) }
#[inline] fn product(&self) -> S { fold!(mul, { $(self.$field),+ }) }
#[inline] fn comp_min(&self) -> S { fold!(partial_min, { $(self.$field),+ }) }
#[inline] fn comp_max(&self) -> S { fold!(partial_max, { $(self.$field),+ }) }
}

View file

@ -41,25 +41,25 @@ fn test_dot() {
}
#[test]
fn test_comp_add() {
assert_eq!(Vector2::new(1isize, 2isize).comp_add(), 3isize);
assert_eq!(Vector3::new(1isize, 2isize, 3isize).comp_add(), 6isize);
assert_eq!(Vector4::new(1isize, 2isize, 3isize, 4isize).comp_add(), 10isize);
fn test_sum() {
assert_eq!(Vector2::new(1isize, 2isize).sum(), 3isize);
assert_eq!(Vector3::new(1isize, 2isize, 3isize).sum(), 6isize);
assert_eq!(Vector4::new(1isize, 2isize, 3isize, 4isize).sum(), 10isize);
assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_add(), 7.0f64);
assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_add(), 15.0f64);
assert_eq!(Vector4::new(5.0f64, 6.0f64, 7.0f64, 8.0f64).comp_add(), 26.0f64);
assert_eq!(Vector2::new(3.0f64, 4.0f64).sum(), 7.0f64);
assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).sum(), 15.0f64);
assert_eq!(Vector4::new(5.0f64, 6.0f64, 7.0f64, 8.0f64).sum(), 26.0f64);
}
#[test]
fn test_comp_mul() {
assert_eq!(Vector2::new(1isize, 2isize).comp_mul(), 2isize);
assert_eq!(Vector3::new(1isize, 2isize, 3isize).comp_mul(), 6isize);
assert_eq!(Vector4::new(1isize, 2isize, 3isize, 4isize).comp_mul(), 24isize);
fn test_product() {
assert_eq!(Vector2::new(1isize, 2isize).product(), 2isize);
assert_eq!(Vector3::new(1isize, 2isize, 3isize).product(), 6isize);
assert_eq!(Vector4::new(1isize, 2isize, 3isize, 4isize).product(), 24isize);
assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_mul(), 12.0f64);
assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_mul(), 120.0f64);
assert_eq!(Vector4::new(5.0f64, 6.0f64, 7.0f64, 8.0f64).comp_mul(), 1680.0f64);
assert_eq!(Vector2::new(3.0f64, 4.0f64).product(), 12.0f64);
assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).product(), 120.0f64);
assert_eq!(Vector4::new(5.0f64, 6.0f64, 7.0f64, 8.0f64).product(), 1680.0f64);
}
#[test]