JOML-CI / JOML

A Java math library for OpenGL rendering calculations
MIT License
728 stars 104 forks source link

[Suggestion] Vector .map() function #311

Open TheDudeFromCI opened 2 years ago

TheDudeFromCI commented 2 years ago

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.