static float Clamp( float v, float min, float max )

robot_2Generated
code_blocksInput

Description

The Clamp method is a static utility function in the MathX class that constrains a given floating-point value to lie within a specified range. If the value is less than the minimum, it returns the minimum. If the value is greater than the maximum, it returns the maximum. Otherwise, it returns the value itself.

Usage

Use this method when you need to ensure that a floating-point value does not exceed specified bounds. This is particularly useful in scenarios where values are derived from calculations that might exceed expected limits, such as physics simulations or user input processing.

Example

// Example usage of MathX.Clamp
float value = 10.5f;
float minValue = 0.0f;
float maxValue = 10.0f;

// Clamps the value to be within the range [minValue, maxValue]
float clampedValue = MathX.Clamp(value, minValue, maxValue);
// clampedValue will be 10.0f because 10.5f exceeds the maxValue