71 lines
2.3 KiB
Rust
71 lines
2.3 KiB
Rust
#![forbid(unsafe_code)]
|
|
|
|
pub mod ex;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
|
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
|
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case", tag = "type"))]
|
|
pub enum SelectExample {
|
|
AstroidPedal { a: f64 },
|
|
|
|
CassiniOval { a: f64, c: f64 },
|
|
|
|
CassiniAstroid { ca: f64, cc: f64, aa: f64 },
|
|
CassiniAstroidTsq { ca: f64, cc: f64, aa: f64 },
|
|
|
|
Ellipse { a: f64, b: f64 },
|
|
|
|
Lemniskate { a: f64 },
|
|
|
|
Spiral { k: u32 },
|
|
|
|
Circle,
|
|
Intersect8,
|
|
Intersect8pp,
|
|
}
|
|
|
|
impl SelectExample {
|
|
pub fn add_offset(&mut self, l: f64) {
|
|
match self {
|
|
Self::AstroidPedal { a } => *a += l,
|
|
Self::CassiniOval { a, c } => {
|
|
*a += l;
|
|
*c += l;
|
|
}
|
|
Self::CassiniAstroid { ca, cc, aa } | Self::CassiniAstroidTsq { ca, cc, aa } => {
|
|
*ca += l;
|
|
*cc += l;
|
|
*aa += l;
|
|
}
|
|
Self::Ellipse { a, b } => {
|
|
*a /= 1.0 + l;
|
|
*b *= 1.0 + l;
|
|
}
|
|
Self::Lemniskate { a } => {
|
|
*a += l;
|
|
}
|
|
Self::Spiral { .. } | Self::Circle | Self::Intersect8 | Self::Intersect8pp => {
|
|
panic!("offsetting not supported for this example")
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn instantiate(self) -> Box<dyn Fn(f64) -> [f64; 2]> {
|
|
match self {
|
|
Self::AstroidPedal { a } => Box::new(move |t: f64| ex::astroid_pedal(t, a)),
|
|
Self::CassiniOval { a, c } => Box::new(ex::cassini_oval(a, c)),
|
|
Self::CassiniAstroid { ca, cc, aa } => Box::new(ex::cassini_astroid(ca, cc, aa)),
|
|
Self::CassiniAstroidTsq { ca, cc, aa } => {
|
|
let x = ex::cassini_astroid(ca, cc, aa);
|
|
Box::new(move |t: f64| x(t * t))
|
|
},
|
|
Self::Ellipse { a, b } => Box::new(ex::ellipse(a, b)),
|
|
Self::Lemniskate { a } => Box::new(move |t: f64| ex::lemniskate(t, a)),
|
|
Self::Spiral { k } => Box::new(ex::spiral(k)),
|
|
Self::Circle => Box::new(ex::circle),
|
|
Self::Intersect8 => Box::new(ex::intersect_eight),
|
|
Self::Intersect8pp => Box::new(ex::intersect_8pp),
|
|
}
|
|
}
|
|
}
|