-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint_list.c
38 lines (34 loc) · 851 Bytes
/
point_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <grass/gis.h>
#include <grass/glocale.h>
#include "global.h"
void init_point_list(struct point_list *pl)
{
pl->nalloc = pl->n = 0;
pl->x = pl->y = NULL;
}
void reset_point_list(struct point_list *pl)
{
pl->n = 0;
}
void free_point_list(struct point_list *pl)
{
if (pl->x)
G_free(pl->x);
if (pl->y)
G_free(pl->y);
init_point_list(pl);
}
/* adapted from r.path */
void add_point(struct point_list *pl, double x, double y)
{
if (pl->n == pl->nalloc) {
pl->nalloc += REALLOC_INCREMENT;
pl->x = (double *)G_realloc(pl->x, pl->nalloc * sizeof(double));
pl->y = (double *)G_realloc(pl->y, pl->nalloc * sizeof(double));
if (!pl->x || !pl->y)
G_fatal_error(_("Unable to increase point list"));
}
pl->x[pl->n] = x;
pl->y[pl->n] = y;
pl->n++;
}