diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-06-06 21:13:59 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-06-06 22:06:16 +0200 |
| commit | fd417da04f7ca4b995de7f6510abafd3e9c31307 (patch) | |
| tree | 3675529c75ca7363701ac8ea306de2cc1d3cbcb3 /library/src/visualize/path.rs | |
| parent | 168bdf35bd773e67343c965cb473492cc5cae9e7 (diff) | |
Improve value casting infrastructure
Diffstat (limited to 'library/src/visualize/path.rs')
| -rw-r--r-- | library/src/visualize/path.rs | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/library/src/visualize/path.rs b/library/src/visualize/path.rs index c9b596c7..641095c5 100644 --- a/library/src/visualize/path.rs +++ b/library/src/visualize/path.rs @@ -1,6 +1,9 @@ -use self::PathVertex::{AllControlPoints, MirroredControlPoint, Vertex}; -use crate::prelude::*; use kurbo::{CubicBez, ParamCurveExtrema}; +use typst::eval::Reflect; + +use crate::prelude::*; + +use PathVertex::{AllControlPoints, MirroredControlPoint, Vertex}; /// A path through a list of points, connected by Bezier curves. /// @@ -179,8 +182,13 @@ impl PathVertex { } } -cast_from_value! { +cast! { PathVertex, + self => match self { + Vertex(x) => x.into_value(), + MirroredControlPoint(x, c) => array![x, c].into_value(), + AllControlPoints(x, c1, c2) => array![x, c1, c2].into_value(), + }, array: Array => { let mut iter = array.into_iter(); match (iter.next(), iter.next(), iter.next(), iter.next()) { @@ -188,7 +196,7 @@ cast_from_value! { Vertex(a.cast()?) }, (Some(a), Some(b), None, None) => { - if Axes::<Rel<Length>>::is(&a) { + if Axes::<Rel<Length>>::castable(&a) { MirroredControlPoint(a.cast()?, b.cast()?) } else { Vertex(Axes::new(a.cast()?, b.cast()?)) @@ -201,19 +209,3 @@ cast_from_value! { } }, } - -cast_to_value! { - v: PathVertex => { - match v { - PathVertex::Vertex(x) => { - Value::from(x) - }, - PathVertex::MirroredControlPoint(x, c) => { - Value::Array(array![x, c]) - }, - PathVertex::AllControlPoints(x, c1, c2) => { - Value::Array(array![x, c1, c2]) - }, - } - } -} |
