use crate::transformer::Transformers; use crate::point::Point; use serde::{Serialize,Deserialize}; //use std::f32::consts::PI; /// Rotate #[derive(Serialize,Deserialize,Debug,Clone,Copy)] pub struct Rotate { cx: f32, cy: f32, angle: f32, } impl Transformers for Rotate { fn apply(&self, point_list: &[Point]) -> Vec { point_list.iter() .map(| pt | { let dx = pt.x - self.cx; let dy = pt.y - self.cy; let cos = self.angle.cos(); let sin = self.angle.sin(); let x = (dx * cos - dy * sin) + self.cx; let y = (dx * sin + dy * cos) + self.cy; Point { x, y, ..*pt } }).collect() } }