30 lines
501 B
Rust
30 lines
501 B
Rust
use crate::Transformers;
|
|
use crate::point::Point;
|
|
use serde::{Serialize,Deserialize};
|
|
|
|
/// Translate
|
|
|
|
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
|
pub struct Translate {
|
|
x: f32,
|
|
y: f32
|
|
}
|
|
|
|
impl Translate {
|
|
pub fn new(x: f32, y: f32) -> Self {
|
|
Self { x, y }
|
|
}
|
|
}
|
|
|
|
impl Transformers for Translate {
|
|
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
|
point_list.iter()
|
|
.map(| pt | {
|
|
Point { x: pt.x + self.x,
|
|
y: pt.y + self.y,
|
|
..*pt
|
|
}
|
|
}).collect()
|
|
}
|
|
}
|