-
Notifications
You must be signed in to change notification settings - Fork 723
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
vec2 truncate function #308
Comments
Hey @mreinstein can you share scenarios where this might be useful as part of the |
I wanted multiple time to have a way to build a vec3 out of a vec4 or a vec2 out of a vec4 or vec 3. |
@WhiteSEEKER Please open a new issue for that. |
Oh I see, I miss understand this feature request. I though it was about truncating in dimensions, not in length ... my bad. |
@andrevenancio I can't enumerate all possible use cases, but one example is boids/flocking: https://github.com/hughsk/boids/blob/master/index.js#L146-L153
|
Here would be a (untested) implementation for vec2. export function truncate(out, maxLength) {
let x = a[0],
y = a[1];
let len = Math.sqrt(x*x + y*y);
if (len > maxLength) {
let scaleDown = maxLength / len;
a[0] = x * scaleDown;
a[1] = y * scaleDown;
}
return out
} |
Yeah, something like that might work. I do understand some frustrations from a user point of view, me, for example, I would love if I think it's better to have a math util folder on your project specifically. Otherwise, |
I couldn't have expressed my thoughts better than andrevenancio did. I'm starting to think that having a second repository with all sorts of extra functions for gl-matrix might be a decent idea. 🤔 |
I've recently come back to some projects that require vector math, and I'm again finding a need for I can (and do) maintain a set of math utility functions for these unordained vector functions, but now I have 4 different projects with these identical modules in them. so the next logical thought is "hey I could publish these in a module and cut down on duplication". And then the following thought is "wait, the world already has a polished vector/matrix math module, why am I making a new one?" I can totally understand and appreciate the desire to avoid bloating gl-matrix with a ton of stuff. Can we please re-consider our stance on some of these vector additions? 🙏 |
Which functions would you be interested in? And, are there any relevant feature requests? |
at the moment, the most common one I'm looking for is I'm happy to open a separate issue for this if that's helpful (I don't think we should let people create issues that lump together like 8 different function requests in one. :) ) |
Yes please, do open a new issue with that feature request! |
related PR: #394 |
Shortens a vector to
maxLength
if it is longer.The text was updated successfully, but these errors were encountered: