translate: Stub out the pointed cap style.

This commit is contained in:
dongar committed 2024-06-16 06:31:08 -05:00
1 parent b731b29c96
commit d979e55a20
1 file changed
+57 -1
+57 -1
View File
@@ -59,11 +59,67 @@ fn cap_layers_dome(mushroom: &Mushroom, base: &Vertex, resolution: f32) -> Vec<l
return result;
}
fn cap_layers_pointed(mushroom: &Mushroom, base: &Vertex, resolution: f32) -> Vec<layers::Layer> {
// 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<Key<f64, f64>> = 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<f64, f64>, y: f64, x_min: f64, x_max: f64, tol: f64, max_iter: usize) -> Option<f64> {
// 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<layers::Layer> {
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),
}
}