bevy_math/
aspect_ratio.rs1use crate::Vec2;
4
5#[cfg(feature = "bevy_reflect")]
6use bevy_reflect::Reflect;
7
8#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
10#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
11pub struct AspectRatio(f32);
12
13impl AspectRatio {
14 #[inline]
16 pub fn new(width: f32, height: f32) -> Self {
17 Self(width / height)
18 }
19
20 #[inline]
22 pub fn from_pixels(x: u32, y: u32) -> Self {
23 Self::new(x as f32, y as f32)
24 }
25}
26
27impl From<Vec2> for AspectRatio {
28 #[inline]
29 fn from(value: Vec2) -> Self {
30 Self::new(value.x, value.y)
31 }
32}
33
34impl From<AspectRatio> for f32 {
35 #[inline]
36 fn from(aspect_ratio: AspectRatio) -> Self {
37 aspect_ratio.0
38 }
39}