Trouv / bevy_ecs_ldtk

ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap
Other
687 stars 79 forks source link

Make GridCoords a newtype for IVec2? #85

Open johanhelsing opened 2 years ago

johanhelsing commented 2 years ago

I was just wondering about whether it might be better to wrap IVec2 instead.

#[derive(Component, From, Deref, ...)]
pub struct GridCoords(pub IVec2);

Might save some of the re-implementation of arithmetic operators and make it easier to make use of IVec2's helper methods without doing IVec2::from or .into() all the time.

Trouv commented 2 years ago

I did consider this while writing GridCoords initially. I think I decided against it at the time because it was unclear to me whether this sort of pattern was accepted by the rust community. However, since the bevy 0.7 blog post explicitly encouraged it, I think it's fine.

I still think it's probably a good idea to keep a lot of the conversion functions in utils operating on GridCoords instead of IVec2, just to be more explicit about their purpose in the typing.