From e2cdda67dc0e16b9a482aa3a4bfd5991db06d143 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 15 Jun 2021 16:34:41 +0200 Subject: Refactor grid row layout --- src/geom/length.rs | 11 +++++++++++ src/geom/size.rs | 7 +++++++ 2 files changed, 18 insertions(+) (limited to 'src/geom') diff --git a/src/geom/length.rs b/src/geom/length.rs index 21843d3e..ecfe5616 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -18,6 +18,11 @@ impl Length { Self { raw: N64::from(0.0) } } + /// The inifinite length. + pub fn inf() -> Self { + Self { raw: N64::from(f64::INFINITY) } + } + /// Create a length from a number of points. pub fn pt(pt: f64) -> Self { Self::with_unit(pt, LengthUnit::Pt) @@ -203,6 +208,12 @@ impl Sum for Length { } } +impl<'a> Sum<&'a Length> for Length { + fn sum>(iter: I) -> Self { + iter.copied().fold(Length::zero(), Add::add) + } +} + /// Different units of length measurement. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] pub enum LengthUnit { diff --git a/src/geom/size.rs b/src/geom/size.rs index 1c411fb3..4b94d0ae 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -57,6 +57,13 @@ impl Size { SpecAxis::Vertical => Gen::new(self.width, self.height), } } + + /// Find the largest contained size that satisfies the given `aspect` ratio. + pub fn with_aspect(self, aspect: f64) -> Self { + let width = self.width.min(aspect * self.height); + let height = width / aspect; + Size::new(width, height) + } } impl Get for Size { -- cgit v1.2.3