Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make converting positions to points easier #95

Open
ndarilek opened this issue Aug 11, 2021 · 6 comments
Open

Make converting positions to points easier #95

ndarilek opened this issue Aug 11, 2021 · 6 comments
Labels
A-Integration very bevy specific C-Enhancement New feature or request D-Easy P-Medium S-not-started Work has not started

Comments

@ndarilek
Copy link
Contributor

I often find myself doing something like:

let p1: Point<f32> = position.position.translation.vector.into();

if I want to get the distance between entities. This gets verbose quickly, especially with multiple entities.

I wonder if it makes sense to add the conversions higher up in the chain:

let p1: Point<f32> = position.position.translation.into();

Most straight-forward, since I'm working directly on the translation.

let p1: Point<f32> = position.position.into();

Unless there's some other, more meaningful point that can be derived from the isometry, this would be preferable since distance between positions seems common enough.

let p1: Point<f32> = position.into();

In general, if someone isn't interested in the next position, I'd argue that current should be the default assumption without having to be explicit about it every time. This makes calculating distances between two entities a whole lot cleaner:

let distance = na::distance(position1.into(), position2.into());

Thanks.

@MiniaczQ
Copy link

MiniaczQ commented Oct 8, 2021

Stumbled here randomly,
while the first few are still every long,
the later ones start getting non-obvious as to what they actually return.

You should consider making a trait extension to get the point directly from position, probably with a more accurate name.
as_point() perhaps?
Maybe something more descriptive.
Let me know what you think.

@ndarilek
Copy link
Contributor Author

ndarilek commented Oct 8, 2021

It should be obvious what all these things return given that most have type annotations--often a requirement when using into().

I know I can make an extension trait, but I don't think I should have to. Rapier already has lots of conversions, so running up against the lack of them here is a bit jarring.

@sebcrozet
Copy link
Member

Adding (to nalgebra) a conversion from Translation to Point sounds legitimate (especially since we already have a Point -> Translation conversion). Anything higher up the hierarchy start being too ambiguous since some information (the rotation part of the isometry) is lost in the process.

@ndarilek
Copy link
Contributor Author

Sure, but what relevant part of the position is lost when calculating distance between two points? Since rotation isn't relevant there anyway, what's the harm in dropping it if explicitly requested to do so?

@sebcrozet
Copy link
Member

sebcrozet commented Oct 12, 2021

if explicitly requested to do so

Yes, so writing isometry.translation.into() would be the explicit way to request only the translational part as a point. Writing isometry.into() to extract only the translational part on the other hand doesn’t look explicit.

@ndarilek
Copy link
Contributor Author

I can respect that if it's your ultimate decision. But I'd counter that, if the type-checker wants a thing that behaves like it's idea of how a Point should, that .into() translating directly into that is as explicit as it needs to be, regardless of how high on the type hierarchy Point is.

Either way, I'll be glad to see this get a bit easier to accomplish. Thanks.

@Vrixyz Vrixyz added C-Enhancement New feature or request D-Easy P-Medium S-not-started Work has not started A-Integration very bevy specific labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Integration very bevy specific C-Enhancement New feature or request D-Easy P-Medium S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

4 participants