50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
use crate::point::{Color, Point};
|
|
use crate::transformer::Transformers;
|
|
use crate::worldstate::WorldState;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Replicate
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
|
pub enum Replicate {
|
|
Until(usize),
|
|
Times(usize),
|
|
}
|
|
|
|
impl Transformers for Replicate {
|
|
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> {
|
|
let mut point_list2 = vec![];
|
|
|
|
match self {
|
|
Replicate::Until(n) => {
|
|
while point_list2.len() < *n {
|
|
if point_list.len() == 0 {
|
|
// to prevent infinit loop in case of empty frame
|
|
point_list2.append(
|
|
&mut vec![
|
|
Point {
|
|
x: 0.,
|
|
y: 0.,
|
|
color: Color { r: 0, g: 0, b: 0 }
|
|
};
|
|
*n
|
|
]
|
|
.to_vec(),
|
|
);
|
|
} else {
|
|
point_list2.append(&mut point_list.to_vec());
|
|
}
|
|
}
|
|
}
|
|
Replicate::Times(n) => {
|
|
for _ in 0..*n {
|
|
point_list2.append(&mut point_list.to_vec());
|
|
}
|
|
}
|
|
}
|
|
point_list2
|
|
}
|
|
}
|