diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-06-15 16:34:41 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-06-15 16:34:41 +0200 |
| commit | e2cdda67dc0e16b9a482aa3a4bfd5991db06d143 (patch) | |
| tree | 7a3ee517b7417c08888eac105ca1431b9d3817cf /src/geom/size.rs | |
| parent | a61ee46ed2d39d7b7b0c14e6c36d224e03532bac (diff) | |
Refactor grid row layout
Diffstat (limited to 'src/geom/size.rs')
| -rw-r--r-- | src/geom/size.rs | 7 |
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 { |
