2
\file lib/pngdriver/polygon.c
4
\brief GRASS png display driver - draw polygon
6
(C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
11
\author Per Henrik Johansen (original contributor)
12
\author Glynn Clements
17
#include <grass/gis.h>
20
#include "pngdriver.h"
22
static int cmp_double(const void *aa, const void *bb)
33
static void fill(double x0, double x1, double y)
35
int yi = (int) floor(y);
36
int xi0 = (int) floor(x0 + 0.5);
37
int xi1 = (int) floor(x1 + 0.5);
41
if (yi >= png.clip_bot || yi < png.clip_top)
44
if (xi0 > png.clip_rite)
47
if (xi1 < png.clip_left)
50
if (xi0 < png.clip_left)
53
if (xi1 > png.clip_rite)
56
p = &png.grid[yi * png.width + xi0];
58
for (x = xi0; x < xi1; x++)
59
*p++ = png.current_color;
62
static void line(const struct vertex *p, int n, double y)
69
for (i = 1; i < n; i++) {
70
const struct vertex *p0 = &p[i - 1];
71
const struct vertex *p1 = &p[i];
72
const struct vertex *tmp;
79
tmp = p0, p0 = p1, p1 = tmp;
87
x = p1->x * (y - p0->y) + p0->x * (p1->y - y);
92
xs = G_realloc(xs, max_x * sizeof(double));
98
qsort(xs, num_x, sizeof(double), cmp_double);
100
for (i = 0; i + 1 < num_x; i += 2)
101
fill(xs[i], xs[i + 1], y);
104
static void poly(const struct vertex *p, int n)
114
for (i = 1; i < n; i++) {
122
if (y0 > png.clip_bot || y1 < png.clip_top)
125
if (y0 < png.clip_top)
128
if (y1 > png.clip_bot)
131
for (y = floor(y0 + 0.5) + 0.5; y < y1; y++)
138
void png_polygon(struct path *p)
140
if (p->vertices[p->count - 1].mode != P_CLOSE)
143
poly(p->vertices, p->count);