X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_point.c;h=a86dd67d29d02aff41dee5f2e2c5675d05d347df;hb=63fb8a7f484648c3caa25351c8c94ac2395ec563;hp=53419bee16d0ab988857e97f37a3ec9ad7c95115;hpb=dbb61f82cfb84f18d8df5d2aa114fd114d559d39;p=platform%2Fupstream%2Fisl.git diff --git a/isl_point.c b/isl_point.c index 53419be..a86dd67 100644 --- a/isl_point.c +++ b/isl_point.c @@ -5,6 +5,7 @@ #include #include #include +#include isl_ctx *isl_point_get_ctx(__isl_keep isl_point *pnt) { @@ -125,14 +126,48 @@ int isl_point_is_void(__isl_keep isl_point *pnt) return pnt->vec->size == 0; } -void isl_point_get_coordinate(__isl_keep isl_point *pnt, +int isl_point_get_coordinate(__isl_keep isl_point *pnt, enum isl_dim_type type, int pos, isl_int *v) { if (!pnt || isl_point_is_void(pnt)) - return; + return -1; + + if (pos < 0 || pos >= isl_space_dim(pnt->dim, type)) + isl_die(isl_point_get_ctx(pnt), isl_error_invalid, + "position out of bounds", return -1); + if (type == isl_dim_set) pos += isl_space_dim(pnt->dim, isl_dim_param); isl_int_set(*v, pnt->vec->el[1 + pos]); + + return 0; +} + +/* Return the value of coordinate "pos" of type "type" of "pnt". + */ +__isl_give isl_val *isl_point_get_coordinate_val(__isl_keep isl_point *pnt, + enum isl_dim_type type, int pos) +{ + isl_ctx *ctx; + isl_val *v; + + if (!pnt) + return NULL; + + ctx = isl_point_get_ctx(pnt); + if (isl_point_is_void(pnt)) + isl_die(ctx, isl_error_invalid, + "void point does not have coordinates", return NULL); + if (pos < 0 || pos >= isl_space_dim(pnt->dim, type)) + isl_die(ctx, isl_error_invalid, + "position out of bounds", return NULL); + + if (type == isl_dim_set) + pos += isl_space_dim(pnt->dim, isl_dim_param); + + v = isl_val_rat_from_isl_int(ctx, pnt->vec->el[1 + pos], + pnt->vec->el[0]); + return isl_val_normalize(v); } __isl_give isl_point *isl_point_set_coordinate(__isl_take isl_point *pnt, @@ -159,6 +194,58 @@ error: return NULL; } +/* Replace coordinate "pos" of type "type" of "pnt" by "v". + */ +__isl_give isl_point *isl_point_set_coordinate_val(__isl_take isl_point *pnt, + enum isl_dim_type type, int pos, __isl_take isl_val *v) +{ + if (!pnt || !v) + goto error; + if (isl_point_is_void(pnt)) + isl_die(isl_point_get_ctx(pnt), isl_error_invalid, + "void point does not have coordinates", goto error); + if (pos < 0 || pos >= isl_space_dim(pnt->dim, type)) + isl_die(isl_point_get_ctx(pnt), isl_error_invalid, + "position out of bounds", goto error); + if (!isl_val_is_rat(v)) + isl_die(isl_point_get_ctx(pnt), isl_error_invalid, + "expecting rational value", goto error); + + if (isl_int_eq(pnt->vec->el[1 + pos], v->n) && + isl_int_eq(pnt->vec->el[0], v->d)) { + isl_val_free(v); + return pnt; + } + + pnt = isl_point_cow(pnt); + if (!pnt) + goto error; + pnt->vec = isl_vec_cow(pnt->vec); + if (!pnt->vec) + goto error; + + if (isl_int_eq(pnt->vec->el[0], v->d)) { + isl_int_set(pnt->vec->el[1 + pos], v->n); + } else if (isl_int_is_one(v->d)) { + isl_int_mul(pnt->vec->el[1 + pos], pnt->vec->el[0], v->n); + } else { + isl_seq_scale(pnt->vec->el + 1, + pnt->vec->el + 1, v->d, pnt->vec->size - 1); + isl_int_mul(pnt->vec->el[1 + pos], pnt->vec->el[0], v->n); + isl_int_mul(pnt->vec->el[0], pnt->vec->el[0], v->d); + pnt->vec = isl_vec_normalize(pnt->vec); + if (!pnt->vec) + goto error; + } + + isl_val_free(v); + return pnt; +error: + isl_val_free(v); + isl_point_free(pnt); + return NULL; +} + __isl_give isl_point *isl_point_add_ui(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, unsigned val) {