Make the slicer generic allowing slicing into different formats

This commit is contained in:
Connor Slade
2024-07-03 12:59:59 -04:00
parent 5fdf616fbe
commit 3fae064c63
7 changed files with 78 additions and 57 deletions

View File

@@ -39,8 +39,8 @@ impl Image {
let half_kernel_size = kernel_size / 2;
let mut kernel = vec![0.0; kernel_size];
for x in 0..kernel_size {
kernel[x] = gaussian((x - half_kernel_size) as f32, sigma);
for (i, e) in kernel.iter_mut().enumerate().take(kernel_size) {
*e = gaussian((i - half_kernel_size) as f32, sigma);
}
// Blur image horizontally
@@ -104,6 +104,6 @@ impl Image {
}
fn gaussian(x: f32, sigma: f32) -> f32 {
const ROOT_TWO_PI: f32 = 2.50662827463100050242;
const ROOT_TWO_PI: f32 = 2.506_628_3;
(x.powi(2) / (2.0 * sigma.powi(2))).exp() / (sigma * ROOT_TWO_PI)
}

View File

@@ -1,7 +1,7 @@
use crate::{config::SliceConfig, image::Image};
use crate::config::SliceConfig;
pub struct SliceResult<'a> {
pub layers: Vec<Image>,
pub struct SliceResult<'a, Layer> {
pub layers: Vec<Layer>,
pub slice_config: &'a SliceConfig,
}
@@ -9,3 +9,11 @@ pub struct Run {
pub length: u64,
pub value: u8,
}
pub trait EncodableLayer {
type Output: Send;
fn new() -> Self;
fn add_run(&mut self, length: u64, value: u8);
fn finish(self, layer: usize, config: &SliceConfig) -> Self::Output;
}