Code

excise never-used code and stale comments
[inkscape.git] / src / libnr / nr-svp.cpp
1 #define __NR_SVP_C__
3 /*
4  * Pixel buffer rendering library
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * This code is in public domain
10  */
12 #define noNR_VERBOSE
14 #define NR_SVP_LENGTH_MAX 128
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
20 #ifdef HAVE_IEEEFP_H
21 # include <ieeefp.h>
22 #endif
24 #include "nr-rect.h"
25 #include "nr-svp-private.h"
27 /* Sorted vector paths */
29 void
30 nr_svp_free (NRSVP *svp)
31 {
32     if (svp->points) nr_free (svp->points);
33     free (svp);
34 }
36 void
37 nr_svp_bbox (NRSVP *svp, NRRect *bbox, unsigned int clear)
38 {
39     unsigned int sidx;
40     float x0, y0, x1, y1;
42     x0 = y0 = NR_HUGE;
43     x1 = y1 = -NR_HUGE;
45     for (sidx = 0; sidx < svp->length; sidx++) {
46         NRSVPSegment *seg;
47         seg = svp->segments + sidx;
48         if (seg->length) {
49             x0 = MIN (x0, seg->x0);
50             y0 = MIN (y0, svp->points[seg->start].y);
51             x1 = MAX (x1, seg->x1);
52             y1 = MAX (y1, svp->points[seg->start + seg->length - 1].y);
53         }
54     }
56     if ((x1 > x0) && (y1 > y0)) {
57         if (clear || (bbox->x1 <= bbox->x0) || (bbox->y1 <= bbox->y0)) {
58             bbox->x0 = x0;
59             bbox->y0 = y0;
60             bbox->x1 = x1;
61             bbox->y1 = y1;
62         } else {
63             bbox->x0 = MIN (bbox->x0, x0);
64             bbox->y0 = MIN (bbox->y0, y0);
65             bbox->x1 = MAX (bbox->x1, x1);
66             bbox->y1 = MAX (bbox->y1, y1);
67         }
68     }
69 }
71 /* NRVertex */
73 #define NR_VERTEX_ALLOC_SIZE 4096
74 static NRVertex *ffvertex = NULL;
76 NRVertex *
77 nr_vertex_new (void)
78 {
79     NRVertex * v;
80 #ifndef NR_VERTEX_ALLOC
82     v = ffvertex;
84     if (v == NULL) {
85         int i;
86         v = nr_new (NRVertex, NR_VERTEX_ALLOC_SIZE);
87         for (i = 1; i < (NR_VERTEX_ALLOC_SIZE - 1); i++) v[i].next = &v[i + 1];
88         v[NR_VERTEX_ALLOC_SIZE - 1].next = NULL;
89         ffvertex = v + 1;
90     } else {
91         ffvertex = v->next;
92     }
93 #else
94     v = nr_new (NRVertex, 1);
95 #endif
97     v->next = NULL;
99     return v;
102 NRVertex *
103 nr_vertex_new_xy (NR::Coord x, NR::Coord y)
105     NRVertex * v;
107     if (!finite(x) || !finite(y)) {
108         g_critical("nr_vertex_new_xy: BUG: Coordinates are not finite");
109         x = y = 0;
110     } else if (!( fabs(x) < 1e17 && fabs(y) < 1e17 )) {
111         g_critical("nr_vertex_new_xy: Coordinates out of range");
112         x = y = 0;
113     }
115     v = nr_vertex_new ();
117     v->x = x;
118     v->y = y;
120     return v;
123 void
124 nr_vertex_free_one (NRVertex * v)
126 #ifndef NR_VERTEX_ALLOC
127     v->next = ffvertex;
128     ffvertex = v;
129 #else
130     nr_free (v);
131 #endif
134 void
135 nr_vertex_free_list (NRVertex * v)
137 #ifndef NR_VERTEX_ALLOC
138     NRVertex * l;
139     for (l = v; l->next != NULL; l = l->next);
140     l->next = ffvertex;
141     ffvertex = v;
142 #else
143     NRVertex *l, *n;
144     l = v;
145     while (l) {
146         n = l->next;
147         nr_free (l);
148         l = n;
149     }
150 #endif
153 NRVertex *
154 nr_vertex_reverse_list (NRVertex * v)
156     NRVertex * p;
158     p = NULL;
160     while (v) {
161         NRVertex * n;
162         n = v->next;
163         v->next = p;
164         p = v;
165         v = n;
166     }
168     return p;
171 /*
172   Local Variables:
173   mode:c++
174   c-file-style:"stroustrup"
175   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
176   indent-tabs-mode:nil
177   fill-column:99
178   End:
179 */
180 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :