OEOE.MOE

[ frontpage ]
about / projects / useful things / not very useful things
page #1 (ptl, dda) page #2 (tri) page #3 (grd, dth) page #4 (3d) page #5 (buf) page #6 (idx) scratches

2D array indexing

int index = x + y * arrayWidth;

3D array indexing

int index = x + (arrayWidth * (y + (arrayWidth * z)));

2D array indexing (unknown bounds, no intersections)

inline int XYToIndex(int x, int y)
{
    if (x > y) {
        return (x * x) + y;
    } else {
        return (y * y) + y + x;
    }
}