made Vec2's T ToPrimitive

This commit is contained in:
dani 2023-07-01 14:36:32 +00:00
parent 36c8b87d47
commit ee2eb7c34d
2 changed files with 8 additions and 8 deletions

View File

@ -1,17 +1,17 @@
use num::Num;
use crate::vec2::Vec2;
use num::{Num, ToPrimitive};
#[derive(Copy, Clone)]
pub struct Rect<T: Num + Copy> {
pub struct Rect<T: Num + Copy + ToPrimitive> {
pub pos: Vec2<T>,
pub size: Vec2<T>,
}
impl<T: Num + Copy> Rect<T> {
impl<T: Num + Copy + ToPrimitive> Rect<T> {
pub fn new(x: T, y: T, w: T, h: T) -> Rect<T> {
Rect {
pos: Vec2{x, y},
size: Vec2{x: w, y: h},
pos: Vec2 { x, y },
size: Vec2 { x: w, y: h },
}
}
}

View File

@ -6,7 +6,7 @@ pub struct Vec2<T: Num + Copy + ToPrimitive> {
pub y: T,
}
impl<T: Num + Copy> Vec2<T> {
impl<T: Num + Copy + ToPrimitive> Vec2<T> {
//pub static
pub fn zero() -> Self {
Vec2 {
@ -17,11 +17,11 @@ impl<T: Num + Copy> Vec2<T> {
//pub
pub fn size(&self) -> usize {
(self.x * self.y) as usize
(self.x * self.y).to_usize().unwrap()
}
}
impl<T: Num + Copy + Default> Default for Vec2<T> {
impl<T: Num + Copy + ToPrimitive + Default> Default for Vec2<T> {
fn default() -> Self {
Vec2 {
x: T::default(),