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

Improving ergonomics of extend #113

Closed
Boscop opened this issue Dec 16, 2020 · 2 comments
Closed

Improving ergonomics of extend #113

Boscop opened this issue Dec 16, 2020 · 2 comments

Comments

@Boscop
Copy link

Boscop commented Dec 16, 2020

It would be nice to have an extend method on f32: fn extend(self, y: f32) -> Vec2.

Also the Vec2::extend method could take something that impls Into<ExtendRemaining2>, and the f32::extend method could take something that impls Into<ExtendRemaining3>.
ExtendRemainingN is a trait that types implement that can fill up the remaining N "slots".
E.g. f32 impls ExtendRemaining2 because it can be appended when there are 2 free "slots".
Vec2 also impls ExtendRemaining2 but not Vec3.
E.g. you want to be able to do p.extend(q) when both are Vec2 to create one Vec4.
Or 1f32.extend(p) when p is a Vec2 (to create a Vec3) or when p is a Vec3 (to create a Vec4).

Related to #109, #110 and #112

@bitshifter
Copy link
Owner

Can you provide a code example of how you would like to use extend on f32? This would require adding a trait and implementation for primitive types, which is not something glam currently does or has any other need for.

For extending to other types, I would be more inclined to add more From conversions, e.g. there are currently:

  • impl From<(Vec2, f32)> for Vec3
  • impl From<(Vec3, f32)> for Vec4

I would be OK with continuing this pattern and adding:

  • impl From<(Vec2, f32, f32)> for Vec4
  • impl From<(Vec2, Vec2)> for Vec4

Which wouldn't require adding additional traits to glam.

@bitshifter
Copy link
Owner

Added all the above From impls in my comment, going to close this as won't fix for now. I don't want to add these additional traits to glam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants