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