Clamping (graphics)
From Wikipedia, the free encyclopedia
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. Pseudocode for it is:
function clamp(X, Min, Max:Real):Real; if X > Max then X := Max; if X < Min then X := Min; return X;
And the C/C++ code like this (int can be changed into any other datatype).
int clamp(int X, int Min, int Max)
{
if( X > Max )
X = Max;
else if( X < Min )
X = Min;
return X;
}
[edit] Uses
One of the many uses of clamping in computer graphics is the placing of a detail inside a polygon--for example, a bullethole on a wall. It can also be used with wrapping to create a variety of effects.

