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

[Suggestion] Vector .map() function #311

Open
TheDudeFromCI opened this issue Apr 11, 2022 · 0 comments
Open

[Suggestion] Vector .map() function #311

TheDudeFromCI opened this issue Apr 11, 2022 · 0 comments

Comments

@TheDudeFromCI
Copy link

TheDudeFromCI commented Apr 11, 2022

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.

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

1 participant