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

Add functions to map a value from one range to another in Magnum:Math #341

Closed
roig opened this issue May 23, 2019 · 3 comments
Closed

Add functions to map a value from one range to another in Magnum:Math #341

roig opened this issue May 23, 2019 · 3 comments

Comments

@roig
Copy link
Contributor

@roig roig commented May 23, 2019

I think it would be useful to have those functions in Magnum::Math

something like :
http://api.unrealengine.com/INT/BlueprintAPI/Math/Float/MapRangeClamped/

@mosra mosra added this to TODO in Math and algorithms via automation May 23, 2019
@mosra mosra added this to the 2019.0b milestone May 23, 2019
@mosra

This comment has been minimized.

Copy link
Owner

@mosra mosra commented May 23, 2019

You mean Math::lerpInverted() combined with Math::lerp()? :)

Float b = Math::lerp(5.0f, 15.0f, Math::lerpInverted(-1.0f, 1.0f, a));

maps a from a range [ -1; +1 ] to a range [ 5; 15 ]. Works for vectors (and vector ranges) too. In addition you can (but you don't have to) clamp() the value to have the same behavior as UE:

Float b = Math::lerp(5.0f, 15.0f, Math::clamp(Math::lerpInverted(-1.0f, 1.0f, a), 0.0f, 1.0f));
@roig

This comment has been minimized.

Copy link
Contributor Author

@roig roig commented May 24, 2019

Yes, that's it!

@mosra mosra moved this from TODO to In progress in Math and algorithms May 25, 2019
@mosra

This comment has been minimized.

Copy link
Owner

@mosra mosra commented May 25, 2019

A mention of this is in the docs of Math::lerpInverted() since 2a9f4a1. Closing as resolved :)

@mosra mosra closed this May 25, 2019
Math and algorithms automation moved this from In progress to Done May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants
You can’t perform that action at this time.