I have been reading about an implementation of the diamond-square algorithm in C# that wraps around to create seamless textures. To calculate the next point, an average is taken of four sample points arranged in a square or a diamond. If a sample point lies of the edge of the texture, it is wrapped around to the other side. This wrapping appears to be done using the following method:
public double sample(int x, int y)
{
return values[(x & (width - 1)) + (y & (height - 1)) * width];
}
A little bit of research tells me this is a bitwise operator. I have not used them before, and the wikipedia article was not enlightening. Could someone explain what the &
operator is doing in this method?
EDIT: The texture dimensions are always powers of two