Skip to content

Commit

Permalink
Implement From<Vec2> for AspectRatio (#12754)
Browse files Browse the repository at this point in the history
# 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`
  • Loading branch information
mamekoro authored Mar 27, 2024
1 parent c38e2d0 commit 6840f95
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/bevy_math/src/aspect_ratio.rs
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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 {
Expand Down

0 comments on commit 6840f95

Please sign in to comment.