Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fmt::Debug;
- #[derive(Debug)]
- struct Sphere ();
- #[derive(Debug)]
- struct Cube {
- size: f32,
- }
- #[derive(Debug)]
- struct Intersection<'a> {
- t: f32,
- obj: &'a Shape
- }
- #[derive(Debug)]
- struct Intersections<'a> (Vec<Intersection<'a>>);
- trait Shape: Debug {
- fn intersects(&self, ray: f32) -> Intersections;
- }
- impl Shape for Sphere {
- fn intersects(&self, ray: f32) -> Intersections {
- return Intersections(vec![Intersection{
- t: ray,
- obj: self
- }])
- }
- }
- impl Shape for Cube {
- fn intersects(&self, ray: f32) -> Intersections {
- return Intersections(vec![Intersection{
- t: ray,
- obj: self
- }])
- }
- }
- fn main() {
- let mut v = Sphere().intersects(2.).0;
- v.append( & mut Cube {size: 1.}.intersects(3.).0);
- println!("{:?}", Intersections(v));
- }
Add Comment
Please, Sign In to add comment