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:
		
							parent
							
								
									c38e2d037d
								
							
						
					
					
						commit
						6840f95d62
					
				| @ -1,5 +1,7 @@ | |||||||
| //! Provides a simple aspect ratio struct to help with calculations.
 | //! Provides a simple aspect ratio struct to help with calculations.
 | ||||||
| 
 | 
 | ||||||
|  | use crate::Vec2; | ||||||
|  | 
 | ||||||
| /// An `AspectRatio` is the ratio of width to height.
 | /// An `AspectRatio` is the ratio of width to height.
 | ||||||
| pub struct AspectRatio(f32); | 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 { | impl From<AspectRatio> for f32 { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn from(aspect_ratio: AspectRatio) -> Self { |     fn from(aspect_ratio: AspectRatio) -> Self { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 mamekoro
						mamekoro