dimforge / parry

2D and 3D collision-detection library for Rust.
https://parry.rs
Apache License 2.0
555 stars 96 forks source link

Add RayCast impl to SharedShape #43

Closed FredrikNoren closed 2 years ago

sebcrozet commented 3 years ago

Thank you for this PR! Is there a particular reason for adding this trait implementation? The Shape trait already derives from RayCast, which means that &*shared_shape.0 implements RayCast.

FredrikNoren commented 3 years ago

@sebcrozet Just for consistency; I'm using Box<dyn RayCast> in my project and I wanted to be able to dump anything in there that can be ray cast (shared or "simple").

Demindiro commented 3 years ago

The Shape trait already derives from RayCast, which means that &*shared_shape.0 implements RayCast.

I'm using Box<dyn RayCast> in my project and I wanted to be able to dump anything in there that can be ray cast (shared or "simple").

Perhaps it would be useful to to implement Deref with Target = &dyn Shape? That way all methods implemented on Shape should be accessible without needing &*shared_shape.0.

FredrikNoren commented 3 years ago

@Demindiro Looks like type Target = dyn Shape; is already implemented on SharedShape. Not sure if type Target = &dyn Shape; is different though?

Demindiro commented 3 years ago

Looks like type Target = dyn Shape; is already implemented on SharedShape.

Indeed (I meant dyn Shape instead of &dyn Shape). I would expect cast_local_ray to be already useable then though.

FredrikNoren commented 3 years ago

@Demindiro Hm, I tried just doing Box::new(shared_shape.clone()) but I got the trait bound 'SharedShape: RayCast' is not satisfied. required for the cast to the object type 'dyn RayCast'. Not sure if there's some other way to do that though. Box::new(pick_bounding.clone() as dyn RayCast) doesn't work either.