lj_rust/src/transformer/flip_horizontal.rs

29 lines
574 B
Rust

use crate::transformer::Transformers;
use crate::point::Point;
use serde::{Serialize,Deserialize};
/// Flip Horizontal
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
pub struct FlipHorizontal {
x: f32,
}
impl FlipHorizontal {
pub fn new(x: f32) -> Self {
Self {x}
}
}
impl Transformers for FlipHorizontal {
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
point_list.iter()
.map(| pt | {
let dx = pt.x - self.x;
Point { x: dx - 2. * dx,
..*pt
}
}).collect()
}
}