/* Cell subsequences (packs) in unidimensional dyadic grids. */ /* Last edited on 2014-05-15 20:51:03 by stolfilocal */ #ifndef udg_pack_H #define udg_pack_H #define _GNU_SOURCE #include #include #include #include #include #include #include /* CELL PACKS A /cell pack/ is a sequence {\X} of consecutive cells in a given layer {r} of {G*}, defined by the layer index (rank) {r}, an /initial position/ {pos}, the position of the lowest cell in that layer, and a non-negative /pack size/ {psz}, the number of cells in the pack. The pack may fold around the end of the layer. Alternatively (and in several procedures below), a pack is specified by its size {psz} and by the cell identifier {idb} of the inferior cell. Let {gsz} be the size of layer {r}. A cell {C'} of layer {r} belongs to the pack {\X} if and only if its position {pos'} satisfies {pos' = pos + e (mod gsz)}, where {e} is some integer in the range {0..psz-1}. The integer {e} is the /relative position/ or /slot index/ of {C'} within the pack. The lowest (inferior) cell of the pack has slot index 0, and the uppermost (superior) has slot index {psz-1}. */ typedef int64_t udg_pack_slot_index_t; /* Identifies a cell slot in a cell pack. Normally between 0 and {psz-1} where {psz} is the pack size. */ #define udg_NOT_SLOT ((udg_pack_slot_index_t)-1) /* The {udg_pack_slot_index_t} of a cell that is not in the pack. */ void udg_pack_cells(udg_cell_id_t idb, udg_grid_size_t psz, udg_cell_id_t id[]); /* Returns in {id[0..psz-1]} the identifiers of all cells in the pack whose lower cell is {idb} and whose size is {psz}. */ udg_pack_slot_index_t udg_pack_find_cell ( udg_cell_id_t id, udg_cell_id_t idb, udg_grid_size_t psz ); /* Returns the slot index {pkx} of the cell with identifier {id} in the cell pack whose lower cell has identifier {idb} and whose size is {psz}. If {id} occurs multiple times in the pack, returns the first occurrence. If {id} is not part of the pack, returns {udg_NOT_SLOT} */ bool_t udg_pack_intersects_cell ( udg_cell_id_t id, udg_cell_id_t idb, udg_grid_size_t psz ); /* Returns TRUE if cell {id} intersects some cell of the pack with lower cell {idb} and size {psz}. */ void udg_pack_interval_root_relative ( udg_cell_id_t idb, udg_grid_size_t psz, interval_t *B ); /* Stores in {B} the interval that is the union of all cells in the cell pack with lower cell {idb} and size {psz}. The lower endpoint will be in the range {[0_1)}; the upper endpoint will be strictly greater. Due to the toroidal geometry, the upper endpoint {HI((*B))} will be 1 or more whenever the position of {idb} is {gsz-psz} or more, where {gsz} is the grid's size. */ #endif