use crate::geom::{Bbox, Point};
#[derive(Debug, Clone, PartialEq)]
pub struct Drawing {
pub shapes: Vec<Shape>,
pub bbox: Bbox,
pub prelude_thick: f64,
pub canvas_margin: CanvasMargin,
pub anims: Vec<Anim>,
pub diagnostics: Vec<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct CanvasMargin {
pub top: f64,
pub right: f64,
pub bottom: f64,
pub left: f64,
}
impl CanvasMargin {
pub fn horizontal(self) -> f64 {
self.left + self.right
}
pub fn vertical(self) -> f64 {
self.top + self.bottom
}
pub fn scale_by(&mut self, factor: f64) {
self.top *= factor;
self.right *= factor;
self.bottom *= factor;
self.left *= factor;
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Anim {
pub shape: usize,
pub effect: String,
pub start: f64,
pub duration: f64,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum Dash {
#[default]
Solid,
Dashed(f64),
Dotted(Option<f64>),
}
#[derive(Debug, Clone, PartialEq)]
pub enum Fill {
Gray(f64),
Color(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Style {
pub stroke: Option<String>,
pub fill: Option<Fill>,
pub fill_open: bool,
pub dash: Dash,
pub thick: Option<f64>,
pub invis: bool,
pub invis_bounds: bool,
pub arrow_ht: f64,
pub arrow_wid: f64,
pub arrow_filled: bool,
}
impl Default for Style {
fn default() -> Self {
Style {
stroke: None,
fill: None,
fill_open: false,
dash: Dash::Solid,
thick: None,
invis: false,
invis_bounds: false,
arrow_ht: 0.1,
arrow_wid: 0.05,
arrow_filled: true,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Arrowheads {
#[default]
None,
Start,
End,
Both,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TextLine {
pub s: String,
pub halign: i8,
pub valign: i8,
pub text_offset: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Shape {
Box {
c: Point,
w: f64,
h: f64,
rad: f64,
style: Style,
text: Vec<TextLine>,
},
Circle {
c: Point,
r: f64,
style: Style,
text: Vec<TextLine>,
},
Ellipse {
c: Point,
w: f64,
h: f64,
style: Style,
text: Vec<TextLine>,
},
Path {
pts: Vec<Point>,
arrows: Arrowheads,
style: Style,
text: Vec<TextLine>,
},
Spline {
pts: Vec<Point>,
tension: Option<f64>,
arrows: Arrowheads,
style: Style,
text: Vec<TextLine>,
},
Arc {
c: Point,
r: f64,
a0: f64,
a1: f64,
cw: bool,
arrows: Arrowheads,
style: Style,
text: Vec<TextLine>,
},
Text {
at: Point,
text: Vec<TextLine>,
bbox: Bbox,
w: f64,
h: f64,
standalone: bool,
},
}