diff --git a/src/translate.rs b/src/translate.rs index ff25c96..a8c1589 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -59,11 +59,67 @@ fn cap_layers_dome(mushroom: &Mushroom, base: &Vertex, resolution: f32) -> Vec Vec { + // use spline::{Interpolation, Key, Spline}; + + // fn main() { + // // Define the example points + // let x_points = vec![0.0, 1.0, 2.0]; + // let y_points = vec![1.0, 0.2, 0.0]; + + // // Create the keys for the spline + // let keys: Vec> = x_points + // .iter() + // .zip(y_points.iter()) + // .map(|(&x, &y)| Key::new(x, y, Interpolation::CatmullRom)) + // .collect(); + + // // Create the spline + // let spline = Spline::from_vec(keys); + + // // Function to solve for x given y + // let y_target = 0.5; + // if let Some(x_solved) = solve_for_x(&spline, y_target, 0.0, 2.0, 1e-6, 1000) { + // println!("x value for y = {} is x = {}", y_target, x_solved); + // } else { + // println!("Could not find x value for y = {}", y_target); + // } + // } + + // Function to solve for x given y using binary search + // fn solve_for_x(spline: &Spline, y: f64, x_min: f64, x_max: f64, tol: f64, max_iter: usize) -> Option { + // let mut left = x_min; + // let mut right = x_max; + // let mut iter = 0; + + // while right - left > tol && iter < max_iter { + // let mid = (left + right) / 2.0; + // let y_mid = spline.clamped_sample(mid).unwrap_or(0.0); + + // if (y_mid - y).abs() < tol { + // return Some(mid); + // } else if y_mid < y { + // left = mid; + // } else { + // right = mid; + // } + + // iter += 1; + // } + + // None + // } + + // TODO: + // Investigate using spline to generate a pointed style cap. + return cap_layers_dome(mushroom, base, resolution); +} + fn cap_layers(mushroom: &Mushroom, base: &Vertex, resolution: f32) -> Vec { match mushroom.cap_style { CapStyle::Cylinder => cap_layers_cylinder(mushroom, base), CapStyle::Dome => cap_layers_dome(mushroom, base, resolution), - CapStyle::Pointed => cap_layers_dome(mushroom, base, resolution), + CapStyle::Pointed => cap_layers_pointed(mushroom, base, resolution), } }