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

remap function included in the std library #1899

Open
emkkla opened this issue Nov 5, 2024 · 1 comment
Open

remap function included in the std library #1899

emkkla opened this issue Nov 5, 2024 · 1 comment
Assignees

Comments

@emkkla
Copy link

emkkla commented Nov 5, 2024

The need for a remap() function (also called efit() in VEX) is very common in shading, and it would be appreciated if the standard library included it natively.

So far, of course, we can remap vectors or floats by simply defining the function manually:

vector vectorRemap(vector input, vector minIn, vector maxIn, vector minOut, vector maxOut) {
    return minOut + (input - minIn) * (maxOut - minOut) / (maxIn - minIn);
}
float floatRemap(float input, float minIn, float maxIn, float minOut, float maxOut) {
    return minOut + (input - minIn) * (maxOut - minOut) / (maxIn - minIn);
}

But, having it part of the std would simplify code and ensure a proper implementation:

type remap(type input, type minIn, type maxIn, type minOut, type maxOut)
@lgritz
Copy link
Collaborator

lgritz commented Nov 10, 2024

That's a good idea, I will do so.

@lgritz lgritz self-assigned this Nov 10, 2024
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