1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
pub trait Point: Copy{ fn new(x: f32 , y: f32 , z: f32) -> Self; fn x(&self) -> f32; fn y(&self) -> f32; fn z(&self) -> f32; } impl Point for (f32 , f32 , f32){ fn new(x: f32 , y: f32 , z: f32) -> Self{ (x , y , z) } fn x(&self) -> f32{ self.0 } fn y(&self) -> f32{ self.1 } fn z(&self) -> f32{ self.2 } } impl Point for [f32;3]{ fn new(x: f32 , y: f32 , z: f32) -> Self{ [x , y , z] } fn x(&self) -> f32{ self[0] } fn y(&self) -> f32{ self[1] } fn z(&self) -> f32{ self[2] } } pub trait Triangle<P: Point>{ fn new(normal: P , vert1: P , vert2: P , vert3: P , attr: u16) -> Self; fn normal(&self) -> P; fn vert1(&self) -> P; fn vert2(&self) -> P; fn vert3(&self) -> P; fn attr(&self) -> u16; } #[derive(Copy , Clone , Debug)] pub struct Trig<P: Point>{ normal: P, v1: P, v2: P, v3: P, } impl<P: Point> Triangle<P> for Trig<P>{ fn new(normal: P , vert1: P , vert2: P , vert3: P , _: u16) -> Self{ Self{ normal, v1: vert1, v2: vert2, v3: vert3, } } fn normal(&self) -> P{ self.normal } fn vert1(&self) -> P{ self.v1 } fn vert2(&self) -> P{ self.v2 } fn vert3(&self) -> P{ self.v3 } fn attr(&self) -> u16{0} }