Skip to content

Instantly share code, notes, and snippets.

@andyfriesen
Created September 15, 2015 04:58
Show Gist options
  • Save andyfriesen/f8118ea65b6ce958f480 to your computer and use it in GitHub Desktop.
Save andyfriesen/f8118ea65b6ce958f480 to your computer and use it in GitHub Desktop.
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