summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorTetragramm <9815373+Tetragramm@users.noreply.github.com>2024-12-08 10:43:25 -0600
committerGitHub <noreply@github.com>2024-12-08 16:43:25 +0000
commitd04cc61eee2b9519e82b7759a929314299cb4a34 (patch)
treeef4f38103339a622d1db804f4cc7396037fb07d9 /crates
parent62567fc91e2d58d5d12457bbeddc5d7950d7c570 (diff)
Add missing functions to the gradient object. (#5528)
Co-authored-by: PgBiel <9021226+PgBiel@users.noreply.github.com> Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-library/src/visualize/gradient.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/crates/typst-library/src/visualize/gradient.rs b/crates/typst-library/src/visualize/gradient.rs
index 2be7e370..e16e5d88 100644
--- a/crates/typst-library/src/visualize/gradient.rs
+++ b/crates/typst-library/src/visualize/gradient.rs
@@ -697,6 +697,8 @@ impl Gradient {
}
/// Returns the angle of this gradient.
+ ///
+ /// Returns `{none}` if the gradient is neither linear nor conic.
#[func]
pub fn angle(&self) -> Option<Angle> {
match self {
@@ -706,6 +708,54 @@ impl Gradient {
}
}
+ /// Returns the center of this gradient.
+ ///
+ /// Returns `{none}` if the gradient is neither radial nor conic.
+ #[func]
+ pub fn center(&self) -> Option<Axes<Ratio>> {
+ match self {
+ Self::Linear(_) => None,
+ Self::Radial(radial) => Some(radial.center),
+ Self::Conic(conic) => Some(conic.center),
+ }
+ }
+
+ /// Returns the radius of this gradient.
+ ///
+ /// Returns `{none}` if the gradient is not radial.
+ #[func]
+ pub fn radius(&self) -> Option<Ratio> {
+ match self {
+ Self::Linear(_) => None,
+ Self::Radial(radial) => Some(radial.radius),
+ Self::Conic(_) => None,
+ }
+ }
+
+ /// Returns the focal-center of this gradient.
+ ///
+ /// Returns `{none}` if the gradient is not radial.
+ #[func]
+ pub fn focal_center(&self) -> Option<Axes<Ratio>> {
+ match self {
+ Self::Linear(_) => None,
+ Self::Radial(radial) => Some(radial.focal_center),
+ Self::Conic(_) => None,
+ }
+ }
+
+ /// Returns the focal-radius of this gradient.
+ ///
+ /// Returns `{none}` if the gradient is not radial.
+ #[func]
+ pub fn focal_radius(&self) -> Option<Ratio> {
+ match self {
+ Self::Linear(_) => None,
+ Self::Radial(radial) => Some(radial.focal_radius),
+ Self::Conic(_) => None,
+ }
+ }
+
/// Sample the gradient at a given position.
///
/// The position is either a position along the gradient (a [ratio] between