diff --git a/src/matrix.rs b/src/matrix.rs index e015b04..460a936 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -294,22 +294,28 @@ pub trait Matrix>: Array2 + ApproxEq + Sized { /// Multiply this matrix by a scalar, returning the new matrix. + #[must_use] fn mul_s(&self, s: S) -> Self; /// Divide this matrix by a scalar, returning the new matrix. + #[must_use] fn div_s(&self, s: S) -> Self; /// Take the remainder of this matrix by a scalar, returning the new /// matrix. + #[must_use] fn rem_s(&self, s: S) -> Self; /// Add this matrix with another matrix, returning the new metrix. + #[must_use] fn add_m(&self, m: &Self) -> Self; /// Subtract another matrix from this matrix, returning the new matrix. + #[must_use] fn sub_m(&self, m: &Self) -> Self; /// Multiplay a vector by this matrix, returning a new vector. fn mul_v(&self, v: &V) -> V; /// Multiply this matrix by another matrix, returning the new matrix. + #[must_use] fn mul_m(&self, m: &Self) -> Self; /// Negate this matrix in-place (multiply by scalar -1). @@ -332,6 +338,7 @@ pub trait Matrix>: Array2 fn mul_self_m(&mut self, m: &Self) { *self = self.mul_m(m); } /// Transpose this matrix, returning a new matrix. + #[must_use] fn transpose(&self) -> Self; /// Transpose this matrix in-place. fn transpose_self(&mut self); @@ -348,6 +355,7 @@ pub trait Matrix>: Array2 /// Invert this matrix, returning a new matrix. `m.mul_m(m.invert())` is /// the identity matrix. Returns `None` if this matrix is not invertible /// (has a determinant of zero). + #[must_use] fn invert(&self) -> Option; /// Invert this matrix in-place. diff --git a/src/point.rs b/src/point.rs index 38c6d73..4b8d6e3 100644 --- a/src/point.rs +++ b/src/point.rs @@ -73,13 +73,17 @@ pub trait Point>: Array1 + Clone { fn to_vec(&self) -> V; /// Multiply each component by a scalar, returning the new point. + #[must_use] fn mul_s(&self, s: S) -> Self; /// Divide each component by a scalar, returning the new point. + #[must_use] fn div_s(&self, s: S) -> Self; /// Subtract a scalar from each component, returning the new point. + #[must_use] fn rem_s(&self, s: S) -> Self; /// Add a vector to this point, returning the new point. + #[must_use] fn add_v(&self, v: &V) -> Self; /// Subtract another point from this one, returning a new vector. fn sub_p(&self, p: &Self) -> V; @@ -97,8 +101,10 @@ pub trait Point>: Array1 + Clone { /// This is a weird one, but its useful for plane calculations. fn dot(&self, v: &V) -> S; + #[must_use] fn min(&self, p: &Self) -> Self; + #[must_use] fn max(&self, p: &Self) -> Self; } diff --git a/src/vector.rs b/src/vector.rs index 66f8edb..1fe88e6 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -111,25 +111,35 @@ use num::{BaseNum, BaseFloat, Zero, One, zero, one}; /// for pragmatic reasons. pub trait Vector: Array1 + Zero + One + Neg { /// Add a scalar to this vector, returning a new vector. + #[must_use] fn add_s(&self, s: S) -> Self; /// Subtract a scalar from this vector, returning a new vector. + #[must_use] fn sub_s(&self, s: S) -> Self; /// Multiply this vector by a scalar, returning a new vector. + #[must_use] fn mul_s(&self, s: S) -> Self; /// Divide this vector by a scalar, returning a new vector. + #[must_use] fn div_s(&self, s: S) -> Self; /// Take the remainder of this vector by a scalar, returning a new vector. + #[must_use] fn rem_s(&self, s: S) -> Self; /// Add this vector to another, returning a new vector. + #[must_use] fn add_v(&self, v: &Self) -> Self; /// Subtract another vector from this one, returning a new vector. + #[must_use] fn sub_v(&self, v: &Self) -> Self; /// Multiply this vector by another, returning a new vector. + #[must_use] fn mul_v(&self, v: &Self) -> Self; /// Divide this vector by another, returning a new vector. + #[must_use] fn div_v(&self, v: &Self) -> Self; /// Take the remainder of this vector by another, returning a new scalar. + #[must_use] fn rem_v(&self, v: &Self) -> Self; /// Negate this vector in-place. @@ -410,6 +420,7 @@ impl Vector3 { /// Returns the cross product of the vector and `other`. #[inline] + #[must_use] pub fn cross(&self, other: &Vector3) -> Vector3 { Vector3::new((self.y * other.z) - (self.z * other.y), (self.z * other.x) - (self.x * other.z), @@ -498,12 +509,14 @@ pub trait EuclideanVector: Vector /// Returns a vector with the same direction, but with a `length` (or /// `norm`) of `1`. #[inline] + #[must_use] fn normalize(&self) -> Self { self.normalize_to(one::()) } /// Returns a vector with the same direction and a given `length`. #[inline] + #[must_use] fn normalize_to(&self, length: S) -> Self { self.mul_s(length / self.length()) } @@ -511,6 +524,7 @@ pub trait EuclideanVector: Vector /// Returns the result of linarly interpolating the length of the vector /// towards the length of `other` by the specified amount. #[inline] + #[must_use] fn lerp(&self, other: &Self, amount: S) -> Self { self.add_v(&other.sub_v(self).mul_s(amount)) }