Guest User

Untitled

a guest
Nov 21st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. use std::fmt::Debug;
  2.  
  3. #[derive(Debug)]
  4. struct Sphere ();
  5.  
  6. #[derive(Debug)]
  7. struct Cube {
  8. size: f32,
  9. }
  10.  
  11. #[derive(Debug)]
  12. struct Intersection<'a> {
  13. t: f32,
  14. obj: &'a Shape
  15. }
  16.  
  17. #[derive(Debug)]
  18. struct Intersections<'a> (Vec<Intersection<'a>>);
  19.  
  20.  
  21. trait Shape: Debug {
  22. fn intersects(&self, ray: f32) -> Intersections;
  23. }
  24.  
  25. impl Shape for Sphere {
  26. fn intersects(&self, ray: f32) -> Intersections {
  27. return Intersections(vec![Intersection{
  28. t: ray,
  29. obj: self
  30. }])
  31. }
  32. }
  33.  
  34. impl Shape for Cube {
  35. fn intersects(&self, ray: f32) -> Intersections {
  36. return Intersections(vec![Intersection{
  37. t: ray,
  38. obj: self
  39. }])
  40. }
  41. }
  42.  
  43. fn main() {
  44. let mut v = Sphere().intersects(2.).0;
  45. v.append( & mut Cube {size: 1.}.intersects(3.).0);
  46. println!("{:?}", Intersections(v));
  47. }
Add Comment
Please, Sign In to add comment