Skip to main content

dioxuscut_paths/
types.rs

1//! SVG path types and data structures.
2
3use serde::{Deserialize, Serialize};
4
5/// 2D point coordinate.
6#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7pub struct Point {
8    pub x: f64,
9    pub y: f64,
10}
11
12impl Point {
13    pub fn new(x: f64, y: f64) -> Self {
14        Self { x, y }
15    }
16}
17
18/// Represents an individual SVG path command instruction.
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
20pub enum Instruction {
21    /// `M x y` or `m x y`
22    MoveTo { x: f64, y: f64 },
23    /// `L x y` or `l x y`
24    LineTo { x: f64, y: f64 },
25    /// `C x1 y1 x2 y2 x y` or `c x1 y1 x2 y2 x y` (Cubic Bezier)
26    CubicCurveTo {
27        x1: f64,
28        y1: f64,
29        x2: f64,
30        y2: f64,
31        x: f64,
32        y: f64,
33    },
34    /// `Q x1 y1 x y` or `q x1 y1 x y` (Quadratic Bezier)
35    QuadCurveTo { x1: f64, y1: f64, x: f64, y: f64 },
36    /// `Z` or `z`
37    ClosePath,
38}
39
40/// Calculated SVG stroke properties for line drawing animation.
41#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
42pub struct EvolvedPath {
43    /// `stroke-dasharray` CSS property value.
44    pub stroke_dasharray: String,
45    /// `stroke-dashoffset` CSS property value.
46    pub stroke_dashoffset: f64,
47}