/** * Get the exact tile for the given position and zoom. * * If the tile was unused then it's removed from the cache. * * After usage, please give it back using * ewk_tile_matrix_tile_put(). If you just want to check if it exists, * then use ewk_tile_matrix_tile_exact_exists(). * * @param tm the tile matrix to get tile from. * @param col the column number. * @param row the row number. * @param zoom the exact zoom to use. * * @return The tile instance or @c NULL if none is found. If the tile * was in the unused cache it will be @b removed (thus * considered used) and one should give it back with * ewk_tile_matrix_tile_put() afterwards. * * @see ewk_tile_matrix_tile_nearest_get() * @see ewk_tile_matrix_tile_exact_get() */ Ewk_Tile *ewk_tile_matrix_tile_exact_get(Ewk_Tile_Matrix *tm, unsigned long col, unsigned int row, float zoom) { Ewk_Tile *t, *item, *item_found = NULL; Eina_Inlist *inl; t = eina_matrixsparse_data_idx_get(tm->matrix, row, col); if (!t) return NULL; if (t->zoom == zoom) goto end; EINA_INLIST_FOREACH(EINA_INLIST_GET(t), item) { if (item->zoom != zoom) continue; item_found = item; break; } if (!item_found) return NULL; inl = eina_inlist_promote(EINA_INLIST_GET(t), EINA_INLIST_GET(item_found)); eina_matrixsparse_data_idx_replace(tm->matrix, row, col, inl, NULL); end: if (!t->visible) { if (!ewk_tile_unused_cache_tile_get(tm->tuc, t)) WRN("Ewk_Tile was unused but not in cache? bug!"); } return t; }
static void matrixsparse_check(Eina_Matrixsparse *matrix, long data[MAX_ROWS][MAX_COLS], unsigned long nrows __UNUSED__, unsigned long ncols __UNUSED__) { unsigned long i, j; long *test1; for (i = 0; i < MAX_ROWS; i++) for (j = 0; j < MAX_COLS; j++) { if (data[i][j] != 0) { test1 = eina_matrixsparse_data_idx_get(matrix, i, j); fail_if(test1 == NULL || *test1 != data[i][j]); } else { test1 = eina_matrixsparse_data_idx_get(matrix, i, j); fail_if(test1 != NULL); } } }
/** * Checks if tile of given zoom exists in matrix. * * @param tm the tile matrix to check tile existence. * @param col the column number. * @param row the row number. * @param zoom the exact zoom to query. * * @return @c EINA_TRUE if found, @c EINA_FALSE otherwise. * * @see ewk_tile_matrix_tile_exact_get() */ Eina_Bool ewk_tile_matrix_tile_exact_exists(Ewk_Tile_Matrix *tm, unsigned long col, unsigned int row, float zoom) { Ewk_Tile *t, *item; t = eina_matrixsparse_data_idx_get(tm->matrix, row, col); if (!t) return EINA_FALSE; EINA_INLIST_FOREACH(EINA_INLIST_GET(t), item) { if (item->zoom == zoom) return EINA_TRUE; } return EINA_FALSE; }
/** * Get the nearest tile for given position and zoom. * * The nearest tile is the one at the given position but with the * closest zoom, this being the division of the tile zoom by the * desired zoom, the closest to 1.0 gets it. * * If the tile was unused then it's removed from the cache. * * After usage, please give it back using ewk_tile_matrix_tile_put(). * * @param tm the tile matrix to get tile from. * @param col the column number. * @param row the row number. * @param zoom the exact zoom to use. * * @return The tile instance or @c NULL if none is found. If the tile * was in the unused cache it will be @b removed (thus * considered used) and one should give it back with * ewk_tile_matrix_tile_put() afterwards. */ Ewk_Tile *ewk_tile_matrix_tile_nearest_get(Ewk_Tile_Matrix *tm, unsigned long col, unsigned int row, float zoom) { Ewk_Tile *t, *item, *item_found = NULL; Eina_Inlist *inl; float zoom_found = 0; EINA_SAFETY_ON_NULL_RETURN_VAL(tm, NULL); EINA_SAFETY_ON_FALSE_RETURN_VAL(zoom > 0.0, NULL); t = eina_matrixsparse_data_idx_get(tm->matrix, row, col); if (!t) return NULL; if (t->zoom == zoom) { item_found = t; goto end; } EINA_INLIST_FOREACH(EINA_INLIST_GET(t), item) { float cur_zoom = item->zoom; if (cur_zoom == zoom) { item_found = item; break; } if (cur_zoom > zoom) cur_zoom = zoom / cur_zoom; else cur_zoom = cur_zoom / zoom; if (cur_zoom > zoom_found) { item_found = item; zoom_found = cur_zoom; } }