Fix crash when printing some text

This commit is contained in:
Joscha 2024-03-17 17:35:44 +01:00
parent 4f3d66f6a0
commit d69557daf6
2 changed files with 32 additions and 10 deletions

View file

@ -20,12 +20,24 @@ impl Vec2 {
Self { x, y }
}
pub fn from_u32_checked(x: u32, y: u32) -> Option<Self> {
let x: i32 = x.try_into().ok()?;
let y: i32 = y.try_into().ok()?;
Some(Self::new(x, y))
}
pub fn from_u32(x: u32, y: u32) -> Self {
let x: i32 = x.try_into().expect("x too large");
let y: i32 = y.try_into().expect("y too large");
Self::new(x, y)
}
pub fn to_u32_checked(self) -> Option<(u32, u32)> {
let x: u32 = self.x.try_into().ok()?;
let y: u32 = self.y.try_into().ok()?;
Some((x, y))
}
pub fn to_u32(self) -> (u32, u32) {
let x: u32 = self.x.try_into().expect("x too small");
let y: u32 = self.y.try_into().expect("y too small");