1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
use math::{ Point, Vec2, Radians }; use super::ArcFlags; #[derive(Copy, Clone, Debug, PartialEq)] pub enum SvgEvent { MoveTo(Point), RelativeMoveTo(Vec2), LineTo(Point), RelativeLineTo(Vec2), QuadraticTo(Point, Point), RelativeQuadraticTo(Vec2, Vec2), CubicTo(Point, Point, Point), RelativeCubicTo(Vec2, Vec2, Vec2), ArcTo(Point, Vec2, Radians<f32>, ArcFlags), RelativeArcTo(Vec2, Vec2, Radians<f32>, ArcFlags), HorizontalLineTo(f32), VerticalLineTo(f32), RelativeHorizontalLineTo(f32), RelativeVerticalLineTo(f32), SmoothQuadraticTo(Point), SmoothRelativeQuadraticTo(Vec2), SmoothCubicTo(Point, Point), SmoothRelativeCubicTo(Vec2, Vec2), Close, } #[derive(Copy, Clone, Debug, PartialEq)] pub enum PathEvent { MoveTo(Point), LineTo(Point), QuadraticTo(Point, Point), CubicTo(Point, Point, Point), Close, } #[derive(Copy, Clone, Debug, PartialEq)] pub enum QuadraticPathEvent { MoveTo, LineTo, QuadraticTo(Point, Point), Close, } #[derive(Copy, Clone, Debug, PartialEq)] pub enum FlattenedEvent { MoveTo(Point), LineTo(Point), Close, } impl PathEvent { pub fn to_svg_event(self) -> SvgEvent { return match self { PathEvent::MoveTo(to) => { SvgEvent::MoveTo(to) } PathEvent::LineTo(to) => { SvgEvent::LineTo(to) } PathEvent::QuadraticTo(ctrl, to) => { SvgEvent::QuadraticTo(ctrl, to) } PathEvent::CubicTo(ctrl1, ctrl2, to) => { SvgEvent::CubicTo(ctrl1, ctrl2, to) } PathEvent::Close => { SvgEvent::Close } }; } pub fn destination(self) -> Option<Point> { return match self { PathEvent::MoveTo(to) => Some(to), PathEvent::LineTo(to) => Some(to), PathEvent::QuadraticTo(_, to) => Some(to), PathEvent::CubicTo(_, _, to) => Some(to), PathEvent::Close => None, } } } impl FlattenedEvent { pub fn to_svg_event(self) -> SvgEvent { return match self { FlattenedEvent::MoveTo(to) => { SvgEvent::MoveTo(to) } FlattenedEvent::LineTo(to) => { SvgEvent::LineTo(to) } FlattenedEvent::Close => { SvgEvent::Close } } } pub fn to_path_event(self) -> PathEvent { return match self { FlattenedEvent::MoveTo(to) => { PathEvent::MoveTo(to) } FlattenedEvent::LineTo(to) => { PathEvent::LineTo(to) } FlattenedEvent::Close => { PathEvent::Close } } } }