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

« back to all changes in this revision

Viewing changes to vector/v.delaunay2/memory.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
 
 *
3
 
 * MODULE:       v.delaunay
4
 
 *
5
 
 * AUTHOR(S):    Martin Pavlovsky (Google SoC 2008, Paul Kelly mentor)
6
 
 *               Based on "dct" by Geoff Leach, Department of Computer 
7
 
 *               Science, RMIT.
8
 
 *
9
 
 * PURPOSE:      Creates a Delaunay triangulation vector map
10
 
 *
11
 
 * COPYRIGHT:    (C) RMIT 1993
12
 
 *               (C) 2008-2009 by the GRASS Development Team
13
 
 *
14
 
 *               This program is free software under the GNU General
15
 
 *               Public License (>=v2).  Read the file COPYING that
16
 
 *               comes with GRASS for details.
17
 
 * 
18
 
 * The following notices apply to portions of the code originally
19
 
 * derived from work by Geoff Leach of RMIT:
20
 
 *
21
 
 *   Author: Geoff Leach, Department of Computer Science, RMIT.
22
 
 *   email: gl@cs.rmit.edu.au
23
 
 *
24
 
 *   Date: 6/10/93
25
 
 *
26
 
 *   Version 1.0
27
 
 *   
28
 
 *   Copyright (c) RMIT 1993. All rights reserved.
29
 
 *
30
 
 *   License to copy and use this software purposes is granted provided 
31
 
 *   that appropriate credit is given to both RMIT and the author.
32
 
 *
33
 
 *   License is also granted to make and use derivative works provided
34
 
 *   that appropriate credit is given to both RMIT and the author.
35
 
 *
36
 
 *   RMIT makes no representations concerning either the merchantability 
37
 
 *   of this software or the suitability of this software for any particular 
38
 
 *   purpose.  It is provided "as is" without express or implied warranty 
39
 
 *   of any kind.
40
 
 *
41
 
 *   These notices must be retained in any copies of any part of this software.
42
 
 * 
43
 
 **************************************************************/
44
 
 
45
 
#include <stdlib.h>
46
 
#include <grass/gis.h>
47
 
#include <grass/glocale.h>
48
 
#include "defs.h"
49
 
#include "data_types.h"
50
 
 
51
 
static struct edge *edges;
52
 
static struct edge **free_list_e;
53
 
 
54
 
static unsigned int n_free_e;
55
 
 
56
 
void alloc_memory(unsigned int n)
57
 
{
58
 
    struct edge *e;
59
 
    int i;
60
 
 
61
 
    /* Sites storage. */
62
 
    sites = (struct vertex *)G_calloc(n, sizeof(struct vertex));
63
 
    if (sites == NULL)
64
 
        G_fatal_error(_("Not enough memory."));
65
 
 
66
 
    /* Edges. Euler's formula - at most 3n edges on a set of n sites */
67
 
    n_free_e = 3 * n;
68
 
    edges = e = (struct edge *)G_calloc(n_free_e, sizeof(struct edge));
69
 
    if (edges == NULL)
70
 
        G_fatal_error(_("Not enough memory."));
71
 
 
72
 
    free_list_e = (struct edge **)G_calloc(n_free_e, sizeof(struct edge *));
73
 
    if (free_list_e == NULL)
74
 
        G_fatal_error(_("Not enough memory."));
75
 
    for (i = 0; i < n_free_e; i++, e++)
76
 
        free_list_e[i] = e;
77
 
}
78
 
 
79
 
void alloc_sites(unsigned int n)
80
 
{
81
 
    /* Sites storage. */
82
 
    sites = (struct vertex *)G_calloc(n, sizeof(struct vertex));
83
 
    if (sites == NULL)
84
 
        G_fatal_error(_("Not enough memory."));
85
 
}
86
 
 
87
 
void realloc_sites(unsigned int n)
88
 
{
89
 
    /* Sites storage. */
90
 
    sites = (struct vertex *)G_realloc(sites, n * sizeof(struct vertex));
91
 
    if (sites == NULL)
92
 
        G_fatal_error(_("Not enough memory."));
93
 
}
94
 
 
95
 
void alloc_edges(unsigned int n)
96
 
{
97
 
    struct edge *e;
98
 
    int i;
99
 
 
100
 
    /* Edges. Euler's formula - at most 3n edges on a set of n sites */
101
 
    n_free_e = 3 * n;
102
 
    edges = e = (struct edge *)G_calloc(n_free_e, sizeof(struct edge));
103
 
    if (edges == NULL)
104
 
        G_fatal_error(_("Not enough memory."));
105
 
 
106
 
    free_list_e = (struct edge **)G_calloc(n_free_e, sizeof(struct edge *));
107
 
    if (free_list_e == NULL)
108
 
        G_fatal_error(_("Not enough memory."));
109
 
    for (i = 0; i < n_free_e; i++, e++)
110
 
        free_list_e[i] = e;
111
 
}
112
 
 
113
 
 
114
 
void free_memory()
115
 
{
116
 
    G_free(sites);
117
 
    G_free(edges);
118
 
    G_free(free_list_e);
119
 
}
120
 
 
121
 
struct edge *get_edge()
122
 
{
123
 
    if (n_free_e < 1)
124
 
        G_fatal_error(_("All allocated edges have been used."));
125
 
    return (free_list_e[--n_free_e]);
126
 
}
127
 
 
128
 
void free_edge(struct edge *e)
129
 
{
130
 
    free_list_e[n_free_e++] = e;
131
 
}