lj_rust/src/transformer/rotate.rs

33 lines
834 B
Rust

use crate::point::Point;
use crate::transformer::Transformers;
use crate::worldstate::WorldState;
use serde::{Deserialize, Serialize};
//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], _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()
}
}