This commit is contained in:
Lapin Raving 2023-08-23 13:13:53 +02:00
parent 4a87821c22
commit baf149ef8a
23 changed files with 1030 additions and 856 deletions

View file

@ -1,35 +1,32 @@
use crate::transformer::Transformers;
use crate::point::Point;
use crate::transformer::Transformers;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize};
use serde::{Deserialize, Serialize};
//use std::f32::consts::PI;
/// Rotate
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
#[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], _ws: &WorldState) -> Vec<Point> {
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()
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()
}
}