~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/driver/path.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <grass/gis.h>
 
3
#include "path.h"
 
4
 
 
5
void path_init(struct path *p)
 
6
{
 
7
    p->vertices = NULL;
 
8
    p->count = 0;
 
9
    p->alloc = 0;
 
10
    p->start = -1;
 
11
}
 
12
 
 
13
void path_free(struct path *p)
 
14
{
 
15
    if (p->vertices)
 
16
        G_free(p->vertices);
 
17
 
 
18
    p->count = 0;
 
19
    p->alloc = 0;
 
20
    p->start = -1;
 
21
}
 
22
 
 
23
void path_alloc(struct path *p, int n)
 
24
{
 
25
    if (p->alloc >= n)
 
26
        return;
 
27
 
 
28
    p->alloc = n;
 
29
    p->vertices = G_realloc(p->vertices, p->alloc * sizeof(struct vertex));
 
30
}
 
31
 
 
32
void path_reset(struct path *p)
 
33
{
 
34
    p->count = 0;
 
35
    p->start = -1;
 
36
}
 
37
 
 
38
void path_append(struct path *p, double x, double y, int mode)
 
39
{
 
40
    struct vertex *v;
 
41
 
 
42
    if (p->count >= p->alloc)
 
43
        path_alloc(p, p->alloc ? p->alloc * 2 : 100);
 
44
 
 
45
    v = &p->vertices[p->count++];
 
46
 
 
47
    v->x = x;
 
48
    v->y = y;
 
49
    v->mode = mode;
 
50
}
 
51
 
 
52
void path_copy(struct path *dst, const struct path *src)
 
53
{
 
54
    int i;
 
55
 
 
56
    path_reset(dst);
 
57
    path_alloc(dst, src->count);
 
58
 
 
59
    for (i = 0; i < src->count; i++) {
 
60
        struct vertex *v = &src->vertices[i];
 
61
        path_append(dst, v->x, v->y, v->mode);
 
62
    }
 
63
 
 
64
    dst->start = src->start;
 
65
}
 
66
 
 
67
void path_begin(struct path *p)
 
68
{
 
69
    p->count = 0;
 
70
    p->start = -1;
 
71
}
 
72
 
 
73
void path_move(struct path *p, double x, double y)
 
74
{
 
75
    p->start = p->count;
 
76
    path_append(p, x, y, P_MOVE);
 
77
}
 
78
 
 
79
void path_cont(struct path *p, double x, double y)
 
80
{
 
81
    path_append(p, x, y, P_CONT);
 
82
}
 
83
 
 
84
void path_close(struct path *p)
 
85
{
 
86
    struct vertex *v;
 
87
 
 
88
    if (p->start < 0)
 
89
        return;
 
90
 
 
91
    v = &p->vertices[p->start];
 
92
    path_append(p, v->x, v->y, P_CLOSE);
 
93
 
 
94
    p->start = -1;
 
95
}
 
96
 
 
97
void path_stroke(struct path *p, void (*line)(double, double, double, double))
 
98
{
 
99
    int i;
 
100
 
 
101
    for (i = 1; i < p->count; i++) {
 
102
        struct vertex *v0 = &p->vertices[i-1];
 
103
        struct vertex *v1 = &p->vertices[i];
 
104
 
 
105
        if (v1->mode != P_MOVE)
 
106
            (*line)(v0->x, v0->y, v1->x, v1->y);
 
107
    }
 
108
 
 
109
    path_reset(p);
 
110
}
 
111