In
computer graphics, clamping is the process of limiting a position to an area. Unlike
wrapping, clamping merely moves the point to the nearest available value.
To put clamping into perspective,
pseudocode
In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
(in
Python) for clamping is as follows:
def clamp(x: int , float, minimum: int , float, maximum: int , float) -> int , float:
"""Limit a position to an area."""
if x < minimum:
x = minimum
elif x > maximum:
x = maximum
return x
Uses
In general, clamping is used to restrict a value to a given range. For example, in
OpenGL
OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardwa ...
the
glClearColor
function takes four
GLfloat
values which are then 'clamped' to the range