From e9948f55d07da0b2a25dc6567e871b666571570c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Thu, 6 Jun 2013 22:57:07 +0000 Subject: [PATCH] Add rotation wrt a point. --- src/traits/rotation.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/traits/rotation.rs b/src/traits/rotation.rs index 59b6c499..bf4a9e37 100644 --- a/src/traits/rotation.rs +++ b/src/traits/rotation.rs @@ -1,3 +1,5 @@ +use traits::translation::Translation; + /// Trait of object which represent a rotation, and to wich new rotations can /// be appended. A rotation is assumed to be an isomitry without translation /// and without reflexion. @@ -13,3 +15,21 @@ pub trait Rotation /// In-place version of `rotated`. fn rotate(&mut self, &V); } + +/** + * Applies a rotation centered on a specific point. + * + * - `m`: the object to be rotated. + * - `ammount`: the rotation to apply. + * - `point`: the center of rotation. + */ +pub fn rotate_wrt_point + Translation, LV: Neg, AV> + (m: &M, ammount: &AV, center: &LV) -> M +{ + let mut res = m.translated(&-center); + + res.rotate(ammount); + res.translate(center); + + res +}