1
/* Libart_LGPL - library of basic graphic primitives
2
* Copyright (C) 1998 Raph Levien
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 3 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
16
* Boston, MA 02111-1307, USA.
19
/* Basic constructors and operations for sorted vector paths */
26
/* Add a new segment. The arguments can be zero and NULL if the caller
27
would rather fill them in later.
29
We also realloc one auxiliary array of ints of size n_segs if
33
* art_svp_add_segment: Add a segment to an #ArtSVP structure.
34
* @p_vp: Pointer to where the #ArtSVP structure is stored.
35
* @pn_segs_max: Pointer to the allocated size of *@p_vp.
36
* @pn_points_max: Pointer to where auxiliary array is stored.
37
* @n_points: Number of points for new segment.
38
* @dir: Direction for new segment; 0 is up, 1 is down.
39
* @points: Points for new segment.
40
* @bbox: Bounding box for new segment.
42
* Adds a new segment to an ArtSVP structure. This routine reallocates
43
* the structure if necessary, updating *@p_vp and *@pn_segs_max as
46
* The new segment is simply added after all other segments. Thus,
47
* this routine should be called in order consistent with the #ArtSVP
50
* If the @bbox argument is given, it is simply stored in the new
51
* segment. Otherwise (if it is NULL), the bounding box is computed
52
* from the @points given.
55
art_svp_add_segment (ArtSVP **p_vp, int *pn_segs_max,
57
int n_points, int dir, ArtPoint *points,
65
seg_num = svp->n_segs++;
66
if (*pn_segs_max == seg_num)
69
svp = (ArtSVP *)art_realloc (svp, sizeof(ArtSVP) +
70
(*pn_segs_max - 1) * sizeof(ArtSVPSeg));
72
if (pn_points_max != NULL)
73
*pn_points_max = art_renew (*pn_points_max, int, *pn_segs_max);
75
seg = &svp->segs[seg_num];
76
seg->n_points = n_points;
86
x_min = x_max = points[0].x;
87
for (i = 1; i < n_points; i++)
89
if (x_min > points[i].x)
91
if (x_max < points[i].x)
95
seg->bbox.y0 = points[0].y;
98
seg->bbox.y1 = points[n_points - 1].y;
105
* art_svp_free: Free an #ArtSVP structure.
106
* @svp: #ArtSVP to free.
108
* Frees an #ArtSVP structure and all the segments in it.
111
art_svp_free (ArtSVP *svp)
113
int n_segs = svp->n_segs;
116
for (i = 0; i < n_segs; i++)
117
art_free (svp->segs[i].points);
121
#ifdef ART_USE_NEW_INTERSECTOR
128
* art_svp_seg_compare: Compare two segments of an svp.
129
* @seg1: First segment to compare.
130
* @seg2: Second segment to compare.
132
* Compares two segments of an svp. Return 1 if @seg2 is below or to the
133
* right of @seg1, -1 otherwise.
136
art_svp_seg_compare (const void *s1, const void *s2)
138
const ArtSVPSeg *seg1 = s1;
139
const ArtSVPSeg *seg2 = s2;
141
if (seg1->points[0].y - EPSILON > seg2->points[0].y) return 1;
142
else if (seg1->points[0].y + EPSILON < seg2->points[0].y) return -1;
143
else if (seg1->points[0].x - EPSILON > seg2->points[0].x) return 1;
144
else if (seg1->points[0].x + EPSILON < seg2->points[0].x) return -1;
145
else if ((seg1->points[1].x - seg1->points[0].x) *
146
(seg2->points[1].y - seg2->points[0].y) -
147
(seg1->points[1].y - seg1->points[0].y) *
148
(seg2->points[1].x - seg2->points[0].x) > 0) return 1;