From 5ad647c4637e80341574ee6631ead49bf13e0299 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 6 Feb 2019 14:01:21 +0100 Subject: boundary: add public functions for querying boundary information Should allow treating boundaries in a generic manner. API bump --- boundary.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'boundary.c') diff --git a/boundary.c b/boundary.c index 86803fc..419a310 100644 --- a/boundary.c +++ b/boundary.c @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -73,3 +74,61 @@ void mg2di_bc_free(MG2DBoundary **pbnd) free(bnd); *pbnd = NULL; } + +static const struct { + unsigned int coord_idx; + unsigned int is_upper; +} boundary_def[] = { + [MG2D_BOUNDARY_0L] = { + .coord_idx = 0, + .is_upper = 0, + }, + [MG2D_BOUNDARY_0U] = { + .coord_idx = 0, + .is_upper = 1, + }, + [MG2D_BOUNDARY_1L] = { + .coord_idx = 1, + .is_upper = 0 + }, + [MG2D_BOUNDARY_1U] = { + .coord_idx = 1, + .is_upper = 1, + }, +}; + +int mg2d_bnd_coord_idx(enum MG2DBoundaryLoc loc) +{ + if (loc < 0 || loc >= ARRAY_ELEMS(boundary_def)) + return -EINVAL; + + return boundary_def[loc].coord_idx; +} + +int mg2d_bnd_is_upper(enum MG2DBoundaryLoc loc) +{ + if (loc < 0 || loc >= ARRAY_ELEMS(boundary_def)) + return -EINVAL; + + return boundary_def[loc].is_upper; +} + +int mg2d_bnd_out_dir(enum MG2DBoundaryLoc loc) +{ + int ret = mg2d_bnd_is_upper(loc); + + if (ret < 0) + return 0; + + return ret ? 1 : -1; +} + +enum MG2DBoundaryLoc mg2d_bnd_id(int coord_idx, int is_upper) +{ + for (int i = 0; i < ARRAY_ELEMS(boundary_def); i++) { + if (boundary_def[i].coord_idx == coord_idx && + boundary_def[i].is_upper == is_upper) + return i; + } + return MG2D_BOUNDARY_NONE; +} -- cgit v1.2.3