From ad4007ef9559a389d26633dd4e53360ff2780e44 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 12 Apr 2013 10:19:21 +0200 Subject: [PATCH] add isl_point_set_coordinate_val Signed-off-by: Sven Verdoolaege --- doc/user.pod | 4 ++++ include/isl/point.h | 3 +++ isl_point.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index 0097f0f..708e85a 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -4395,6 +4395,10 @@ using __isl_give isl_point *isl_point_set_coordinate( __isl_take isl_point *pnt, enum isl_dim_type type, int pos, isl_int 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); __isl_give isl_point *isl_point_add_ui( __isl_take isl_point *pnt, diff --git a/include/isl/point.h b/include/isl/point.h index c17e605..d8bf1e4 100644 --- a/include/isl/point.h +++ b/include/isl/point.h @@ -3,6 +3,7 @@ #include #include +#include #if defined(__cplusplus) extern "C" { @@ -22,6 +23,8 @@ int isl_point_get_coordinate(__isl_keep isl_point *pnt, enum isl_dim_type type, int pos, isl_int *v); __isl_give isl_point *isl_point_set_coordinate(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, isl_int 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); __isl_give isl_point *isl_point_add_ui(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, unsigned val); diff --git a/isl_point.c b/isl_point.c index 00514a9..874a22e 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) { @@ -166,6 +167,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) { -- 2.7.4