About FMath::GetMappedRangeValueClamped()

I find the documentation for FMath::GetMappedRangeValueClamped() confusing, as it mentions the following:

/** For the given Value clamped to the [Input:Range] inclusive, returns the corresponding percentage in [Output:Range] Inclusive. */
static FORCEINLINE float GetMappedRangeValueClamped(const FVector2D& InputRange, const FVector2D& OutputRange, const float Value)
{
    const float ClampedPct = Clamp<float>(GetRangePct(InputRange, Value), 0.f, 1.f);
    return GetRangeValue(OutputRange, ClampedPct);
}

However, the function’s body shows that it returns the value of the percentage from OutputRange, which is calculated from the Value within InputRange.

Or am I just misunderstanding the comment?

I consider FMath::GetMappedRangeValueUnclamped()'s documentation to be superior, even though it’s poorly capitalized:

/** Transform the given Value relative to the input range to the Output Range. */

… try this:

float u = FMath::GetMappedRangeValueClamped(FVector2D(7, 90), FVector2D(700, 9000), 23);

UE_LOG(LogTemp, Log, TEXT(   >>> result:  %f), u);

from:
C++ (Cpp) UWheeledVehicleMovementComponent::SetThrottleInput Examples - HotExamples

1 Like