use super::StabilityCurve;
use crate::hydrostatics::HydrostaticState;
#[derive(Debug, Clone)]
pub struct WindHeelingData {
pub emerged_area: f64,
pub emerged_centroid: [f64; 2],
pub submerged_centroid: [f64; 2],
pub wind_lever_arm: f64,
pub waterline_z: f64,
}
impl WindHeelingData {
pub fn new(
emerged_area: f64,
emerged_centroid: [f64; 2],
submerged_centroid: [f64; 2],
waterline_z: f64,
) -> Self {
let wind_lever_arm = emerged_centroid[1] - submerged_centroid[1];
Self {
emerged_area,
emerged_centroid,
submerged_centroid,
wind_lever_arm,
waterline_z,
}
}
}
#[derive(Debug, Clone)]
pub struct CompleteStabilityResult {
pub hydrostatics: HydrostaticState,
pub gz_curve: StabilityCurve,
pub wind_data: Option<WindHeelingData>,
pub displacement: f64,
pub cog: [f64; 3],
}
impl CompleteStabilityResult {
pub fn new(
hydrostatics: HydrostaticState,
gz_curve: StabilityCurve,
wind_data: Option<WindHeelingData>,
displacement: f64,
cog: [f64; 3],
) -> Self {
Self {
hydrostatics,
gz_curve,
wind_data,
displacement,
cog,
}
}
pub fn gm0(&self) -> Option<f64> {
self.hydrostatics.gmt
}
pub fn gm0_dry(&self) -> Option<f64> {
self.hydrostatics.gmt_dry
}
pub fn max_gz(&self) -> Option<f64> {
self.gz_curve.max_value().map(|p| p.value)
}
pub fn heel_at_max_gz(&self) -> Option<f64> {
self.gz_curve.max_value().map(|p| p.heel)
}
pub fn has_wind_data(&self) -> bool {
self.wind_data.is_some()
}
}