use std::fmt;
pub const TAU: f64 = std::f64::consts::TAU;
#[inline]
pub fn ga() -> f64 {
std::f64::consts::PI * (3.0 - 5.0_f64.sqrt())
}
pub const VERSION: &str = "1.0.0";
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Layout {
Fibonacci,
Random,
}
impl Default for Layout {
fn default() -> Self {
Layout::Fibonacci
}
}
impl Layout {
pub fn from_str_opt(s: &str) -> Option<Layout> {
match s {
"fibonacci" => Some(Layout::Fibonacci),
"random" => Some(Layout::Random),
_ => None,
}
}
pub fn as_str(self) -> &'static str {
match self {
Layout::Fibonacci => "fibonacci",
Layout::Random => "random",
}
}
}
impl fmt::Display for Layout {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
pub type SpectrumFn = Box<dyn Fn(f64) -> f64>;
pub struct HelixOptions {
pub modes: usize,
pub slope: f64,
pub helicity: f64,
pub coherence: f64,
pub kmin: f64,
pub kmax: f64,
pub centers: i64,
pub amplitude: f64,
pub tileable: bool,
pub seed: u32,
pub layout: Layout,
pub churn: f64,
pub decay: f64,
pub anisotropy: f64,
pub axis: [f64; 3],
pub spectrum: Option<SpectrumFn>,
}
impl Default for HelixOptions {
fn default() -> Self {
HelixOptions {
modes: 48,
slope: 1.6,
helicity: 0.0,
coherence: 0.0,
kmin: 1.0,
kmax: 6.2,
centers: 3,
amplitude: 1.0,
tileable: false,
seed: 1,
layout: Layout::Fibonacci,
churn: 1.0,
decay: 0.0,
anisotropy: 0.0,
axis: [0.0, 0.0, 1.0],
spectrum: None,
}
}
}
impl fmt::Debug for HelixOptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("HelixOptions")
.field("modes", &self.modes)
.field("slope", &self.slope)
.field("helicity", &self.helicity)
.field("coherence", &self.coherence)
.field("kmin", &self.kmin)
.field("kmax", &self.kmax)
.field("centers", &self.centers)
.field("amplitude", &self.amplitude)
.field("tileable", &self.tileable)
.field("seed", &self.seed)
.field("layout", &self.layout)
.field("churn", &self.churn)
.field("decay", &self.decay)
.field("anisotropy", &self.anisotropy)
.field("axis", &self.axis)
.field("spectrum", &self.spectrum.as_ref().map(|_| "<fn>"))
.finish()
}
}