Skip to content
Snippets Groups Projects
Commit 7356623b authored by Andreas Gattringer's avatar Andreas Gattringer
Browse files

updated dimension copy check

- renamed functions to match struct name
- better argument names
- added asserts
parent 5d14dc4d
Branches
No related tags found
1 merge request!1preparations for multi-scale simulations
...@@ -70,8 +70,9 @@ void interpolate_environment(const struct cats_configuration *conf, ...@@ -70,8 +70,9 @@ void interpolate_environment(const struct cats_configuration *conf,
const cats_dt_coord rows = environment->current.dimension.rows; const cats_dt_coord rows = environment->current.dimension.rows;
const cats_dt_coord cols = environment->current.dimension.cols; const cats_dt_coord cols = environment->current.dimension.cols;
bool matching_dimensions = dimensions_match(&environment->start.dimension, &environment->end.dimension) bool matching_dimensions = cats_dimensions_match(&environment->start.dimension, &environment->end.dimension)
&& dimensions_match(&environment->start.dimension, &environment->current.dimension); &&
cats_dimensions_match(&environment->start.dimension, &environment->current.dimension);
if (!matching_dimensions) { if (!matching_dimensions) {
log_message(LOG_ERROR, "%s: dimension mismatch", __func__); log_message(LOG_ERROR, "%s: dimension mismatch", __func__);
...@@ -151,7 +152,7 @@ load_environment_raster(struct cats_configuration *conf, struct cats_environment ...@@ -151,7 +152,7 @@ load_environment_raster(struct cats_configuration *conf, struct cats_environment
unload_environment_raster(raster); unload_environment_raster(raster);
copy_dimensions_from_to(&conf->geometry.dimension, &raster->dimension); copy_cats_dimensions(&conf->geometry.dimension, &raster->dimension);
raster->interpolation_type = type; raster->interpolation_type = type;
raster->environment_type = environment_type; raster->environment_type = environment_type;
......
...@@ -55,7 +55,7 @@ void create_raster_if_needed(struct cats_configuration *conf, struct cats_enviro ...@@ -55,7 +55,7 @@ void create_raster_if_needed(struct cats_configuration *conf, struct cats_enviro
log_message(LOG_DEBUG, "%s: ALLOCATING NEW GRID NOW", __func__); log_message(LOG_DEBUG, "%s: ALLOCATING NEW GRID NOW", __func__);
raster->values = new_raw_2d_array_from_dimension(conf->geometry.dimension, sizeof(cats_dt_environment)); raster->values = new_raw_2d_array_from_dimension(conf->geometry.dimension, sizeof(cats_dt_environment));
copy_dimensions_from_to(&conf->geometry.dimension, &raster->dimension); copy_cats_dimensions(&conf->geometry.dimension, &raster->dimension);
} }
......
#include "dimensions.h" #include "dimensions.h"
void copy_dimensions_from_to(const struct cats_dimension *from, struct cats_dimension *to) void copy_cats_dimensions(const struct cats_dimension *source, struct cats_dimension *destination)
{ {
to->rows = from->rows; assert(source != NULL);
to->cols = from->cols; assert(destination != NULL);
destination->rows = source->rows;
destination->cols = source->cols;
} }
bool dimensions_match(const struct cats_dimension *dim1, const struct cats_dimension *dim2) bool cats_dimensions_match(const struct cats_dimension *dim1, const struct cats_dimension *dim2)
{ {
if (dim1->rows == dim2->rows && dim1->cols == dim2->cols) { if (dim1->rows == dim2->rows && dim1->cols == dim2->cols) return true;
return true;
}
return false; return false;
} }
\ No newline at end of file
...@@ -8,17 +8,15 @@ ...@@ -8,17 +8,15 @@
static inline bool valid_coordinates(const struct cats_dimension *dim, cats_dt_coord row, cats_dt_coord col) static inline bool valid_coordinates(const struct cats_dimension *dim, cats_dt_coord row, cats_dt_coord col)
{ {
assert(dim != NULL); assert(dim != NULL);
assert(row >= 0 && row < dim->rows);
assert(col >= 0 && col < dim->cols);
if (row < 0 || col < 0) return false; if (row < 0 || col < 0) return false;
if (row >= dim->rows || col >= dim->cols) return false; if (row >= dim->rows || col >= dim->cols) return false;
return true; return true;
} }
void copy_dimensions_from_to(const struct cats_dimension *from, struct cats_dimension *to); void copy_cats_dimensions(const struct cats_dimension *source, struct cats_dimension *destination);
bool dimensions_match(const struct cats_dimension *dim1, const struct cats_dimension *dim2); bool cats_dimensions_match(const struct cats_dimension *dim1, const struct cats_dimension *dim2);
bool valid_coordinates(const struct cats_dimension *dim, cats_dt_coord row, cats_dt_coord col); bool valid_coordinates(const struct cats_dimension *dim, cats_dt_coord row, cats_dt_coord col);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment