Implement From<Vec2> for AspectRatio (#12754)

# Objective
Since it is common to store a pair of width and height as `Vec2`, it
would be useful to have an easy way to instantiate `AspectRatio` from
`Vec2`.

## Solution
Add `impl From<Vec2> for AspectRatio`.

---

## Changelog
- Added `impl From<Vec2> for AspectRatio`
This commit is contained in:
mamekoro 2024-03-28 07:32:31 +09:00 committed by GitHub
parent c38e2d037d
commit 6840f95d62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,7 @@
//! Provides a simple aspect ratio struct to help with calculations.
use crate::Vec2;
/// An `AspectRatio` is the ratio of width to height.
pub struct AspectRatio(f32);
@ -17,6 +19,13 @@ impl AspectRatio {
}
}
impl From<Vec2> for AspectRatio {
#[inline]
fn from(value: Vec2) -> Self {
Self::new(value.x, value.y)
}
}
impl From<AspectRatio> for f32 {
#[inline]
fn from(aspect_ratio: AspectRatio) -> Self {