lj_rust/src/transformer/rotate.rs

36 lines
813 B
Rust
Raw Normal View History

use crate::transformer::Transformers;
use crate::point::Point;
2023-06-29 21:24:56 +00:00
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize};
2023-06-10 16:53:10 +00:00
//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 {
2023-06-29 21:24:56 +00:00
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> {
point_list.iter()
.map(| pt | {
2023-06-10 15:08:08 +00:00
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()
}
}