Add support for CapStyle::Dome.
This commit is contained in:
1 parent
ffa151135b
commit
e90f330a5e
1 file changed
+34
-2
+34
-2
@@ -1,6 +1,6 @@
|
|||||||
use stl_io::{self, Vertex};
|
use stl_io::{self, Vertex};
|
||||||
|
|
||||||
use crate::mushroom::Mushroom;
|
use crate::mushroom::{CapStyle, Mushroom};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Layer {
|
pub struct Layer {
|
||||||
@@ -53,7 +53,7 @@ fn stalk_layers(mushroom: &Mushroom, base: &Vertex, _resolution: f32) -> Vec<Lay
|
|||||||
.to_vec();
|
.to_vec();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cap_layers(mushroom: &Mushroom, base: &Vertex, _resolution: f32) -> Vec<Layer> {
|
fn cap_layers_cylinder(mushroom: &Mushroom, base: &Vertex) -> Vec<Layer> {
|
||||||
let top = Vertex::new([base[0], base[1], base[2] + mushroom.cap_h]);
|
let top = Vertex::new([base[0], base[1], base[2] + mushroom.cap_h]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -69,6 +69,38 @@ fn cap_layers(mushroom: &Mushroom, base: &Vertex, _resolution: f32) -> Vec<Layer
|
|||||||
.to_vec();
|
.to_vec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cap_layers_dome(mushroom: &Mushroom, base: &Vertex, resolution: f32) -> Vec<Layer> {
|
||||||
|
let mut result: Vec<Layer> = Vec::with_capacity((mushroom.cap_h / resolution) as usize);
|
||||||
|
|
||||||
|
let mut height = 0.0;
|
||||||
|
loop {
|
||||||
|
// A = mushroom.cap_h
|
||||||
|
// B = mushroom.cap_r
|
||||||
|
// x=B/π * arccos(y/A)
|
||||||
|
let radius = (mushroom.cap_r / std::f32::consts::PI) * (height / mushroom.cap_h).acos();
|
||||||
|
|
||||||
|
result.push(Layer {
|
||||||
|
center: Vertex::new([base[0], base[1], base[2] + height]),
|
||||||
|
radius: radius,
|
||||||
|
});
|
||||||
|
|
||||||
|
height += resolution;
|
||||||
|
if height >= mushroom.cap_h {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cap_layers(mushroom: &Mushroom, base: &Vertex, resolution: f32) -> Vec<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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mushroom(mushroom: &Mushroom, resolution: f32) -> Layers {
|
pub fn mushroom(mushroom: &Mushroom, resolution: f32) -> Layers {
|
||||||
let _vertical_steps = (mushroom.height() / resolution) as u32;
|
let _vertical_steps = (mushroom.height() / resolution) as u32;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user