summaryrefslogtreecommitdiff
path: root/src/eval/ops.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-08 17:08:30 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-09 12:02:35 +0200
commit29eb13ca6214461a4b0deb63d589cd39ad6d41c2 (patch)
treec86797d440cfcc801c87a3c64f479e39f2c068b1 /src/eval/ops.rs
parent712c00ecb72b67da2c0788e5d3eb4dcc6366b2a7 (diff)
Sum color and length into stroke
Diffstat (limited to 'src/eval/ops.rs')
-rw-r--r--src/eval/ops.rs41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/eval/ops.rs b/src/eval/ops.rs
index 89802949..4796e042 100644
--- a/src/eval/ops.rs
+++ b/src/eval/ops.rs
@@ -1,6 +1,6 @@
use std::cmp::Ordering;
-use super::{Dynamic, RawAlign, StrExt, Value};
+use super::{Dynamic, RawAlign, RawStroke, Smart, StrExt, Value};
use crate::diag::StrResult;
use crate::geom::{Numeric, Spec, SpecAxis};
use Value::*;
@@ -90,25 +90,32 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
(Array(a), Array(b)) => Array(a + b),
(Dict(a), Dict(b)) => Dict(a + b),
- (a, b) => {
- if let (Dyn(a), Dyn(b)) = (&a, &b) {
- // 1D alignments can be summed into 2D alignments.
- if let (Some(&a), Some(&b)) =
- (a.downcast::<RawAlign>(), b.downcast::<RawAlign>())
- {
- return if a.axis() != b.axis() {
- Ok(Dyn(Dynamic::new(match a.axis() {
- SpecAxis::Horizontal => Spec { x: a, y: b },
- SpecAxis::Vertical => Spec { x: b, y: a },
- })))
- } else {
- Err(format!("cannot add two {:?} alignments", a.axis()))
- };
+ (Color(color), Length(thickness)) | (Length(thickness), Color(color)) => {
+ Dyn(Dynamic::new(RawStroke {
+ paint: Smart::Custom(color.into()),
+ thickness: Smart::Custom(thickness),
+ }))
+ }
+
+ (Dyn(a), Dyn(b)) => {
+ // 1D alignments can be summed into 2D alignments.
+ if let (Some(&a), Some(&b)) =
+ (a.downcast::<RawAlign>(), b.downcast::<RawAlign>())
+ {
+ if a.axis() != b.axis() {
+ Dyn(Dynamic::new(match a.axis() {
+ SpecAxis::Horizontal => Spec { x: a, y: b },
+ SpecAxis::Vertical => Spec { x: b, y: a },
+ }))
+ } else {
+ return Err(format!("cannot add two {:?} alignments", a.axis()));
}
+ } else {
+ mismatch!("cannot add {} and {}", a, b);
}
-
- mismatch!("cannot add {} and {}", a, b);
}
+
+ (a, b) => mismatch!("cannot add {} and {}", a, b),
})
}