-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d8d78e
commit 4759fde
Showing
6 changed files
with
40 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! Provides a simple aspect ratio struct to help with calculations. | ||
/// An `AspectRatio` is the ratio of width to height. | ||
pub struct AspectRatio(f32); | ||
|
||
impl AspectRatio { | ||
/// Create a new `AspectRatio` from a given `width` and `height`. | ||
#[inline] | ||
pub fn new(width: f32, height: f32) -> Self { | ||
Self(width / height) | ||
} | ||
} | ||
|
||
impl From<(f32, f32)> for AspectRatio { | ||
#[inline] | ||
fn from((width, height): (f32, f32)) -> Self { | ||
Self::new(width, height) | ||
} | ||
} | ||
|
||
impl From<AspectRatio> for f32 { | ||
#[inline] | ||
fn from(aspect_ratio: AspectRatio) -> Self { | ||
aspect_ratio.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters