Files
mushroom_generator/src/mushroom.rs
T

45 lines
1.0 KiB
Rust

use serde_derive::Serialize;
#[derive(clap::ValueEnum, Clone, Default, Debug, Serialize, PartialEq, FromFormField)]
pub enum CapStyle {
Cylinder,
#[default]
Dome,
Pointed,
}
#[derive(Debug, PartialEq, Clone, FromForm)]
pub struct Mushroom {
/// Stalk height in millimeters. Zero for default.
#[field(default = 66.0)]
pub stalk_h: f32,
/// Stalk diameter in millimeters. Zero for default.
#[field(default = 5.0)]
pub stalk_r: f32,
/// Cap height in millimeters. Zero for default.
#[field(default = 34.0)]
pub cap_h: f32,
/// Stalk diameter in millimeters. Zero for default.
#[field(default = 50.0)]
pub cap_r: f32,
/// General shape of the cap.
#[field(default = CapStyle::Dome)]
pub cap_style: CapStyle,
}
impl Mushroom {
/// Total height of the mushroom.
pub fn height(&self) -> f32 {
return self.stalk_h + self.cap_h;
}
/// Maximum radius of the mushroom.
pub fn radius(&self) -> f32 {
return self.stalk_r.max(self.cap_r) / 2.0;
}
}