ratex_types/
path_command.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
6#[serde(tag = "type")]
7pub enum PathCommand {
8 MoveTo { x: f64, y: f64 },
9 LineTo { x: f64, y: f64 },
10 CubicTo { x1: f64, y1: f64, x2: f64, y2: f64, x: f64, y: f64 },
11 QuadTo { x1: f64, y1: f64, x: f64, y: f64 },
12 Close,
13}
14
15#[cfg(test)]
16mod tests {
17 use super::*;
18
19 #[test]
20 fn test_serde_roundtrip() {
21 let cmds = vec![
22 PathCommand::MoveTo { x: 0.0, y: 0.0 },
23 PathCommand::LineTo { x: 10.0, y: 0.0 },
24 PathCommand::CubicTo {
25 x1: 10.0, y1: 5.0,
26 x2: 5.0, y2: 10.0,
27 x: 0.0, y: 10.0,
28 },
29 PathCommand::QuadTo {
30 x1: 5.0, y1: 5.0,
31 x: 0.0, y: 0.0,
32 },
33 PathCommand::Close,
34 ];
35 let json = serde_json::to_string(&cmds).unwrap();
36 let cmds2: Vec<PathCommand> = serde_json::from_str(&json).unwrap();
37 assert_eq!(cmds, cmds2);
38 }
39}