JOML
JOML copied to clipboard
[Suggestion] Vector .map() function
One feature that would be helpful would be a simple component-wise mapping function. Useful for performing operations that aren't built-in by default, such as bitwise operations, or more complex operations that are conditional based on the component's current value.
Example Usage:
Vector3i blockPos = getBlockPosition();
Vector3i chunkPos = vec.map(c -> c >> 4, new Vector3i());
Implementation would be rather straightforward, I imagine.
public <T extends Integer> Vector3i map(Function<T,T> mapper, Vector3i dest) {
dest.x = mapper.apply(this.x);
dest.y = mapper.apply(this.y);
dest.z = mapper.apply(this.z);
return dest;
}
Currently, this can easily be done with utility functions, but it would be a nice quality-of-life feature.