summaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/content.rs2
-rw-r--r--src/eval/layout.rs10
-rw-r--r--src/eval/mod.rs6
-rw-r--r--src/eval/ops.rs102
-rw-r--r--src/eval/styles.rs2
-rw-r--r--src/eval/value.rs36
6 files changed, 79 insertions, 79 deletions
diff --git a/src/eval/content.rs b/src/eval/content.rs
index 01b43473..3c1fb310 100644
--- a/src/eval/content.rs
+++ b/src/eval/content.rs
@@ -456,7 +456,7 @@ impl<'a> Builder<'a> {
})
.unwrap_or_default()
{
- par.push_front(ParChild::Spacing(Spacing::Linear(indent)))
+ par.push_front(ParChild::Spacing(Spacing::Relative(indent)))
}
let node = ParNode(par).pack();
diff --git a/src/eval/layout.rs b/src/eval/layout.rs
index aecc7ef9..f541694c 100644
--- a/src/eval/layout.rs
+++ b/src/eval/layout.rs
@@ -8,7 +8,7 @@ use std::sync::Arc;
use super::{Barrier, StyleChain};
use crate::diag::TypResult;
use crate::frame::{Element, Frame, Geometry, Shape, Stroke};
-use crate::geom::{Align, Length, Linear, Paint, Point, Sides, Size, Spec, Transform};
+use crate::geom::{Align, Length, Paint, Point, Relative, Sides, Size, Spec, Transform};
use crate::library::graphics::MoveNode;
use crate::library::layout::{AlignNode, PadNode};
use crate::util::Prehashed;
@@ -161,7 +161,7 @@ impl LayoutNode {
}
/// Force a size for this node.
- pub fn sized(self, sizing: Spec<Option<Linear>>) -> Self {
+ pub fn sized(self, sizing: Spec<Option<Relative>>) -> Self {
if sizing.any(Option::is_some) {
SizedNode { sizing, child: self }.pack()
} else {
@@ -189,7 +189,7 @@ impl LayoutNode {
}
/// Pad this node at the sides.
- pub fn padded(self, padding: Sides<Linear>) -> Self {
+ pub fn padded(self, padding: Sides<Relative>) -> Self {
if !padding.left.is_zero()
|| !padding.top.is_zero()
|| !padding.right.is_zero()
@@ -292,7 +292,7 @@ impl Layout for EmptyNode {
#[derive(Debug, Hash)]
struct SizedNode {
/// How to size the node horizontally and vertically.
- sizing: Spec<Option<Linear>>,
+ sizing: Spec<Option<Relative>>,
/// The node to be sized.
child: LayoutNode,
}
@@ -314,7 +314,7 @@ impl Layout for SizedNode {
.unwrap_or(regions.first);
// Select the appropriate base and expansion for the child depending
- // on whether it is automatically or linearly sized.
+ // on whether it is automatically or relatively sized.
let is_auto = self.sizing.map_is_none();
let base = is_auto.select(regions.base, size);
let expand = regions.expand | !is_auto;
diff --git a/src/eval/mod.rs b/src/eval/mod.rs
index 564dca20..e83c8159 100644
--- a/src/eval/mod.rs
+++ b/src/eval/mod.rs
@@ -41,7 +41,7 @@ use parking_lot::{MappedRwLockWriteGuard, RwLockWriteGuard};
use unicode_segmentation::UnicodeSegmentation;
use crate::diag::{At, StrResult, Trace, Tracepoint, TypResult};
-use crate::geom::{Angle, Fractional, Length, Relative};
+use crate::geom::{Angle, Fraction, Length, Ratio};
use crate::library;
use crate::syntax::ast::*;
use crate::syntax::{Span, Spanned};
@@ -245,8 +245,8 @@ impl Eval for Lit {
LitKind::Float(v) => Value::Float(v),
LitKind::Length(v, unit) => Value::Length(Length::with_unit(v, unit)),
LitKind::Angle(v, unit) => Value::Angle(Angle::with_unit(v, unit)),
- LitKind::Percent(v) => Value::Relative(Relative::new(v / 100.0)),
- LitKind::Fractional(v) => Value::Fractional(Fractional::new(v)),
+ LitKind::Percent(v) => Value::Ratio(Ratio::new(v / 100.0)),
+ LitKind::Fractional(v) => Value::Fraction(Fraction::new(v)),
LitKind::Str(ref v) => Value::Str(v.clone()),
})
}
diff --git a/src/eval/ops.rs b/src/eval/ops.rs
index 9b46e8f6..024de433 100644
--- a/src/eval/ops.rs
+++ b/src/eval/ops.rs
@@ -34,9 +34,9 @@ pub fn pos(value: Value) -> StrResult<Value> {
Float(v) => Float(v),
Length(v) => Length(v),
Angle(v) => Angle(v),
+ Ratio(v) => Ratio(v),
Relative(v) => Relative(v),
- Linear(v) => Linear(v),
- Fractional(v) => Fractional(v),
+ Fraction(v) => Fraction(v),
v => mismatch!("cannot apply '+' to {}", v),
})
}
@@ -48,9 +48,9 @@ pub fn neg(value: Value) -> StrResult<Value> {
Float(v) => Float(-v),
Length(v) => Length(-v),
Angle(v) => Angle(-v),
+ Ratio(v) => Ratio(-v),
Relative(v) => Relative(-v),
- Linear(v) => Linear(-v),
- Fractional(v) => Fractional(-v),
+ Fraction(v) => Fraction(-v),
v => mismatch!("cannot apply '-' to {}", v),
})
}
@@ -66,18 +66,18 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult<Value> {
(Angle(a), Angle(b)) => Angle(a + b),
(Length(a), Length(b)) => Length(a + b),
- (Length(a), Relative(b)) => Linear(a + b),
- (Length(a), Linear(b)) => Linear(a + b),
+ (Length(a), Ratio(b)) => Relative(a + b),
+ (Length(a), Relative(b)) => Relative(a + b),
- (Relative(a), Length(b)) => Linear(a + b),
- (Relative(a), Relative(b)) => Relative(a + b),
- (Relative(a), Linear(b)) => Linear(a + b),
+ (Ratio(a), Length(b)) => Relative(a + b),
+ (Ratio(a), Ratio(b)) => Ratio(a + b),
+ (Ratio(a), Relative(b)) => Relative(a + b),
- (Linear(a), Length(b)) => Linear(a + b),
- (Linear(a), Relative(b)) => Linear(a + b),
- (Linear(a), Linear(b)) => Linear(a + b),
+ (Relative(a), Length(b)) => Relative(a + b),
+ (Relative(a), Ratio(b)) => Relative(a + b),
+ (Relative(a), Relative(b)) => Relative(a + b),
- (Fractional(a), Fractional(b)) => Fractional(a + b),
+ (Fraction(a), Fraction(b)) => Fraction(a + b),
(Str(a), Str(b)) => Str(a + b),
@@ -123,18 +123,18 @@ pub fn sub(lhs: Value, rhs: Value) -> StrResult<Value> {
(Angle(a), Angle(b)) => Angle(a - b),
(Length(a), Length(b)) => Length(a - b),
- (Length(a), Relative(b)) => Linear(a - b),
- (Length(a), Linear(b)) => Linear(a - b),
+ (Length(a), Ratio(b)) => Relative(a - b),
+ (Length(a), Relative(b)) => Relative(a - b),
- (Relative(a), Length(b)) => Linear(a - b),
- (Relative(a), Relative(b)) => Relative(a - b),
- (Relative(a), Linear(b)) => Linear(a - b),
+ (Ratio(a), Length(b)) => Relative(a - b),
+ (Ratio(a), Ratio(b)) => Ratio(a - b),
+ (Ratio(a), Relative(b)) => Relative(a - b),
- (Linear(a), Length(b)) => Linear(a - b),
- (Linear(a), Relative(b)) => Linear(a - b),
- (Linear(a), Linear(b)) => Linear(a - b),
+ (Relative(a), Length(b)) => Relative(a - b),
+ (Relative(a), Ratio(b)) => Relative(a - b),
+ (Relative(a), Relative(b)) => Relative(a - b),
- (Fractional(a), Fractional(b)) => Fractional(a - b),
+ (Fraction(a), Fraction(b)) => Fraction(a - b),
(a, b) => mismatch!("cannot subtract {1} from {0}", a, b),
})
@@ -158,20 +158,20 @@ pub fn mul(lhs: Value, rhs: Value) -> StrResult<Value> {
(Int(a), Angle(b)) => Angle(a as f64 * b),
(Float(a), Angle(b)) => Angle(a * b),
+ (Ratio(a), Int(b)) => Ratio(a * b as f64),
+ (Ratio(a), Float(b)) => Ratio(a * b),
+ (Float(a), Ratio(b)) => Ratio(a * b),
+ (Int(a), Ratio(b)) => Ratio(a as f64 * b),
+
(Relative(a), Int(b)) => Relative(a * b as f64),
(Relative(a), Float(b)) => Relative(a * b),
- (Float(a), Relative(b)) => Relative(a * b),
(Int(a), Relative(b)) => Relative(a as f64 * b),
+ (Float(a), Relative(b)) => Relative(a * b),
- (Linear(a), Int(b)) => Linear(a * b as f64),
- (Linear(a), Float(b)) => Linear(a * b),
- (Int(a), Linear(b)) => Linear(a as f64 * b),
- (Float(a), Linear(b)) => Linear(a * b),
-
- (Float(a), Fractional(b)) => Fractional(a * b),
- (Fractional(a), Int(b)) => Fractional(a * b as f64),
- (Fractional(a), Float(b)) => Fractional(a * b),
- (Int(a), Fractional(b)) => Fractional(a as f64 * b),
+ (Float(a), Fraction(b)) => Fraction(a * b),
+ (Fraction(a), Int(b)) => Fraction(a * b as f64),
+ (Fraction(a), Float(b)) => Fraction(a * b),
+ (Int(a), Fraction(b)) => Fraction(a as f64 * b),
(Str(a), Int(b)) => Str(StrExt::repeat(&a, b)?),
(Int(a), Str(b)) => Str(StrExt::repeat(&b, a)?),
@@ -200,16 +200,16 @@ pub fn div(lhs: Value, rhs: Value) -> StrResult<Value> {
(Angle(a), Float(b)) => Angle(a / b),
(Angle(a), Angle(b)) => Float(a / b),
+ (Ratio(a), Int(b)) => Ratio(a / b as f64),
+ (Ratio(a), Float(b)) => Ratio(a / b),
+ (Ratio(a), Ratio(b)) => Float(a / b),
+
(Relative(a), Int(b)) => Relative(a / b as f64),
(Relative(a), Float(b)) => Relative(a / b),
- (Relative(a), Relative(b)) => Float(a / b),
-
- (Linear(a), Int(b)) => Linear(a / b as f64),
- (Linear(a), Float(b)) => Linear(a / b),
- (Fractional(a), Int(b)) => Fractional(a / b as f64),
- (Fractional(a), Float(b)) => Fractional(a / b),
- (Fractional(a), Fractional(b)) => Float(a / b),
+ (Fraction(a), Int(b)) => Fraction(a / b as f64),
+ (Fraction(a), Float(b)) => Fraction(a / b),
+ (Fraction(a), Fraction(b)) => Float(a / b),
(a, b) => mismatch!("cannot divide {} by {}", a, b),
})
@@ -278,9 +278,9 @@ pub fn equal(lhs: &Value, rhs: &Value) -> bool {
(Float(a), Float(b)) => a == b,
(Length(a), Length(b)) => a == b,
(Angle(a), Angle(b)) => a == b,
+ (Ratio(a), Ratio(b)) => a == b,
(Relative(a), Relative(b)) => a == b,
- (Linear(a), Linear(b)) => a == b,
- (Fractional(a), Fractional(b)) => a == b,
+ (Fraction(a), Fraction(b)) => a == b,
(Color(a), Color(b)) => a == b,
(Str(a), Str(b)) => a == b,
(Content(a), Content(b)) => a == b,
@@ -292,10 +292,10 @@ pub fn equal(lhs: &Value, rhs: &Value) -> bool {
// Some technically different things should compare equal.
(&Int(a), &Float(b)) => a as f64 == b,
(&Float(a), &Int(b)) => a == b as f64,
- (&Length(a), &Linear(b)) => a == b.abs && b.rel.is_zero(),
- (&Relative(a), &Linear(b)) => a == b.rel && b.abs.is_zero(),
- (&Linear(a), &Length(b)) => a.abs == b && a.rel.is_zero(),
- (&Linear(a), &Relative(b)) => a.rel == b && a.abs.is_zero(),
+ (&Length(a), &Relative(b)) => a == b.abs && b.rel.is_zero(),
+ (&Ratio(a), &Relative(b)) => a == b.rel && b.abs.is_zero(),
+ (&Relative(a), &Length(b)) => a.abs == b && a.rel.is_zero(),
+ (&Relative(a), &Ratio(b)) => a.rel == b && a.abs.is_zero(),
_ => false,
}
@@ -309,17 +309,17 @@ pub fn compare(lhs: &Value, rhs: &Value) -> Option<Ordering> {
(Float(a), Float(b)) => a.partial_cmp(b),
(Angle(a), Angle(b)) => a.partial_cmp(b),
(Length(a), Length(b)) => a.partial_cmp(b),
- (Relative(a), Relative(b)) => a.partial_cmp(b),
- (Fractional(a), Fractional(b)) => a.partial_cmp(b),
+ (Ratio(a), Ratio(b)) => a.partial_cmp(b),
+ (Fraction(a), Fraction(b)) => a.partial_cmp(b),
(Str(a), Str(b)) => a.partial_cmp(b),
// Some technically different things should be comparable.
(&Int(a), &Float(b)) => (a as f64).partial_cmp(&b),
(&Float(a), &Int(b)) => a.partial_cmp(&(b as f64)),
- (&Length(a), &Linear(b)) if b.rel.is_zero() => a.partial_cmp(&b.abs),
- (&Relative(a), &Linear(b)) if b.abs.is_zero() => a.partial_cmp(&b.rel),
- (&Linear(a), &Length(b)) if a.rel.is_zero() => a.abs.partial_cmp(&b),
- (&Linear(a), &Relative(b)) if a.abs.is_zero() => a.rel.partial_cmp(&b),
+ (&Length(a), &Relative(b)) if b.rel.is_zero() => a.partial_cmp(&b.abs),
+ (&Ratio(a), &Relative(b)) if b.abs.is_zero() => a.partial_cmp(&b.rel),
+ (&Relative(a), &Length(b)) if a.rel.is_zero() => a.abs.partial_cmp(&b),
+ (&Relative(a), &Ratio(b)) if a.abs.is_zero() => a.rel.partial_cmp(&b),
_ => Option::None,
}
diff --git a/src/eval/styles.rs b/src/eval/styles.rs
index 8bd21612..b7f1889c 100644
--- a/src/eval/styles.rs
+++ b/src/eval/styles.rs
@@ -270,7 +270,7 @@ pub trait Key<'a>: 'static {
/// from a style chain. For example, this is [`bool`] for the
/// [`STRONG`](TextNode::STRONG) property. For non-copy, non-folding
/// properties this is a reference type.
- type Output: 'a;
+ type Output;
/// The name of the property, used for debug printing.
const NAME: &'static str;
diff --git a/src/eval/value.rs b/src/eval/value.rs
index c61c9561..774ae0b6 100644
--- a/src/eval/value.rs
+++ b/src/eval/value.rs
@@ -6,7 +6,7 @@ use std::sync::Arc;
use super::{ops, Args, Array, Content, Context, Dict, Func, Layout, StrExt};
use crate::diag::{with_alternative, At, StrResult, TypResult};
-use crate::geom::{Angle, Color, Fractional, Length, Linear, Relative, RgbaColor};
+use crate::geom::{Angle, Color, Fraction, Length, Ratio, Relative, RgbaColor};
use crate::library::text::RawNode;
use crate::syntax::{Span, Spanned};
use crate::util::EcoString;
@@ -28,12 +28,12 @@ pub enum Value {
Length(Length),
/// An angle: `1.5rad`, `90deg`.
Angle(Angle),
- /// A relative value: `50%`.
+ /// A ratio: `50%`.
+ Ratio(Ratio),
+ /// A relative length, combination of a ratio and a length: `20% + 5cm`.
Relative(Relative),
- /// A combination of an absolute length and a relative value: `20% + 5cm`.
- Linear(Linear),
- /// A fractional value: `1fr`.
- Fractional(Fractional),
+ /// A fraction: `1fr`.
+ Fraction(Fraction),
/// A color value: `#f79143ff`.
Color(Color),
/// A string: `"string"`.
@@ -79,9 +79,9 @@ impl Value {
Self::Float(_) => f64::TYPE_NAME,
Self::Length(_) => Length::TYPE_NAME,
Self::Angle(_) => Angle::TYPE_NAME,
+ Self::Ratio(_) => Ratio::TYPE_NAME,
Self::Relative(_) => Relative::TYPE_NAME,
- Self::Linear(_) => Linear::TYPE_NAME,
- Self::Fractional(_) => Fractional::TYPE_NAME,
+ Self::Fraction(_) => Fraction::TYPE_NAME,
Self::Color(_) => Color::TYPE_NAME,
Self::Str(_) => EcoString::TYPE_NAME,
Self::Content(_) => Content::TYPE_NAME,
@@ -255,9 +255,9 @@ impl Debug for Value {
Self::Float(v) => Debug::fmt(v, f),
Self::Length(v) => Debug::fmt(v, f),
Self::Angle(v) => Debug::fmt(v, f),
+ Self::Ratio(v) => Debug::fmt(v, f),
Self::Relative(v) => Debug::fmt(v, f),
- Self::Linear(v) => Debug::fmt(v, f),
- Self::Fractional(v) => Debug::fmt(v, f),
+ Self::Fraction(v) => Debug::fmt(v, f),
Self::Color(v) => Debug::fmt(v, f),
Self::Str(v) => Debug::fmt(v, f),
Self::Content(_) => f.pad("<content>"),
@@ -293,9 +293,9 @@ impl Hash for Value {
Self::Float(v) => v.to_bits().hash(state),
Self::Length(v) => v.hash(state),
Self::Angle(v) => v.hash(state),
+ Self::Ratio(v) => v.hash(state),
Self::Relative(v) => v.hash(state),
- Self::Linear(v) => v.hash(state),
- Self::Fractional(v) => v.hash(state),
+ Self::Fraction(v) => v.hash(state),
Self::Color(v) => v.hash(state),
Self::Str(v) => v.hash(state),
Self::Content(v) => v.hash(state),
@@ -548,9 +548,9 @@ primitive! { i64: "integer", Int }
primitive! { f64: "float", Float, Int(v) => v as f64 }
primitive! { Length: "length", Length }
primitive! { Angle: "angle", Angle }
-primitive! { Relative: "relative", Relative }
-primitive! { Linear: "relative length", Linear, Length(v) => v.into(), Relative(v) => v.into() }
-primitive! { Fractional: "fractional length", Fractional }
+primitive! { Ratio: "ratio", Ratio }
+primitive! { Relative: "relative length", Relative, Length(v) => v.into(), Ratio(v) => v.into() }
+primitive! { Fraction: "fraction", Fraction }
primitive! { Color: "color", Color }
primitive! { EcoString: "string", Str }
primitive! { Content: "content", Content, None => Content::new() }
@@ -673,9 +673,9 @@ mod tests {
test(3.14, "3.14");
test(Length::pt(5.5), "5.5pt");
test(Angle::deg(90.0), "90deg");
- test(Relative::one() / 2.0, "50%");
- test(Relative::new(0.3) + Length::cm(2.0), "30% + 56.69pt");
- test(Fractional::one() * 7.55, "7.55fr");
+ test(Ratio::one() / 2.0, "50%");
+ test(Ratio::new(0.3) + Length::cm(2.0), "30% + 56.69pt");
+ test(Fraction::one() * 7.55, "7.55fr");
test(Color::Rgba(RgbaColor::new(1, 1, 1, 0xff)), "#010101");
// Collections.