cleanup and new grid
This commit is contained in:
parent
81de6728fc
commit
9a5db444a0
8 changed files with 83 additions and 33 deletions
|
|
@ -9,12 +9,6 @@ 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()
|
||||
|
|
|
|||
|
|
@ -9,12 +9,6 @@ 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()
|
||||
|
|
|
|||
56
src/transformer/grid.rs
Normal file
56
src/transformer/grid.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
use crate::transformer::Transformers;
|
||||
use crate::point::Point;
|
||||
use serde::{Serialize,Deserialize};
|
||||
|
||||
/// Translate
|
||||
|
||||
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
||||
pub struct Grid {
|
||||
width: f32,
|
||||
height: f32
|
||||
}
|
||||
|
||||
fn square_box(size: f32, color: u32) -> Vec<(f32, f32, u32)> {
|
||||
vec![
|
||||
(-size, -size, 0),
|
||||
(-size, -size, color),
|
||||
|
||||
(0.0, -size, color),
|
||||
(0.0, -size, color),
|
||||
|
||||
(size, -size, color),
|
||||
(size, -size, color),
|
||||
|
||||
(size, 0.0, color),
|
||||
(size, 0.0, color),
|
||||
|
||||
(size, size, color),
|
||||
(size, size, color),
|
||||
|
||||
(0.0, size, color),
|
||||
(0.0, size, color),
|
||||
|
||||
(-size, size, color),
|
||||
(-size, size, color),
|
||||
|
||||
(-size, 0.0, color),
|
||||
(-size, 0.0, color),
|
||||
|
||||
(-size, -size, color),
|
||||
(-size, -size, color),
|
||||
|
||||
(-size, -size, 0)
|
||||
]
|
||||
}
|
||||
|
||||
impl Transformers for Grid {
|
||||
fn apply(&self, _point_list: &[Point]) -> Vec<Point> {
|
||||
let mut sq1 = square_box(1000.0, 255 << 8);
|
||||
let mut line = square_box(2000.0, 255);
|
||||
line.append(&mut sq1);
|
||||
|
||||
let line: Vec<Point> = line.into_iter()
|
||||
.map(|tpl| tpl.into()).collect();
|
||||
line
|
||||
}
|
||||
}
|
||||
|
|
@ -13,12 +13,6 @@ pub struct Rotate {
|
|||
|
||||
}
|
||||
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -6,18 +6,12 @@ use serde::{Serialize,Deserialize};
|
|||
|
||||
#[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 }
|
||||
}
|
||||
pub x: f32,
|
||||
pub y: f32
|
||||
}
|
||||
|
||||
impl Transformers for Translate {
|
||||
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
||||
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
||||
point_list.iter()
|
||||
.map(| pt | {
|
||||
Point { x: pt.x + self.x,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue