summaryrefslogtreecommitdiff
path: root/src/geom/size.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/geom/size.rs')
-rw-r--r--src/geom/size.rs7
1 files changed, 7 insertions, 0 deletions
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<SpecAxis> for Size {