diff --git a/src/na.rs b/src/na.rs index 3c03868e..d7a5bc28 100644 --- a/src/na.rs +++ b/src/na.rs @@ -33,6 +33,7 @@ pub use traits::{ Rotate, Rotation, RotationMatrix, RotationWithTranslation, Row, ScalarAdd, ScalarSub, + ScalarMul, ScalarAdd, ToHomogeneous, Transform, Transformation, Translate, Translation, diff --git a/src/traits/mod.rs b/src/traits/mod.rs index 1c471b45..a4901797 100644 --- a/src/traits/mod.rs +++ b/src/traits/mod.rs @@ -9,7 +9,7 @@ pub use self::structure::{FloatVec, FloatVecExt, Basis, Cast, Col, Dim, Indexabl ColSlice, RowSlice, Eye}; pub use self::operations::{Absolute, ApproxEq, Cov, Inv, LMul, Mean, Outer, PartialOrd, RMul, - ScalarAdd, ScalarSub, Transpose}; + ScalarAdd, ScalarSub, ScalarMul, ScalarDiv, Transpose}; pub use self::operations::{PartialOrdering, PartialLess, PartialEqual, PartialGreater, NotComparable}; pub mod geometry; diff --git a/src/traits/operations.rs b/src/traits/operations.rs index 382d3eb7..cb09a0ee 100644 --- a/src/traits/operations.rs +++ b/src/traits/operations.rs @@ -316,9 +316,7 @@ impl> ScalarAdd for T { } } -/** - * Trait of objects having a subtraction with a scalar. - */ +/// Trait of objects having a subtraction with a scalar. pub trait ScalarSub { /// Gets the result of `self - n`. fn sub_s(&self, n: &N) -> Self; @@ -330,3 +328,29 @@ impl> ScalarSub for T { *self - *n } } + +/// Trait of objects having a multiplication with a scalar. +pub trait ScalarMul { + /// Gets the result of `self * n`. + fn mul_s(&self, n: &N) -> Self; +} + +impl> ScalarMul for T { + /// Gets the result of `self * n`. + fn mul_s(&self, n: &N) -> T { + *self * *n + } +} + +/// Trait of objects having a division by a scalar. +pub trait ScalarDiv { + /// Gets the result of `self / n`. + fn div_s(&self, n: &N) -> Self; +} + +impl> ScalarDiv for T { + /// Gets the result of `self / n`. + fn div_s(&self, n: &N) -> T { + *self / *n + } +}