#ifndef COORD_H #define COORD_H #include typedef struct coord { uint16_t x; /* 16 bits should be enough (65536 pixels) */ uint16_t y; } coord_t; #define SET_COORD( coord, cx, cy ) \ ({ (coord).x = (cx); (coord).y = (cy); }) typedef struct rect { coord_t p0; coord_t p1; } rect_t; #define SET_RECT( rect, cx, cy, cw, ch ) \ ({ SET_COORD( (rect).p0, (cx), (cy) ); SET_COORD( (rect).p1, (cw), (ch) ); }) /** * Converts a pair ( x, y ) to a linear coordinate, given the rectangle is * 'width' units large. */ #define QUAD_TO_LIN( width, x, y ) ( (x) + (y) * (width) ) typedef struct coord3d { uint16_t x; uint16_t y; uint16_t z; } coord3d_t; #define SET_COORD3D( coord, cx, cy, cz ) \ ({ (coord).x = (cx); (coord).y = (cy); (coord).z = (cz); }) /** * Converts a triple ( x, y, z ) to a linear coordinate, given the * parallelogram is 'w' units large and 'h' units height */ #define CUB_TO_LIN( w, h, x, y, z ) ( (x) + (y) * (w) + (z) * (w) * (h) ) #endif /* COORD_H */