Compare commits
No commits in common. "256599095fb476226be6fd7db2dc17e3f10c92d1" and "0a5000eea024ca5f4b22d67c444a2e1030d37c47" have entirely different histories.
256599095f
...
0a5000eea0
@ -1,18 +1,12 @@
|
|||||||
//pub mod common;
|
//pub mod common;
|
||||||
mod translate;
|
mod translate;
|
||||||
mod replicate;
|
mod replicate;
|
||||||
mod rotate;
|
|
||||||
mod flip_horizontal;
|
|
||||||
mod flip_vertical;
|
|
||||||
|
|
||||||
use crate::point::Point;
|
use crate::point::Point;
|
||||||
|
|
||||||
// re-export transformers to be abe to use it directly from transformer::
|
// re-export transformers to be abe to use it directly from transformer::
|
||||||
pub use translate::Translate;
|
pub use translate::Translate;
|
||||||
pub use replicate::Replicate;
|
pub use replicate::Replicate;
|
||||||
pub use rotate::Rotate;
|
|
||||||
pub use flip_horizontal::FlipHorizontal;
|
|
||||||
pub use flip_vertical::FlipVertical;
|
|
||||||
|
|
||||||
pub trait Transformers {
|
pub trait Transformers {
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point>;
|
fn apply(&self, point_list: &[Point]) -> Vec<Point>;
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
use crate::transformer::Transformers;
|
|
||||||
use crate::point::Point;
|
|
||||||
use serde::{Serialize,Deserialize};
|
|
||||||
|
|
||||||
/// Flip Vertical
|
|
||||||
|
|
||||||
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
|
||||||
pub struct FlipVertical {
|
|
||||||
y: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FlipVertical {
|
|
||||||
pub fn new(y: f32) -> Self {
|
|
||||||
Self {y}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for FlipVertical {
|
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
|
||||||
point_list.iter()
|
|
||||||
.map(| pt | {
|
|
||||||
let dy = pt.y - self.y;
|
|
||||||
Point { y: dy - 2. * dy,
|
|
||||||
..*pt
|
|
||||||
}
|
|
||||||
}).collect()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
use crate::transformer::Transformers;
|
|
||||||
use crate::point::Point;
|
|
||||||
use serde::{Serialize,Deserialize};
|
|
||||||
use std::f32::consts::PI;
|
|
||||||
|
|
||||||
/// Rotate
|
|
||||||
|
|
||||||
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
|
||||||
pub struct Rotate {
|
|
||||||
cx: f32,
|
|
||||||
cy: f32,
|
|
||||||
angle: f32,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Rotate {
|
|
||||||
pub fn new(cx: f32, cy: f32, angle: f32) -> Self {
|
|
||||||
Self { cx, cy, angle: angle / 180. * PI}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for Rotate {
|
|
||||||
fn apply(&self, point_list: &[Point]) -> 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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user