lj_rust/src/transformer/rotate.rs

33 lines
834 B
Rust
Raw Normal View History

use crate::point::Point;
2023-08-23 11:13:53 +00:00
use crate::transformer::Transformers;
2023-06-29 21:24:56 +00:00
use crate::worldstate::WorldState;
2023-08-23 11:13:53 +00:00
use serde::{Deserialize, Serialize};
2023-06-10 16:53:10 +00:00
//use std::f32::consts::PI;
/// Rotate
2023-08-23 11:13:53 +00:00
#[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> {
2023-08-23 11:13:53 +00:00
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()
}
}