From 6840f95d625b413dcaedb6263eab55dc506525b5 Mon Sep 17 00:00:00 2001 From: mamekoro <86554319+mamekoro@users.noreply.github.com> Date: Thu, 28 Mar 2024 07:32:31 +0900 Subject: [PATCH] Implement `From` 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 for AspectRatio`. --- ## Changelog - Added `impl From for AspectRatio` --- crates/bevy_math/src/aspect_ratio.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/bevy_math/src/aspect_ratio.rs b/crates/bevy_math/src/aspect_ratio.rs index 1d18c690b8f09..08e47e91ba4e1 100644 --- a/crates/bevy_math/src/aspect_ratio.rs +++ b/crates/bevy_math/src/aspect_ratio.rs @@ -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 for AspectRatio { + #[inline] + fn from(value: Vec2) -> Self { + Self::new(value.x, value.y) + } +} + impl From for f32 { #[inline] fn from(aspect_ratio: AspectRatio) -> Self {