diff options
Diffstat (limited to 'library/src/visualize')
| -rw-r--r-- | library/src/visualize/mod.rs | 18 | ||||
| -rw-r--r-- | library/src/visualize/path.rs | 32 |
2 files changed, 30 insertions, 20 deletions
diff --git a/library/src/visualize/mod.rs b/library/src/visualize/mod.rs index 3adf4e77..ea873f44 100644 --- a/library/src/visualize/mod.rs +++ b/library/src/visualize/mod.rs @@ -24,4 +24,22 @@ pub(super) fn define(global: &mut Scope) { global.define("circle", CircleElem::func()); global.define("polygon", PolygonElem::func()); global.define("path", PathElem::func()); + global.define("black", Color::BLACK); + global.define("gray", Color::GRAY); + global.define("silver", Color::SILVER); + global.define("white", Color::WHITE); + global.define("navy", Color::NAVY); + global.define("blue", Color::BLUE); + global.define("aqua", Color::AQUA); + global.define("teal", Color::TEAL); + global.define("eastern", Color::EASTERN); + global.define("purple", Color::PURPLE); + global.define("fuchsia", Color::FUCHSIA); + global.define("maroon", Color::MAROON); + global.define("red", Color::RED); + global.define("orange", Color::ORANGE); + global.define("yellow", Color::YELLOW); + global.define("olive", Color::OLIVE); + global.define("green", Color::GREEN); + global.define("lime", Color::LIME); } 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]) - }, - } - } -} |
