LCOV - code coverage report
Current view: top level - metalib_isl - isl_point.c (source / functions) Hit Total Coverage
Test: 2018-10-31_point_maint_greina16.lcov Lines: 76 372 20.4 %
Date: 2018-11-01 11:27:00 Functions: 12 33 36.4 %

          Line data    Source code
       1             : #include <isl_map_private.h>
       2             : #include <isl_point_private.h>
       3             : #include <isl/set.h>
       4             : #include <isl/union_set.h>
       5             : #include <isl_sample.h>
       6             : #include <isl_scan.h>
       7             : #include <isl_seq.h>
       8             : #include <isl_space_private.h>
       9             : #include <isl_val_private.h>
      10             : #include <isl_vec_private.h>
      11             : #include <isl_output_private.h>
      12             : 
      13             : #include <set_to_map.c>
      14             : 
      15           0 : isl_ctx *isl_point_get_ctx(__isl_keep isl_point *pnt)
      16             : {
      17           0 :         return pnt ? isl_space_get_ctx(pnt->dim) : NULL;
      18             : }
      19             : 
      20             : /* Return the space of "pnt".
      21             :  */
      22     3054144 : __isl_keep isl_space *isl_point_peek_space(__isl_keep isl_point *pnt)
      23             : {
      24     3054144 :         return pnt ? pnt->dim : NULL;
      25             : }
      26             : 
      27           0 : __isl_give isl_space *isl_point_get_space(__isl_keep isl_point *pnt)
      28             : {
      29           0 :         return isl_space_copy(isl_point_peek_space(pnt));
      30             : }
      31             : 
      32     2070006 : __isl_give isl_point *isl_point_alloc(__isl_take isl_space *dim,
      33             :         __isl_take isl_vec *vec)
      34             : {
      35             :         struct isl_point *pnt;
      36             : 
      37     2070006 :         if (!dim || !vec)
      38             :                 goto error;
      39             : 
      40     2070006 :         if (vec->size > 1 + isl_space_dim(dim, isl_dim_all)) {
      41           0 :                 vec = isl_vec_cow(vec);
      42           0 :                 if (!vec)
      43           0 :                         goto error;
      44           0 :                 vec->size = 1 + isl_space_dim(dim, isl_dim_all);
      45             :         }
      46             : 
      47     2070006 :         pnt = isl_alloc_type(dim->ctx, struct isl_point);
      48     2070006 :         if (!pnt)
      49           0 :                 goto error;
      50             : 
      51     2070006 :         pnt->ref = 1;
      52     2070006 :         pnt->dim = dim;
      53     2070006 :         pnt->vec = vec;
      54             : 
      55     2070006 :         return pnt;
      56             : error:
      57           0 :         isl_space_free(dim);
      58           0 :         isl_vec_free(vec);
      59           0 :         return NULL;
      60             : }
      61             : 
      62      112953 : __isl_give isl_point *isl_point_zero(__isl_take isl_space *dim)
      63             : {
      64             :         isl_vec *vec;
      65             : 
      66      112953 :         if (!dim)
      67           0 :                 return NULL;
      68      112953 :         vec = isl_vec_alloc(dim->ctx, 1 + isl_space_dim(dim, isl_dim_all));
      69      112953 :         if (!vec)
      70           0 :                 goto error;
      71      112953 :         isl_int_set_si(vec->el[0], 1);
      72      112953 :         isl_seq_clr(vec->el + 1, vec->size - 1);
      73      112953 :         return isl_point_alloc(dim, vec);
      74             : error:
      75           0 :         isl_space_free(dim);
      76           0 :         return NULL;
      77             : }
      78             : 
      79     1957009 : __isl_give isl_point *isl_point_dup(__isl_keep isl_point *pnt)
      80             : {
      81             :         struct isl_point *pnt2;
      82             : 
      83     1957009 :         if (!pnt)
      84           0 :                 return NULL;
      85     1957009 :         pnt2 = isl_point_alloc(isl_space_copy(pnt->dim), isl_vec_copy(pnt->vec));
      86     1957009 :         return pnt2;
      87             : }
      88             : 
      89     1957009 : __isl_give isl_point *isl_point_cow(__isl_take isl_point *pnt)
      90             : {
      91             :         struct isl_point *pnt2;
      92     1957009 :         if (!pnt)
      93           0 :                 return NULL;
      94             : 
      95     1957009 :         if (pnt->ref == 1)
      96           0 :                 return pnt;
      97             : 
      98     1957009 :         pnt2 = isl_point_dup(pnt);
      99     1957009 :         isl_point_free(pnt);
     100     1957009 :         return pnt2;
     101             : }
     102             : 
     103     5844882 : __isl_give isl_point *isl_point_copy(__isl_keep isl_point *pnt)
     104             : {
     105     5844882 :         if (!pnt)
     106           0 :                 return NULL;
     107             : 
     108     5844882 :         pnt->ref++;
     109     5844882 :         return pnt;
     110             : }
     111             : 
     112     7914888 : __isl_null isl_point *isl_point_free(__isl_take isl_point *pnt)
     113             : {
     114     7914888 :         if (!pnt)
     115           0 :                 return NULL;
     116             : 
     117     7914888 :         if (--pnt->ref > 0)
     118     5844882 :                 return NULL;
     119             : 
     120     2070006 :         isl_space_free(pnt->dim);
     121     2070006 :         isl_vec_free(pnt->vec);
     122     2070006 :         free(pnt);
     123     2070006 :         return NULL;
     124             : }
     125             : 
     126           0 : __isl_give isl_point *isl_point_void(__isl_take isl_space *dim)
     127             : {
     128           0 :         if (!dim)
     129           0 :                 return NULL;
     130             : 
     131           0 :         return isl_point_alloc(dim, isl_vec_alloc(dim->ctx, 0));
     132             : }
     133             : 
     134     3054144 : isl_bool isl_point_is_void(__isl_keep isl_point *pnt)
     135             : {
     136     3054144 :         if (!pnt)
     137           0 :                 return isl_bool_error;
     138             : 
     139     3054144 :         return pnt->vec->size == 0;
     140             : }
     141             : 
     142             : /* Return the space of "pnt".
     143             :  * This may be either a copy or the space itself
     144             :  * if there is only one reference to "pnt".
     145             :  * This allows the space to be modified inplace
     146             :  * if both the point and its space have only a single reference.
     147             :  * The caller is not allowed to modify "pnt" between this call and
     148             :  * a subsequent call to isl_point_restore_space.
     149             :  * The only exception is that isl_point_free can be called instead.
     150             :  */
     151           0 : __isl_give isl_space *isl_point_take_space(__isl_keep isl_point *pnt)
     152             : {
     153             :         isl_space *space;
     154             : 
     155           0 :         if (!pnt)
     156           0 :                 return NULL;
     157           0 :         if (pnt->ref != 1)
     158           0 :                 return isl_point_get_space(pnt);
     159           0 :         space = pnt->dim;
     160           0 :         pnt->dim = NULL;
     161           0 :         return space;
     162             : }
     163             : 
     164             : /* Set the space of "pnt" to "space", where the space of "pnt" may be missing
     165             :  * due to a preceding call to isl_point_take_space.
     166             :  * However, in this case, "pnt" only has a single reference and
     167             :  * then the call to isl_point_cow has no effect.
     168             :  */
     169           0 : __isl_give isl_point *isl_point_restore_space(__isl_take isl_point *pnt,
     170             :         __isl_take isl_space *space)
     171             : {
     172           0 :         if (!pnt || !space)
     173             :                 goto error;
     174             : 
     175           0 :         if (pnt->dim == space) {
     176           0 :                 isl_space_free(space);
     177           0 :                 return pnt;
     178             :         }
     179             : 
     180           0 :         pnt = isl_point_cow(pnt);
     181           0 :         if (!pnt)
     182           0 :                 goto error;
     183           0 :         isl_space_free(pnt->dim);
     184           0 :         pnt->dim = space;
     185             : 
     186           0 :         return pnt;
     187             : error:
     188           0 :         isl_point_free(pnt);
     189           0 :         isl_space_free(space);
     190           0 :         return NULL;
     191             : }
     192             : 
     193             : /* Return the coordinate vector of "pnt".
     194             :  */
     195           0 : __isl_keep isl_vec *isl_point_peek_vec(__isl_keep isl_point *pnt)
     196             : {
     197           0 :         return pnt ? pnt->vec : NULL;
     198             : }
     199             : 
     200             : /* Return a copy of the coordinate vector of "pnt".
     201             :  */
     202           0 : __isl_give isl_vec *isl_point_get_vec(__isl_keep isl_point *pnt)
     203             : {
     204           0 :         return isl_vec_copy(isl_point_peek_vec(pnt));
     205             : }
     206             : 
     207             : /* Return the coordinate vector of "pnt".
     208             :  * This may be either a copy or the coordinate vector itself
     209             :  * if there is only one reference to "pnt".
     210             :  * This allows the coordinate vector to be modified inplace
     211             :  * if both the point and its coordinate vector have only a single reference.
     212             :  * The caller is not allowed to modify "pnt" between this call and
     213             :  * a subsequent call to isl_point_restore_vec.
     214             :  * The only exception is that isl_point_free can be called instead.
     215             :  */
     216           0 : __isl_give isl_vec *isl_point_take_vec(__isl_keep isl_point *pnt)
     217             : {
     218             :         isl_vec *vec;
     219             : 
     220           0 :         if (!pnt)
     221           0 :                 return NULL;
     222           0 :         if (pnt->ref != 1)
     223           0 :                 return isl_point_get_vec(pnt);
     224           0 :         vec = pnt->vec;
     225           0 :         pnt->vec = NULL;
     226           0 :         return vec;
     227             : }
     228             : 
     229             : /* Set the coordinate vector of "pnt" to "vec",
     230             :  * where the coordinate vector of "pnt" may be missing
     231             :  * due to a preceding call to isl_point_take_vec.
     232             :  * However, in this case, "pnt" only has a single reference and
     233             :  * then the call to isl_point_cow has no effect.
     234             :  */
     235           0 : __isl_give isl_point *isl_point_restore_vec(__isl_take isl_point *pnt,
     236             :         __isl_take isl_vec *vec)
     237             : {
     238           0 :         if (!pnt || !vec)
     239             :                 goto error;
     240             : 
     241           0 :         if (pnt->vec == vec) {
     242           0 :                 isl_vec_free(vec);
     243           0 :                 return pnt;
     244             :         }
     245             : 
     246           0 :         pnt = isl_point_cow(pnt);
     247           0 :         if (!pnt)
     248           0 :                 goto error;
     249           0 :         isl_vec_free(pnt->vec);
     250           0 :         pnt->vec = vec;
     251             : 
     252           0 :         return pnt;
     253             : error:
     254           0 :         isl_point_free(pnt);
     255           0 :         isl_vec_free(vec);
     256           0 :         return NULL;
     257             : }
     258             : 
     259             : /* Return the value of coordinate "pos" of type "type" of "pnt".
     260             :  */
     261           0 : __isl_give isl_val *isl_point_get_coordinate_val(__isl_keep isl_point *pnt,
     262             :         enum isl_dim_type type, int pos)
     263             : {
     264             :         isl_ctx *ctx;
     265             :         isl_val *v;
     266             : 
     267           0 :         if (!pnt)
     268           0 :                 return NULL;
     269             : 
     270           0 :         ctx = isl_point_get_ctx(pnt);
     271           0 :         if (isl_point_is_void(pnt))
     272           0 :                 isl_die(ctx, isl_error_invalid,
     273             :                         "void point does not have coordinates", return NULL);
     274           0 :         if (pos < 0 || pos >= isl_space_dim(pnt->dim, type))
     275           0 :                 isl_die(ctx, isl_error_invalid,
     276             :                         "position out of bounds", return NULL);
     277             : 
     278           0 :         if (type == isl_dim_set)
     279           0 :                 pos += isl_space_dim(pnt->dim, isl_dim_param);
     280             : 
     281           0 :         v = isl_val_rat_from_isl_int(ctx, pnt->vec->el[1 + pos],
     282           0 :                                                 pnt->vec->el[0]);
     283           0 :         return isl_val_normalize(v);
     284             : }
     285             : 
     286             : /* Replace coordinate "pos" of type "type" of "pnt" by "v".
     287             :  */
     288     3054144 : __isl_give isl_point *isl_point_set_coordinate_val(__isl_take isl_point *pnt,
     289             :         enum isl_dim_type type, int pos, __isl_take isl_val *v)
     290             : {
     291     3054144 :         if (!pnt || !v)
     292             :                 goto error;
     293     3054144 :         if (isl_point_is_void(pnt))
     294           0 :                 isl_die(isl_point_get_ctx(pnt), isl_error_invalid,
     295             :                         "void point does not have coordinates", goto error);
     296     3054144 :         if (pos < 0 || pos >= isl_space_dim(pnt->dim, type))
     297           0 :                 isl_die(isl_point_get_ctx(pnt), isl_error_invalid,
     298             :                         "position out of bounds", goto error);
     299     3054144 :         if (!isl_val_is_rat(v))
     300           0 :                 isl_die(isl_point_get_ctx(pnt), isl_error_invalid,
     301             :                         "expecting rational value", goto error);
     302             : 
     303     3054144 :         pos += isl_space_offset(isl_point_peek_space(pnt), type);
     304     4151279 :         if (isl_int_eq(pnt->vec->el[1 + pos], v->n) &&
     305     1097135 :             isl_int_eq(pnt->vec->el[0], v->d)) {
     306     1097135 :                 isl_val_free(v);
     307     1097135 :                 return pnt;
     308             :         }
     309             : 
     310     1957009 :         pnt = isl_point_cow(pnt);
     311     1957009 :         if (!pnt)
     312           0 :                 goto error;
     313     1957009 :         pnt->vec = isl_vec_cow(pnt->vec);
     314     1957009 :         if (!pnt->vec)
     315           0 :                 goto error;
     316             : 
     317     1957009 :         if (isl_int_eq(pnt->vec->el[0], v->d)) {
     318     1957009 :                 isl_int_set(pnt->vec->el[1 + pos], v->n);
     319           0 :         } else if (isl_int_is_one(v->d)) {
     320           0 :                 isl_int_mul(pnt->vec->el[1 + pos], pnt->vec->el[0], v->n);
     321             :         } else {
     322           0 :                 isl_seq_scale(pnt->vec->el + 1,
     323           0 :                                 pnt->vec->el + 1, v->d, pnt->vec->size - 1);
     324           0 :                 isl_int_mul(pnt->vec->el[1 + pos], pnt->vec->el[0], v->n);
     325           0 :                 isl_int_mul(pnt->vec->el[0], pnt->vec->el[0], v->d);
     326           0 :                 pnt->vec = isl_vec_normalize(pnt->vec);
     327           0 :                 if (!pnt->vec)
     328           0 :                         goto error;
     329             :         }
     330             : 
     331     1957009 :         isl_val_free(v);
     332     1957009 :         return pnt;
     333             : error:
     334           0 :         isl_val_free(v);
     335           0 :         isl_point_free(pnt);
     336           0 :         return NULL;
     337             : }
     338             : 
     339           0 : __isl_give isl_point *isl_point_add_ui(__isl_take isl_point *pnt,
     340             :         enum isl_dim_type type, int pos, unsigned val)
     341             : {
     342           0 :         if (!pnt || isl_point_is_void(pnt))
     343           0 :                 return pnt;
     344             : 
     345           0 :         pnt = isl_point_cow(pnt);
     346           0 :         if (!pnt)
     347           0 :                 return NULL;
     348           0 :         pnt->vec = isl_vec_cow(pnt->vec);
     349           0 :         if (!pnt->vec)
     350           0 :                 goto error;
     351             : 
     352           0 :         if (type == isl_dim_set)
     353           0 :                 pos += isl_space_dim(pnt->dim, isl_dim_param);
     354             : 
     355           0 :         isl_int_add_ui(pnt->vec->el[1 + pos], pnt->vec->el[1 + pos], val);
     356             : 
     357           0 :         return pnt;
     358             : error:
     359           0 :         isl_point_free(pnt);
     360           0 :         return NULL;
     361             : }
     362             : 
     363           0 : __isl_give isl_point *isl_point_sub_ui(__isl_take isl_point *pnt,
     364             :         enum isl_dim_type type, int pos, unsigned val)
     365             : {
     366           0 :         if (!pnt || isl_point_is_void(pnt))
     367           0 :                 return pnt;
     368             : 
     369           0 :         pnt = isl_point_cow(pnt);
     370           0 :         if (!pnt)
     371           0 :                 return NULL;
     372           0 :         pnt->vec = isl_vec_cow(pnt->vec);
     373           0 :         if (!pnt->vec)
     374           0 :                 goto error;
     375             : 
     376           0 :         if (type == isl_dim_set)
     377           0 :                 pos += isl_space_dim(pnt->dim, isl_dim_param);
     378             : 
     379           0 :         isl_int_sub_ui(pnt->vec->el[1 + pos], pnt->vec->el[1 + pos], val);
     380             : 
     381           0 :         return pnt;
     382             : error:
     383           0 :         isl_point_free(pnt);
     384           0 :         return NULL;
     385             : }
     386             : 
     387             : struct isl_foreach_point {
     388             :         struct isl_scan_callback callback;
     389             :         isl_stat (*fn)(__isl_take isl_point *pnt, void *user);
     390             :         void *user;
     391             :         isl_space *dim;
     392             : };
     393             : 
     394           0 : static isl_stat foreach_point(struct isl_scan_callback *cb,
     395             :         __isl_take isl_vec *sample)
     396             : {
     397           0 :         struct isl_foreach_point *fp = (struct isl_foreach_point *)cb;
     398             :         isl_point *pnt;
     399             : 
     400           0 :         pnt = isl_point_alloc(isl_space_copy(fp->dim), sample);
     401             : 
     402           0 :         return fp->fn(pnt, fp->user);
     403             : }
     404             : 
     405           0 : isl_stat isl_set_foreach_point(__isl_keep isl_set *set,
     406             :         isl_stat (*fn)(__isl_take isl_point *pnt, void *user), void *user)
     407             : {
     408           0 :         struct isl_foreach_point fp = { { &foreach_point }, fn, user };
     409             :         int i;
     410             : 
     411           0 :         if (!set)
     412           0 :                 return isl_stat_error;
     413             : 
     414           0 :         fp.dim = isl_set_get_space(set);
     415           0 :         if (!fp.dim)
     416           0 :                 return isl_stat_error;
     417             : 
     418           0 :         set = isl_set_copy(set);
     419           0 :         set = isl_set_cow(set);
     420           0 :         set = isl_set_make_disjoint(set);
     421           0 :         set = isl_set_compute_divs(set);
     422           0 :         if (!set)
     423           0 :                 goto error;
     424             : 
     425           0 :         for (i = 0; i < set->n; ++i)
     426           0 :                 if (isl_basic_set_scan(isl_basic_set_copy(set->p[i]),
     427             :                                         &fp.callback) < 0)
     428           0 :                         goto error;
     429             : 
     430           0 :         isl_set_free(set);
     431           0 :         isl_space_free(fp.dim);
     432             : 
     433           0 :         return isl_stat_ok;
     434             : error:
     435           0 :         isl_set_free(set);
     436           0 :         isl_space_free(fp.dim);
     437           0 :         return isl_stat_error;
     438             : }
     439             : 
     440             : /* Return 1 if "bmap" contains the point "point".
     441             :  * "bmap" is assumed to have known divs.
     442             :  * The point is first extended with the divs and then passed
     443             :  * to basic_map_contains.
     444             :  */
     445          44 : isl_bool isl_basic_map_contains_point(__isl_keep isl_basic_map *bmap,
     446             :         __isl_keep isl_point *point)
     447             : {
     448             :         int i;
     449             :         struct isl_vec *vec;
     450             :         unsigned dim;
     451             :         isl_bool contains;
     452             : 
     453          44 :         if (!bmap || !point)
     454           0 :                 return isl_bool_error;
     455          44 :         isl_assert(bmap->ctx, isl_space_is_equal(bmap->dim, point->dim),
     456             :                 return isl_bool_error);
     457          44 :         if (bmap->n_div == 0)
     458          44 :                 return isl_basic_map_contains(bmap, point->vec);
     459             : 
     460           0 :         dim = isl_basic_map_total_dim(bmap) - bmap->n_div;
     461           0 :         vec = isl_vec_alloc(bmap->ctx, 1 + dim + bmap->n_div);
     462           0 :         if (!vec)
     463           0 :                 return isl_bool_error;
     464             : 
     465           0 :         isl_seq_cpy(vec->el, point->vec->el, point->vec->size);
     466           0 :         for (i = 0; i < bmap->n_div; ++i) {
     467           0 :                 isl_seq_inner_product(bmap->div[i] + 1, vec->el,
     468           0 :                                         1 + dim + i, &vec->el[1+dim+i]);
     469           0 :                 isl_int_fdiv_q(vec->el[1+dim+i], vec->el[1+dim+i],
     470             :                                 bmap->div[i][0]);
     471             :         }
     472             : 
     473           0 :         contains = isl_basic_map_contains(bmap, vec);
     474             : 
     475           0 :         isl_vec_free(vec);
     476           0 :         return contains;
     477             : }
     478             : 
     479           0 : isl_bool isl_map_contains_point(__isl_keep isl_map *map,
     480             :         __isl_keep isl_point *point)
     481             : {
     482             :         int i;
     483           0 :         isl_bool found = isl_bool_false;
     484             : 
     485           0 :         if (!map || !point)
     486           0 :                 return isl_bool_error;
     487             : 
     488           0 :         map = isl_map_copy(map);
     489           0 :         map = isl_map_compute_divs(map);
     490           0 :         if (!map)
     491           0 :                 return isl_bool_error;
     492             : 
     493           0 :         for (i = 0; i < map->n; ++i) {
     494           0 :                 found = isl_basic_map_contains_point(map->p[i], point);
     495           0 :                 if (found < 0)
     496           0 :                         goto error;
     497           0 :                 if (found)
     498           0 :                         break;
     499             :         }
     500           0 :         isl_map_free(map);
     501             : 
     502           0 :         return found;
     503             : error:
     504           0 :         isl_map_free(map);
     505           0 :         return isl_bool_error;
     506             : }
     507             : 
     508           0 : isl_bool isl_set_contains_point(__isl_keep isl_set *set,
     509             :         __isl_keep isl_point *point)
     510             : {
     511           0 :         return isl_map_contains_point(set_to_map(set), point);
     512             : }
     513             : 
     514     1395369 : __isl_give isl_basic_set *isl_basic_set_from_point(__isl_take isl_point *pnt)
     515             : {
     516             :         isl_basic_set *bset;
     517             :         isl_basic_set *model;
     518             : 
     519     1395369 :         if (!pnt)
     520           0 :                 return NULL;
     521             : 
     522     1395369 :         model = isl_basic_set_empty(isl_space_copy(pnt->dim));
     523     1395369 :         bset = isl_basic_set_from_vec(isl_vec_copy(pnt->vec));
     524     1395369 :         bset = isl_basic_set_from_underlying_set(bset, model);
     525     1395369 :         isl_point_free(pnt);
     526             : 
     527     1395369 :         return bset;
     528             : }
     529             : 
     530     1395369 : __isl_give isl_set *isl_set_from_point(__isl_take isl_point *pnt)
     531             : {
     532             :         isl_basic_set *bset;
     533     1395369 :         bset = isl_basic_set_from_point(pnt);
     534     1395369 :         return isl_set_from_basic_set(bset);
     535             : }
     536             : 
     537             : /* Construct a union set, containing the single element "pnt".
     538             :  * If "pnt" is void, then return an empty union set.
     539             :  */
     540           0 : __isl_give isl_union_set *isl_union_set_from_point(__isl_take isl_point *pnt)
     541             : {
     542           0 :         if (!pnt)
     543           0 :                 return NULL;
     544           0 :         if (isl_point_is_void(pnt)) {
     545             :                 isl_space *space;
     546             : 
     547           0 :                 space = isl_point_get_space(pnt);
     548           0 :                 isl_point_free(pnt);
     549           0 :                 return isl_union_set_empty(space);
     550             :         }
     551             : 
     552           0 :         return isl_union_set_from_set(isl_set_from_point(pnt));
     553             : }
     554             : 
     555           0 : __isl_give isl_basic_set *isl_basic_set_box_from_points(
     556             :         __isl_take isl_point *pnt1, __isl_take isl_point *pnt2)
     557             : {
     558           0 :         isl_basic_set *bset = NULL;
     559             :         unsigned total;
     560             :         int i;
     561             :         int k;
     562             :         isl_int t;
     563             : 
     564           0 :         isl_int_init(t);
     565             : 
     566           0 :         if (!pnt1 || !pnt2)
     567             :                 goto error;
     568             : 
     569           0 :         isl_assert(pnt1->dim->ctx,
     570             :                         isl_space_is_equal(pnt1->dim, pnt2->dim), goto error);
     571             : 
     572           0 :         if (isl_point_is_void(pnt1) && isl_point_is_void(pnt2)) {
     573           0 :                 isl_space *dim = isl_space_copy(pnt1->dim);
     574           0 :                 isl_point_free(pnt1);
     575           0 :                 isl_point_free(pnt2);
     576           0 :                 isl_int_clear(t);
     577           0 :                 return isl_basic_set_empty(dim);
     578             :         }
     579           0 :         if (isl_point_is_void(pnt1)) {
     580           0 :                 isl_point_free(pnt1);
     581           0 :                 isl_int_clear(t);
     582           0 :                 return isl_basic_set_from_point(pnt2);
     583             :         }
     584           0 :         if (isl_point_is_void(pnt2)) {
     585           0 :                 isl_point_free(pnt2);
     586           0 :                 isl_int_clear(t);
     587           0 :                 return isl_basic_set_from_point(pnt1);
     588             :         }
     589             : 
     590           0 :         total = isl_space_dim(pnt1->dim, isl_dim_all);
     591           0 :         bset = isl_basic_set_alloc_space(isl_space_copy(pnt1->dim), 0, 0, 2 * total);
     592             : 
     593           0 :         for (i = 0; i < total; ++i) {
     594           0 :                 isl_int_mul(t, pnt1->vec->el[1 + i], pnt2->vec->el[0]);
     595           0 :                 isl_int_submul(t, pnt2->vec->el[1 + i], pnt1->vec->el[0]);
     596             : 
     597           0 :                 k = isl_basic_set_alloc_inequality(bset);
     598           0 :                 if (k < 0)
     599           0 :                         goto error;
     600           0 :                 isl_seq_clr(bset->ineq[k] + 1, total);
     601           0 :                 if (isl_int_is_pos(t)) {
     602           0 :                         isl_int_set_si(bset->ineq[k][1 + i], -1);
     603           0 :                         isl_int_set(bset->ineq[k][0], pnt1->vec->el[1 + i]);
     604             :                 } else {
     605           0 :                         isl_int_set_si(bset->ineq[k][1 + i], 1);
     606           0 :                         isl_int_neg(bset->ineq[k][0], pnt1->vec->el[1 + i]);
     607             :                 }
     608           0 :                 isl_int_fdiv_q(bset->ineq[k][0], bset->ineq[k][0], pnt1->vec->el[0]);
     609             : 
     610           0 :                 k = isl_basic_set_alloc_inequality(bset);
     611           0 :                 if (k < 0)
     612           0 :                         goto error;
     613           0 :                 isl_seq_clr(bset->ineq[k] + 1, total);
     614           0 :                 if (isl_int_is_pos(t)) {
     615           0 :                         isl_int_set_si(bset->ineq[k][1 + i], 1);
     616           0 :                         isl_int_neg(bset->ineq[k][0], pnt2->vec->el[1 + i]);
     617             :                 } else {
     618           0 :                         isl_int_set_si(bset->ineq[k][1 + i], -1);
     619           0 :                         isl_int_set(bset->ineq[k][0], pnt2->vec->el[1 + i]);
     620             :                 }
     621           0 :                 isl_int_fdiv_q(bset->ineq[k][0], bset->ineq[k][0], pnt2->vec->el[0]);
     622             :         }
     623             : 
     624           0 :         bset = isl_basic_set_finalize(bset);
     625             : 
     626           0 :         isl_point_free(pnt1);
     627           0 :         isl_point_free(pnt2);
     628             : 
     629           0 :         isl_int_clear(t);
     630             : 
     631           0 :         return bset;
     632             : error:
     633           0 :         isl_point_free(pnt1);
     634           0 :         isl_point_free(pnt2);
     635           0 :         isl_int_clear(t);
     636           0 :         isl_basic_set_free(bset);
     637           0 :         return NULL;
     638             : }
     639             : 
     640           0 : __isl_give isl_set *isl_set_box_from_points(__isl_take isl_point *pnt1,
     641             :         __isl_take isl_point *pnt2)
     642             : {
     643             :         isl_basic_set *bset;
     644           0 :         bset = isl_basic_set_box_from_points(pnt1, pnt2);
     645           0 :         return isl_set_from_basic_set(bset);
     646             : }
     647             : 
     648             : /* Print the coordinate at position "pos" of the point "pnt".
     649             :  */
     650           0 : static __isl_give isl_printer *print_coordinate(__isl_take isl_printer *p,
     651             :         struct isl_print_space_data *data, unsigned pos)
     652             : {
     653           0 :         isl_point *pnt = data->user;
     654             : 
     655           0 :         pos += isl_space_offset(data->space, data->type);
     656           0 :         p = isl_printer_print_isl_int(p, pnt->vec->el[1 + pos]);
     657           0 :         if (!isl_int_is_one(pnt->vec->el[0])) {
     658           0 :                 p = isl_printer_print_str(p, "/");
     659           0 :                 p = isl_printer_print_isl_int(p, pnt->vec->el[0]);
     660             :         }
     661             : 
     662           0 :         return p;
     663             : }
     664             : 
     665           0 : __isl_give isl_printer *isl_printer_print_point(
     666             :         __isl_take isl_printer *p, __isl_keep isl_point *pnt)
     667             : {
     668           0 :         struct isl_print_space_data data = { 0 };
     669             :         int i;
     670             :         unsigned nparam;
     671             : 
     672           0 :         if (!pnt)
     673           0 :                 return p;
     674           0 :         if (isl_point_is_void(pnt)) {
     675           0 :                 p = isl_printer_print_str(p, "void");
     676           0 :                 return p;
     677             :         }
     678             : 
     679           0 :         nparam = isl_space_dim(pnt->dim, isl_dim_param);
     680           0 :         if (nparam > 0) {
     681           0 :                 p = isl_printer_print_str(p, "[");
     682           0 :                 for (i = 0; i < nparam; ++i) {
     683             :                         const char *name;
     684           0 :                         if (i)
     685           0 :                                 p = isl_printer_print_str(p, ", ");
     686           0 :                         name = isl_space_get_dim_name(pnt->dim, isl_dim_param, i);
     687           0 :                         if (name) {
     688           0 :                                 p = isl_printer_print_str(p, name);
     689           0 :                                 p = isl_printer_print_str(p, " = ");
     690             :                         }
     691           0 :                         p = isl_printer_print_isl_int(p, pnt->vec->el[1 + i]);
     692           0 :                         if (!isl_int_is_one(pnt->vec->el[0])) {
     693           0 :                                 p = isl_printer_print_str(p, "/");
     694           0 :                                 p = isl_printer_print_isl_int(p, pnt->vec->el[0]);
     695             :                         }
     696             :                 }
     697           0 :                 p = isl_printer_print_str(p, "]");
     698           0 :                 p = isl_printer_print_str(p, " -> ");
     699             :         }
     700           0 :         data.print_dim = &print_coordinate;
     701           0 :         data.user = pnt;
     702           0 :         p = isl_printer_print_str(p, "{ ");
     703           0 :         p = isl_print_space(pnt->dim, p, 0, &data);
     704           0 :         p = isl_printer_print_str(p, " }");
     705           0 :         return p;
     706             : }

Generated by: LCOV version 1.12