coordinate.h (1651B)
1 /* Macros defined in a separate file for easier testing */ 2 #include "coordinate_macros.h" 3 4 STATIC_INLINE int64_t coord_h48(cube_t, const uint32_t *, uint8_t); 5 STATIC_INLINE int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); 6 STATIC_INLINE cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); 7 8 STATIC_INLINE int64_t 9 coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h) 10 { 11 int64_t cocsep, coclass; 12 uint32_t data; 13 uint8_t ttrep; 14 15 DBG_ASSERT(h <= 11, -1, "coord_h48: h must be between 0 and 11\n"); 16 17 cocsep = coord_cocsep(c); 18 data = cocsepdata[cocsep]; 19 coclass = (int64_t)COCLASS(data); 20 ttrep = (int64_t)TTREP(data); 21 22 return coord_h48_edges(c, coclass, ttrep, h); 23 } 24 25 STATIC_INLINE int64_t 26 coord_h48_edges(cube_t c, int64_t coclass, uint8_t ttrep, uint8_t h) 27 { 28 cube_t d; 29 int64_t esep, eo, edges; 30 31 d = transform_edges(c, ttrep); 32 esep = coord_esep(d); 33 eo = coord_eo(d); 34 edges = (esep << 11) + eo; 35 36 return (coclass * H48_ESIZE(11) + edges) >> (11 - (int64_t)h); 37 } 38 39 /* 40 This function does not necessarily return a cube whose coordinate is 41 the given value, because it works up to symmetry. This means that the 42 returned cube is a transformed cube of one that gives the correct value. 43 */ 44 STATIC_INLINE cube_t 45 invcoord_h48(int64_t i, const cube_t *crep, uint8_t h) 46 { 47 cube_t ret; 48 int64_t hh, coclass, ee, esep, eo; 49 50 DBG_ASSERT(h <= 11, ZERO_CUBE, 51 "invcoord_h48: h must be between 0 and 11\n"); 52 53 hh = (int64_t)h; 54 coclass = i / H48_ESIZE(h); 55 ee = i % H48_ESIZE(h); 56 esep = ee >> hh; 57 eo = (ee & ((1 << hh) - 1)) << (11 - hh); 58 59 ret = invcoord_esep(esep); 60 copy_corners(&ret, crep[coclass]); 61 set_eo(&ret, eo); 62 63 return ret; 64 }