Created
September 15, 2015 04:58
-
-
Save andyfriesen/f8118ea65b6ce958f480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::{Add, Sub}; | |
#[derive(Copy, Debug)] | |
pub struct Rect<T> { | |
pub left: T, | |
pub top: T, | |
pub right: T, | |
pub bottom: T | |
} | |
impl<T : Add<T> + Sub<T> + Copy> Rect<T> { | |
pub fn width(&self) -> <T as Sub>::Output { | |
return self.right - self.left; | |
} | |
pub fn height(&self) -> <T as Sub>::Output { | |
return self.bottom - self.top; | |
} | |
} | |
#[derive(Copy, Debug)] | |
pub struct Point<T> { | |
pub x: T, | |
pub y: T | |
} | |
impl<T : PartialEq> PartialEq for Point<T> { | |
fn eq(&self, other:&Point<T>) -> bool { | |
self.x == other.x && self.y == other.y | |
} | |
} | |
pub type Recti = Rect<isize>; | |
pub type Rectf = Rect<f32>; | |
pub type Sizei = Point<isize>; | |
pub type Posi = Point<isize>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment