svg-path-bbox 0.0.1

SVG paths bounding box calculator in Rust
Documentation
use derive_more::{Add, AddAssign};
use strum::EnumDiscriminants;

#[derive(Clone, Debug, PartialEq)]
pub enum AbsRel {
    Absolute,
    Relative,
}

#[derive(Add, AddAssign, Clone, Debug, PartialEq)]
pub struct Point {
    pub x: f64,
    pub y: f64,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Cubic {
    pub ctrl1: Point,
    pub ctrl2: Point,
    pub to: Point,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Bezier2 {
    pub ctrl1: Point,
    pub to: Point,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Arc {
    pub radii: Point,
    pub x_axis_rotation: f64,
    pub large_arc: bool,
    pub sweep: bool,
    pub to: Point,
}

// see: https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorials/SVG_from_scratch/Paths
// EnumDiscriminants use to generate
#[derive(Clone, Debug, PartialEq, EnumDiscriminants)]
pub enum PathCommandKind {
    // Line Command

    // M x y (or) m dx dy
    MoveTo(Vec<Point>),
    // L x y (or) l dx dy
    LineTo(Vec<Point>),
    // H x (or) h dx
    HorizontalLineTo(Vec<f64>),
    // V y (or) v dy
    VerticalLineTo(Vec<f64>),
    // Z (or) z
    ClosePath,

    // Curve Command

    // C x1 y1, x2 y2,x y (or) c dx1 dy1, dx2 dy2, dx dy
    CurveTo(Vec<Cubic>),
    // S x2 y2, x y (or) s dx2 dy2, dx dy
    SmoothCurveTo(Vec<Bezier2>),
    // Q x1 y1, x y (or) Q dx1 dy1, dx dy
    QuadraticCurveTo(Vec<Bezier2>),
    // T x y (or) t dx dy
    SmoothQuadraticCurveTo(Vec<Point>),
    // A rx ry x-axis-rotation large-arc-flag sweep-flag x y
    // a rx ry x-axis-rotation large-arc-flag sweep-flag dx dy
    EllipticalArcTo(Vec<Arc>),
}

pub type PathCommand = (AbsRel, PathCommandKind);

pub type PathCommands = Vec<PathCommand>;

pub struct BBox {
    pub min_x: f64,
    pub max_x: f64,
    pub min_y: f64,
    pub max_y: f64,
}