From 8680fcd4903b451909a5932e8b948a68c9aacb16 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 13 Oct 2020 13:24:33 +0200 Subject: [PATCH] =?UTF-8?q?Rename=20geometric=20eval=20and=20apply=20to=20?= =?UTF-8?q?resolve=20=E2=9C=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eval/mod.rs | 8 ++++---- src/eval/state.rs | 2 +- src/geom/align.rs | 2 +- src/geom/linear.rs | 7 +++---- src/geom/relative.rs | 6 +++--- src/geom/sides.rs | 12 ++++++------ src/layout/fixed.rs | 4 ++-- src/layout/pad.rs | 4 ++-- src/layout/par.rs | 4 ++-- src/layout/stack.rs | 4 ++-- src/library/spacing.rs | 2 +- 11 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 71a097495..e1fa8c1ae 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -173,7 +173,7 @@ impl EvalContext { self.start_group(ParGroup { dirs: self.state.dirs, aligns: self.state.aligns, - line_spacing: self.state.par.line_spacing.eval(em), + line_spacing: self.state.par.line_spacing.resolve(em), }); } @@ -299,7 +299,7 @@ impl Eval for SynNode { SynNode::Space => { let em = ctx.state.font.font_size(); ctx.push(Spacing { - amount: ctx.state.par.word_spacing.eval(em), + amount: ctx.state.par.word_spacing.resolve(em), softness: Softness::Soft, }); } @@ -318,7 +318,7 @@ impl Eval for SynNode { ctx.end_par_group(); let em = ctx.state.font.font_size(); ctx.push(Spacing { - amount: ctx.state.par.par_spacing.eval(em), + amount: ctx.state.par.par_spacing.resolve(em), softness: Softness::Soft, }); ctx.start_par_group(); @@ -358,7 +358,7 @@ impl Eval for NodeRaw { families.flatten(); let em = ctx.state.font.font_size(); - let line_spacing = ctx.state.par.line_spacing.eval(em); + let line_spacing = ctx.state.par.line_spacing.resolve(em); let mut children = vec![]; for line in &self.lines { diff --git a/src/eval/state.rs b/src/eval/state.rs index 9c5476d91..521e8c124 100644 --- a/src/eval/state.rs +++ b/src/eval/state.rs @@ -121,7 +121,7 @@ pub struct FontState { impl FontState { /// The absolute font size. pub fn font_size(&self) -> Length { - self.scale.eval(self.size) + self.scale.resolve(self.size) } } diff --git a/src/geom/align.rs b/src/geom/align.rs index 1030a133c..422624d84 100644 --- a/src/geom/align.rs +++ b/src/geom/align.rs @@ -13,7 +13,7 @@ pub enum Align { impl Align { /// Returns the position of this alignment in the given range. - pub fn apply(self, range: Range) -> Length { + pub fn resolve(self, range: Range) -> Length { match self { Self::Start => range.start, Self::Center => (range.start + range.end) / 2.0, diff --git a/src/geom/linear.rs b/src/geom/linear.rs index d9860d43b..5638517bf 100644 --- a/src/geom/linear.rs +++ b/src/geom/linear.rs @@ -21,10 +21,9 @@ impl Linear { Self { rel, abs } } - /// Evaluate the linear length with `one` being `100%` for the relative - /// part. - pub fn eval(self, one: Length) -> Length { - self.rel.eval(one) + self.abs + /// Resolve this relative to the given `length`. + pub fn resolve(self, length: Length) -> Length { + self.rel.resolve(length) + self.abs } /// Whether this linear's relative part is zero. diff --git a/src/geom/relative.rs b/src/geom/relative.rs index 037c83dc9..d87cfac73 100644 --- a/src/geom/relative.rs +++ b/src/geom/relative.rs @@ -26,9 +26,9 @@ impl Relative { self.0 } - /// Evaluate the relative length with `one` being `100%`. - pub fn eval(self, one: Length) -> Length { - self.get() * one + /// Resolve this relative to the given `length`. + pub fn resolve(self, length: Length) -> Length { + self.get() * length } } diff --git a/src/geom/sides.rs b/src/geom/sides.rs index 770fad58b..39487ff75 100644 --- a/src/geom/sides.rs +++ b/src/geom/sides.rs @@ -34,13 +34,13 @@ impl Sides { } impl Sides { - /// Evaluate the linear values in this container. - pub fn eval(self, size: Size) -> Sides { + /// Resolve the linear margins relative to the given `size`. + pub fn resolve(self, size: Size) -> Sides { Sides { - left: self.left.eval(size.width), - top: self.top.eval(size.height), - right: self.right.eval(size.width), - bottom: self.bottom.eval(size.height), + left: self.left.resolve(size.width), + top: self.top.resolve(size.height), + right: self.right.resolve(size.width), + bottom: self.bottom.resolve(size.height), } } } diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs index 8a42a9d34..d0daa2ca0 100644 --- a/src/layout/fixed.rs +++ b/src/layout/fixed.rs @@ -16,8 +16,8 @@ impl Layout for Fixed { fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted { let Area { rem, full } = areas.current; let size = Size::new( - self.width.map(|w| w.eval(full.width)).unwrap_or(rem.width), - self.height.map(|h| h.eval(full.height)).unwrap_or(rem.height), + self.width.map(|w| w.resolve(full.width)).unwrap_or(rem.width), + self.height.map(|h| h.resolve(full.height)).unwrap_or(rem.height), ); let areas = Areas::once(size); diff --git a/src/layout/pad.rs b/src/layout/pad.rs index f574e8232..09cf016b0 100644 --- a/src/layout/pad.rs +++ b/src/layout/pad.rs @@ -31,7 +31,7 @@ impl Layout for Pad { /// Shrink all areas by the padding. fn shrink_areas(areas: &Areas, padding: Sides) -> Areas { - let shrink = |size| size - padding.eval(size).size(); + let shrink = |size| size - padding.resolve(size).size(); Areas { current: Area { rem: shrink(areas.current.rem), @@ -44,7 +44,7 @@ fn shrink_areas(areas: &Areas, padding: Sides) -> Areas { /// Enlarge the box and move all elements inwards. fn pad_layout(layout: &mut BoxLayout, padding: Sides) { - let padding = padding.eval(layout.size); + let padding = padding.resolve(layout.size); let origin = Point::new(padding.left, padding.top); layout.size += padding.size(); diff --git a/src/layout/par.rs b/src/layout/par.rs index b1bba7902..bd38442db 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -125,7 +125,7 @@ impl<'a> ParLayouter<'a> { let child_cross_size = layout.size.get(self.cross); // Position along the cross axis. - let cross = align.apply(if self.dirs.cross.is_positive() { + let cross = align.resolve(if self.dirs.cross.is_positive() { let after_with_self = self.run_size.cross - before; before .. full_size.cross - after_with_self } else { @@ -164,7 +164,7 @@ impl<'a> ParLayouter<'a> { }; // Align along the cross axis. - let cross = cross_align.apply(if self.dirs.cross.is_positive() { + let cross = cross_align.resolve(if self.dirs.cross.is_positive() { Length::ZERO .. size.cross - child_size.cross } else { size.cross - child_size.cross .. Length::ZERO diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 13c585e34..7e1bb2c51 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -117,7 +117,7 @@ impl<'a> StackLayouter<'a> { let child_size = layout.size.switch(self.dirs); // Align along the main axis. - let main = aligns.main.apply(if self.dirs.main.is_positive() { + let main = aligns.main.resolve(if self.dirs.main.is_positive() { let after_with_self = self.used.main - before; before .. full_size.main - after_with_self } else { @@ -127,7 +127,7 @@ impl<'a> StackLayouter<'a> { }); // Align along the cross axis. - let cross = aligns.cross.apply(if self.dirs.cross.is_positive() { + let cross = aligns.cross.resolve(if self.dirs.cross.is_positive() { Length::ZERO .. full_size.cross - child_size.cross } else { full_size.cross - child_size.cross .. Length::ZERO diff --git a/src/library/spacing.rs b/src/library/spacing.rs index 765153810..449977398 100644 --- a/src/library/spacing.rs +++ b/src/library/spacing.rs @@ -24,7 +24,7 @@ fn spacing(mut args: Args, ctx: &mut EvalContext, axis: SpecAxis) -> Value { args.done(ctx); if let Some(linear) = spacing { - let amount = linear.eval(ctx.state.font.font_size()); + let amount = linear.resolve(ctx.state.font.font_size()); let spacing = Spacing { amount, softness: Softness::Hard }; if ctx.state.dirs.main.axis() == axis { ctx.end_par_group();