In
computer graphics
Computer graphics deals with generating images with the aid of computers. Today, computer graphics is a core technology in digital photography, film, video games, cell phone and computer displays, and many specialized applications. A great de ...
, clamping is the process of limiting a position to an area. Unlike
wrapping
Wrapping may refer to:
*Buddy wrapping, the act of bandaging a damaged (particularly a fractured) finger or toe together with a healthy one
*Overwrap, a wrapping of items in a package of a wrapping over packaging
*Wrapping (graphics), the process ...
, clamping merely moves the point to the nearest available value.
To put clamping into perspective,
pseudocode (in
Python
Python may refer to:
Snakes
* Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia
** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia
* Python (mythology), a mythical serpent
Computing
* Python (pro ...
) 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 the
glClearColor
function takes four
GLfloat
values which are then 'clamped' to the range