renderbug: first implementation of virtual coordinate based rendering
This commit is contained in:
53
src/geometry.rs
Normal file
53
src/geometry.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub trait CoordinateSpace {}
|
||||
|
||||
pub trait Coordinates<T, S: CoordinateSpace> {
|
||||
fn x(&self) -> T;
|
||||
fn y(&self) -> T;
|
||||
fn new(x: T, y: T) -> Self;
|
||||
|
||||
const MAX: T;
|
||||
const MIN: T;
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
pub struct Virtual {}
|
||||
impl CoordinateSpace for Virtual {}
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
pub struct Physical {}
|
||||
impl CoordinateSpace for Physical {}
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
pub struct Coord8<S: CoordinateSpace> {
|
||||
x: u8,
|
||||
y: u8,
|
||||
space: PhantomData<S>
|
||||
}
|
||||
|
||||
pub type VirtualCoordinates = Coord8<Virtual>;
|
||||
pub type PhysicalCoordinates = Coord8<Physical>;
|
||||
|
||||
impl<S> Coordinates<u8, S> for Coord8<S>
|
||||
where
|
||||
S: CoordinateSpace {
|
||||
fn new(x: u8, y: u8) -> Self {
|
||||
Self {
|
||||
x: x,
|
||||
y: y,
|
||||
space: PhantomData
|
||||
}
|
||||
}
|
||||
|
||||
fn x(&self) -> u8 {
|
||||
self.x
|
||||
}
|
||||
|
||||
fn y(&self) -> u8 {
|
||||
self.y
|
||||
}
|
||||
|
||||
const MAX: u8 = 255;
|
||||
const MIN: u8 = 255;
|
||||
}
|
Reference in New Issue
Block a user