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

« back to all changes in this revision

Viewing changes to lib/vector/diglib/plus_line.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:
14
14
 * \date 2001-2008
15
15
 */
16
16
 
 
17
#include <sys/types.h>
17
18
#include <stdlib.h>
18
 
#include <grass/Vect.h>
 
19
#include <grass/vector.h>
19
20
 
20
 
static int add_line(struct Plus_head *plus, int lineid, int type, struct line_pnts *Points,
21
 
                    long offset)
 
21
static int add_line(struct Plus_head *plus, int lineid, int type, const struct line_pnts *Points,
 
22
                    const struct bound_box *box, off_t offset)
22
23
{
23
 
    int node, lp;
24
 
    P_LINE *line;
25
 
    BOUND_BOX box;
 
24
    int node, lp, node_new;
 
25
    struct P_line *line;
26
26
 
27
27
    plus->Line[lineid] = dig_alloc_line();
28
28
    line = plus->Line[lineid];
29
29
 
30
 
    /* Add nodes */
 
30
    line->type = type;
 
31
    line->offset = offset;
 
32
 
 
33
    dig_spidx_add_line(plus, lineid, box);
 
34
    if (plus->uplist.do_uplist) {
 
35
        dig_line_add_updated(plus, lineid, offset);
 
36
    }
 
37
    
 
38
    if (type & GV_POINT) {
 
39
        line->topo = NULL;
 
40
        return (lineid);
 
41
    }
 
42
    
 
43
    line->topo = dig_alloc_topo(type);
 
44
 
 
45
    if (type & GV_CENTROID) {
 
46
        struct P_topo_c *topo = (struct P_topo_c *)line->topo;
 
47
 
 
48
        topo->area = 0;
 
49
        return (lineid);
 
50
    }
 
51
 
 
52
    /* Add nodes for lines */
31
53
    G_debug(3, "Register node: type = %d,  %f,%f", type, Points->x[0],
32
54
            Points->y[0]);
33
55
 
 
56
    /* Start node */
34
57
    node = dig_find_node(plus, Points->x[0], Points->y[0], Points->z[0]);
35
58
    G_debug(3, "node = %d", node);
36
59
    if (node == 0) {
37
60
        node = dig_add_node(plus, Points->x[0], Points->y[0], Points->z[0]);
38
61
        G_debug(3, "Add new node: %d", node);
 
62
        node_new = TRUE;
 
63
    }
 
64
    else {
 
65
        G_debug(3, "Old node found: %d", node);
 
66
        node_new = FALSE;
 
67
    }
 
68
    
 
69
    if (type == GV_LINE) {
 
70
        struct P_topo_l *topo = (struct P_topo_l *)line->topo;
 
71
 
 
72
        topo->N1 = node;
 
73
        topo->N2 = 0;
 
74
    }
 
75
    else if (type == GV_BOUNDARY) {
 
76
        struct P_topo_b *topo = (struct P_topo_b *)line->topo;
 
77
 
 
78
        topo->N1 = node;
 
79
        topo->N2 = 0;
 
80
        topo->left = 0;
 
81
        topo->right = 0;
 
82
    }
 
83
 
 
84
    dig_node_add_line(plus, node, lineid, Points, type);
 
85
    if (plus->uplist.do_uplist)
 
86
        dig_node_add_updated(plus, node_new ? -node : node);
 
87
 
 
88
    /* End node */
 
89
    lp = Points->n_points - 1;
 
90
    G_debug(3, "Register node %f,%f", Points->x[lp], Points->y[lp]);
 
91
    node = dig_find_node(plus, Points->x[lp], Points->y[lp],
 
92
                         Points->z[lp]);
 
93
    G_debug(3, "node = %d", node);
 
94
    if (node == 0) {
 
95
        node = dig_add_node(plus, Points->x[lp], Points->y[lp],
 
96
                            Points->z[lp]);
 
97
        G_debug(3, "Add new node: %d", node);
 
98
        node_new = TRUE;
39
99
    }
40
100
    else {
41
101
        G_debug(3, "Old node found: %d", node);
42
 
    }
43
 
    line->N1 = node;
44
 
    dig_node_add_line(plus, node, lineid, Points, type);
45
 
    if (plus->do_uplist)
46
 
        dig_node_add_updated(plus, node);
47
 
 
48
 
    if (type & GV_LINES) {
49
 
        lp = Points->n_points - 1;
50
 
        G_debug(3, "Register node %f,%f", Points->x[lp], Points->y[lp]);
51
 
        node =
52
 
            dig_find_node(plus, Points->x[lp], Points->y[lp], Points->z[lp]);
53
 
        G_debug(3, "node = %d", node);
54
 
        if (node == 0) {
55
 
            node =
56
 
                dig_add_node(plus, Points->x[lp], Points->y[lp],
57
 
                             Points->z[lp]);
58
 
            G_debug(3, "Add new node: %d", node);
59
 
        }
60
 
        else {
61
 
            G_debug(3, "Old node found: %d", node);
62
 
        }
63
 
        line->N2 = node;
64
 
        dig_node_add_line(plus, node, -lineid, Points, type);
65
 
        if (plus->do_uplist)
66
 
            dig_node_add_updated(plus, node);
67
 
    }
68
 
    else {
69
 
        line->N2 = 0;
70
 
    }
71
 
 
72
 
    line->type = type;
73
 
    line->offset = offset;
74
 
    line->left = 0;
75
 
    line->right = 0;
76
 
    line->N = 0;
77
 
    line->S = 0;
78
 
    line->E = 0;
79
 
    line->W = 0;
80
 
 
81
 
    dig_line_box(Points, &box);
82
 
    dig_line_set_box(plus, lineid, &box);
83
 
    dig_spidx_add_line(plus, lineid, &box);
84
 
    if (plus->do_uplist)
85
 
        dig_line_add_updated(plus, lineid);
 
102
        node_new = FALSE;
 
103
    }
 
104
    if (type == GV_LINE) {
 
105
        struct P_topo_l *topo = (struct P_topo_l *)line->topo;
 
106
 
 
107
        topo->N2 = node;
 
108
    }
 
109
    else if (type == GV_BOUNDARY) {
 
110
        struct P_topo_b *topo = (struct P_topo_b *)line->topo;
 
111
 
 
112
        topo->N2 = node;
 
113
    }
 
114
 
 
115
    dig_node_add_line(plus, node, -lineid, Points, type);
 
116
    if (plus->uplist.do_uplist)
 
117
        dig_node_add_updated(plus, node_new ? -node : node);
86
118
 
87
119
    return (lineid);
88
120
}
91
123
 * \brief Add new line to Plus_head structure.
92
124
 *
93
125
 * \param[in,out] plus pointer to Plus_head structure
94
 
 * \param[in] type feature type
95
 
 * \param[in] Points line geometry
96
 
 * \param[in] offset line offset
 
126
 * \param type feature type
 
127
 * \param Points line geometry
 
128
 * \param box bounding box
 
129
 * \param offset line offset
97
130
 *
98
131
 * \return -1 on error      
99
132
 * \return line id
100
133
 */
101
134
int
102
 
dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points,
103
 
             long offset)
 
135
dig_add_line(struct Plus_head *plus, int type, const struct line_pnts *Points,
 
136
             const struct bound_box *box, off_t offset)
104
137
{
105
138
    int ret;
106
139
    
111
144
            return -1;
112
145
    }
113
146
 
114
 
    ret = add_line(plus, plus->n_lines + 1, type, Points, offset);
 
147
    ret = add_line(plus, plus->n_lines + 1, type, Points, box, offset);
115
148
 
116
149
    if (ret == -1)
117
150
        return ret;
146
179
 * \brief Restore line in Plus_head structure.
147
180
 *
148
181
 * \param[in,out] plus pointer to Plus_head structure
149
 
 * \param[in] type feature type
150
 
 * \param[in] Points line geometry
151
 
 * \param[in] offset line offset
 
182
 * \param type feature type
 
183
 * \param Points line geometry
 
184
 * \param box bounding box
 
185
 * \param offset line offset
152
186
 *
153
187
 * \return -1 on error      
154
188
 * \return line id
155
189
 */
156
190
int
157
191
dig_restore_line(struct Plus_head *plus, int lineid,
158
 
                 int type, struct line_pnts *Points,
159
 
                 long offset)
 
192
                 int type, const struct line_pnts *Points,
 
193
                 const struct bound_box *box, off_t offset)
160
194
{
161
195
    if (lineid < 1 || lineid > plus->n_lines) {
162
196
        return -1;
163
197
    }
164
198
 
165
 
    return add_line(plus, lineid, type, Points, offset);    
 
199
    return add_line(plus, lineid, type, Points, box, offset);    
166
200
}
167
201
 
168
202
/*!
175
209
 *
176
210
 * \param[in,out] plus pointer to Plus_head structure
177
211
 * \param[in] line line id
 
212
 * \param[in] x,y,z coordinates
178
213
 *
179
214
 * \return -1 on error
180
215
 * \return  0 OK
181
216
 *
182
217
 */
183
 
int dig_del_line(struct Plus_head *plus, int line)
 
218
int dig_del_line(struct Plus_head *plus, int line, double x, double y, double z)
184
219
{
185
220
    int i, mv;
186
 
    P_LINE *Line;
187
 
    P_NODE *Node;
 
221
    plus_t N1 = 0, N2 = 0;
 
222
    struct P_line *Line;
 
223
    struct P_node *Node;
188
224
 
189
 
    /* TODO: free structures */
190
225
    G_debug(3, "dig_del_line() line =  %d", line);
191
226
 
192
227
    Line = plus->Line[line];
193
 
    dig_spidx_del_line(plus, line);
 
228
    dig_spidx_del_line(plus, line, x, y, z);
 
229
 
 
230
    if (plus->uplist.do_uplist) {
 
231
        dig_line_add_updated(plus, line, -Line->offset);
 
232
    }
 
233
    
 
234
    if (!(Line->type & GV_LINES)) {
 
235
        /* Delete line */
 
236
        dig_free_line(Line);
 
237
        plus->Line[line] = NULL;
 
238
 
 
239
        return 0;
 
240
    }
194
241
 
195
242
    /* Delete from nodes (and nodes) */
196
 
    Node = plus->Node[Line->N1];
197
 
    mv = 0;
198
 
    for (i = 0; i < Node->n_lines; i++) {
199
 
        if (mv) {
200
 
            Node->lines[i - 1] = Node->lines[i];
201
 
            Node->angles[i - 1] = Node->angles[i];
202
 
        }
203
 
        else {
204
 
            if (abs(Node->lines[i]) == line)
205
 
                mv = 1;
206
 
        }
207
 
    }
208
 
    Node->n_lines--;
209
 
    if (Node->n_lines == 0) {
210
 
        G_debug(3, "    node %d has 0 lines -> delete", Line->N1);
211
 
        dig_spidx_del_node(plus, Line->N1);
212
 
        plus->Node[Line->N1] = NULL;
213
 
    }
214
 
    else {
215
 
        if (plus->do_uplist)
216
 
            dig_node_add_updated(plus, Line->N1);
217
 
    }
218
 
 
219
 
    if (Line->type & GV_LINES) {
220
 
        Node = plus->Node[Line->N2];
221
 
        mv = 0;
222
 
        for (i = 0; i < Node->n_lines; i++) {
223
 
            if (mv) {
224
 
                Node->lines[i - 1] = Node->lines[i];
225
 
                Node->angles[i - 1] = Node->angles[i];
226
 
            }
227
 
            else {
228
 
                if (abs(Node->lines[i]) == line)
229
 
                    mv = 1;
230
 
            }
231
 
        }
232
 
        Node->n_lines--;
233
 
        if (Node->n_lines == 0) {
234
 
            G_debug(3, "    node %d has 0 lines -> delete", Line->N2);
235
 
            dig_spidx_del_node(plus, Line->N2);
236
 
            plus->Node[Line->N2] = NULL;
237
 
        }
238
 
        else {
239
 
            if (plus->do_uplist)
240
 
                dig_node_add_updated(plus, Line->N2);
241
 
        }
 
243
    if (Line->type == GV_LINE) {
 
244
        struct P_topo_l *topo = (struct P_topo_l *)Line->topo;
 
245
 
 
246
        N1 = topo->N1;
 
247
    }
 
248
    else if (Line->type == GV_BOUNDARY) {
 
249
        struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
 
250
 
 
251
        N1 = topo->N1;
 
252
    }
 
253
 
 
254
    Node = plus->Node[N1];
 
255
 
 
256
    mv = 0;
 
257
    for (i = 0; i < Node->n_lines; i++) {
 
258
        if (mv) {
 
259
            Node->lines[i - 1] = Node->lines[i];
 
260
            Node->angles[i - 1] = Node->angles[i];
 
261
        }
 
262
        else {
 
263
            if (Node->lines[i] == line)
 
264
                mv = 1;
 
265
        }
 
266
    }
 
267
    Node->n_lines--;
 
268
 
 
269
    if (plus->uplist.do_uplist) {
 
270
        dig_node_add_updated(plus, Node->n_lines > 0 ? N1 : -N1);
 
271
    }
 
272
    if (Node->n_lines == 0) {
 
273
        G_debug(3, "    node %d has 0 lines -> delete", N1);
 
274
        dig_spidx_del_node(plus, N1);
 
275
        /* free structures */
 
276
        dig_free_node(Node);
 
277
        plus->Node[N1] = NULL;
 
278
    }
 
279
    
 
280
    if (Line->type == GV_LINE) {
 
281
        struct P_topo_l *topo = (struct P_topo_l *)Line->topo;
 
282
 
 
283
        N2 = topo->N2;
 
284
    }
 
285
    else if (Line->type == GV_BOUNDARY) {
 
286
        struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
 
287
 
 
288
        N2 = topo->N2;
 
289
    }
 
290
 
 
291
    Node = plus->Node[N2];
 
292
    mv = 0;
 
293
    for (i = 0; i < Node->n_lines; i++) {
 
294
        if (mv) {
 
295
            Node->lines[i - 1] = Node->lines[i];
 
296
            Node->angles[i - 1] = Node->angles[i];
 
297
        }
 
298
        else {
 
299
            if (Node->lines[i] == -line)
 
300
                mv = 1;
 
301
        }
 
302
    }
 
303
    Node->n_lines--;
 
304
 
 
305
    if (plus->uplist.do_uplist) {
 
306
        dig_node_add_updated(plus, Node->n_lines > 0 ? N2 : -N2);
 
307
    }
 
308
    if (Node->n_lines == 0) {
 
309
        G_debug(3, "    node %d has 0 lines -> delete", N2);
 
310
        dig_spidx_del_node(plus, N2);
 
311
        /* free structures */
 
312
        dig_free_node(Node);
 
313
        plus->Node[N2] = NULL;
242
314
    }
243
315
 
244
316
    /* Delete line */
 
317
    dig_free_line(Line);
245
318
    plus->Line[line] = NULL;
246
319
 
247
320
    return 0;
260
333
 */
261
334
plus_t dig_line_get_area(struct Plus_head * plus, plus_t line, int side)
262
335
{
263
 
    P_LINE *Line;
 
336
    struct P_line *Line;
 
337
    struct P_topo_b *topo;
264
338
 
265
339
    Line = plus->Line[line];
 
340
    if (!Line) /* dead */
 
341
        return -1;
 
342
    
 
343
    if (Line->type != GV_BOUNDARY)
 
344
        return -1;
 
345
 
 
346
    topo = (struct P_topo_b *)Line->topo;
266
347
    if (side == GV_LEFT) {
267
348
        G_debug(3,
268
349
                "dig_line_get_area(): line = %d, side = %d (left), area = %d",
269
 
                line, side, Line->left);
270
 
        return (Line->left);
 
350
                line, side, topo->left);
 
351
        return (topo->left);
271
352
    }
272
353
    if (side == GV_RIGHT) {
273
354
        G_debug(3,
274
355
                "dig_line_get_area(): line = %d, side = %d (right), area = %d",
275
 
                line, side, Line->right);
 
356
                line, side, topo->right);
276
357
 
277
 
        return (Line->right);
 
358
        return (topo->right);
278
359
    }
279
360
 
280
361
    return (-1);
293
374
int
294
375
dig_line_set_area(struct Plus_head *plus, plus_t line, int side, plus_t area)
295
376
{
296
 
    P_LINE *Line;
 
377
    struct P_line *Line;
 
378
    struct P_topo_b *topo;
297
379
 
298
380
    Line = plus->Line[line];
 
381
    if (Line->type != GV_BOUNDARY)
 
382
        return (0);
 
383
 
 
384
    topo = (struct P_topo_b *)Line->topo;
 
385
 
299
386
    if (side == GV_LEFT) {
300
 
        Line->left = area;
 
387
        topo->left = area;
301
388
    }
302
389
    else if (side == GV_RIGHT) {
303
 
        Line->right = area;
 
390
        topo->right = area;
304
391
    }
305
392
 
306
393
    return (1);
315
402
 *
316
403
 * \return 1
317
404
 */
318
 
int dig_line_set_box(struct Plus_head *plus, plus_t line, BOUND_BOX * Box)
 
405
/*
 
406
int dig_line_set_box(struct Plus_head *plus, plus_t line, struct bound_box * Box)
319
407
{
320
 
    P_LINE *Line;
 
408
    struct P_line *Line;
321
409
 
322
410
    Line = plus->Line[line];
323
411
 
330
418
 
331
419
    return (1);
332
420
}
 
421
*/
333
422
 
334
423
/*!
335
424
 * \brief Get line bounding box saved in topo
340
429
 *
341
430
 * \return 1
342
431
 */
343
 
int dig_line_get_box(struct Plus_head *plus, plus_t line, BOUND_BOX * Box)
 
432
/*
 
433
int dig_line_get_box(struct Plus_head *plus, plus_t line, struct bound_box * Box)
344
434
{
345
 
    P_LINE *Line;
 
435
    struct P_line *Line;
346
436
 
347
437
    Line = plus->Line[line];
348
438
 
355
445
 
356
446
    return (1);
357
447
}
 
448
*/