|
| 1 | +use std::ops::{Mul, MulAssign}; |
| 2 | + |
1 | 3 | use crate::{ffi::graphics as ffi, graphics::FloatRect, system::Vector2f};
|
2 | 4 |
|
3 | 5 | /// Define a 3x3 transform matrix.
|
@@ -195,3 +197,63 @@ impl Default for Transform {
|
195 | 197 | Self::IDENTITY
|
196 | 198 | }
|
197 | 199 | }
|
| 200 | + |
| 201 | +impl Mul for Transform { |
| 202 | + type Output = Self; |
| 203 | + |
| 204 | + /// Combines two transformations |
| 205 | + /// |
| 206 | + /// Equivelant to calling `left.clone().combine(right)` |
| 207 | + /// |
| 208 | + /// Returns new combined Transform |
| 209 | + /// ``` |
| 210 | + /// # use sfml::graphics::Transform; |
| 211 | + /// let test_transform = Transform::new(1., 2., 3., 4., 5., 6., 7., 8., 9.); |
| 212 | + /// let result = Transform::new(30., 36., 42., 66., 81., 96., 102., 126., 150.); |
| 213 | + /// assert_eq!(test_transform * test_transform, result); |
| 214 | + /// ``` |
| 215 | + fn mul(self, rhs: Self) -> Self::Output { |
| 216 | + let mut clone_self = self; |
| 217 | + clone_self.combine(&rhs); |
| 218 | + clone_self |
| 219 | + } |
| 220 | +} |
| 221 | + |
| 222 | +impl MulAssign for Transform { |
| 223 | + /// Combines two transformations |
| 224 | + /// |
| 225 | + /// Equivelant to calling `left.combine(right)` |
| 226 | + /// |
| 227 | + /// Returns new combined Transform |
| 228 | + /// ``` |
| 229 | + /// # use sfml::graphics::Transform; |
| 230 | + /// let mut test_transform = Transform::new(1., 2., 3., 4., 5., 6., 7., 8., 9.); |
| 231 | + /// let result = Transform::new(30., 36., 42., 66., 81., 96., 102., 126., 150.); |
| 232 | + /// test_transform *= test_transform; |
| 233 | + /// assert_eq!(test_transform, result); |
| 234 | + /// ``` |
| 235 | + fn mul_assign(&mut self, rhs: Self) { |
| 236 | + self.combine(&rhs); |
| 237 | + } |
| 238 | +} |
| 239 | + |
| 240 | +impl Mul<Vector2f> for Transform { |
| 241 | + type Output = Vector2f; |
| 242 | + |
| 243 | + /// Transforms a point |
| 244 | + /// |
| 245 | + /// Equivalent to calling `left.transform_point(right)` |
| 246 | + /// |
| 247 | + /// Returns a new transformed points |
| 248 | + /// ``` |
| 249 | + /// # use sfml::graphics::Transform; |
| 250 | + /// # use sfml::system::Vector2f; |
| 251 | + /// let test_transform = Transform::new(1., 2., 3., 4., 5., 6., 7., 8., 9.); |
| 252 | + /// let test_point = Vector2f::new(2., 3.); |
| 253 | + /// let result = Vector2f::new(11., 29.); |
| 254 | + /// assert_eq!(test_transform * test_point, result); |
| 255 | + /// ``` |
| 256 | + fn mul(self, rhs: Vector2f) -> Self::Output { |
| 257 | + self.transform_point(rhs) |
| 258 | + } |
| 259 | +} |
0 commit comments