@@ -127,8 +127,9 @@ point_in_path_impl(const void* const points_, const size_t s0,
127127 const size_t s1, const size_t n, T& path,
128128 npy_bool* const inside_flag)
129129{
130- int *yflag0, *yflag1;
131- double *vtx0, *vty0, *vtx1, *vty1;
130+ int *yflag0;
131+ int yflag1;
132+ double vtx0, vty0, vtx1, vty1;
132133 double tx, ty;
133134 double sx, sy;
134135 double x, y;
@@ -137,11 +138,6 @@ point_in_path_impl(const void* const points_, const size_t s0,
137138 const char *const points = (const char * const )points_;
138139
139140 yflag0 = (int *)malloc (n * sizeof (int ));
140- yflag1 = (int *)malloc (n * sizeof (int ));
141- vtx0 = (double *)malloc (n * sizeof (double ));
142- vty0 = (double *)malloc (n * sizeof (double ));
143- vtx1 = (double *)malloc (n * sizeof (double ));
144- vty1 = (double *)malloc (n * sizeof (double ));
145141
146142 path.rewind (0 );
147143
@@ -157,17 +153,14 @@ point_in_path_impl(const void* const points_, const size_t s0,
157153 code = path.vertex (&x, &y);
158154 }
159155
160- sx = x;
161- sy = y;
156+ sx = vtx0 = vtx1 = x;
157+ sy = vty0 = vty1 = y;
162158
163159 for (i = 0 ; i < n; ++i) {
164- vtx0[i] = vtx1[i] = x;
165- vty0[i] = vty1[i] = y;
166-
167160 ty = *(double *)(points + s0 * i + s1);
168161
169162 // get test bit for above/below X axis
170- yflag0[i] = (vty0[i] >= ty);
163+ yflag0[i] = (vty0 >= ty);
171164
172165 inside_flag[i] = 0 ;
173166 }
@@ -192,7 +185,7 @@ point_in_path_impl(const void* const points_, const size_t s0,
192185 tx = *(double *)(points + s0 * i);
193186 ty = *(double *)(points + s0 * i + s1);
194187
195- yflag1[i] = (vty1[i] >= ty);
188+ yflag1 = (vty1 >= ty);
196189 // Check if endpoints straddle (are on opposite sides) of
197190 // X axis (i.e. the Y's differ); if so, +X ray could
198191 // intersect this edge. The old test also checked whether
@@ -205,30 +198,30 @@ point_in_path_impl(const void* const points_, const size_t s0,
205198 // have the X intersection computed anyway). I credit
206199 // Joseph Samosky with inspiring me to try dropping the
207200 // "both left or both right" part of my code.
208- if (yflag0[i] != yflag1[i] ) {
201+ if (yflag0[i] != yflag1) {
209202 // Check intersection of pgon segment with +X ray.
210203 // Note if >= point's X; if so, the ray hits it. The
211204 // division operation is avoided for the ">=" test by
212205 // checking the sign of the first vertex wrto the test
213206 // point; idea inspired by Joseph Samosky's and Mark
214207 // Haigh-Hutchinson's different polygon inclusion
215208 // tests.
216- if (((vty1[i] - ty) * (vtx0[i] - vtx1[i] ) >=
217- (vtx1[i] - tx) * (vty0[i] - vty1[i] )) == yflag1[i] ) {
209+ if (((vty1 - ty) * (vtx0 - vtx1) >=
210+ (vtx1 - tx) * (vty0 - vty1)) == yflag1) {
218211 inside_flag[i] ^= 1 ;
219212 }
220213 }
221214
222-
223215 // Move to the next pair of vertices, retaining info as
224216 // possible.
225- yflag0[i] = yflag1[i];
226- vtx0[i] = vtx1[i];
227- vty0[i] = vty1[i];
228-
229- vtx1[i] = x;
230- vty1[i] = y;
217+ yflag0[i] = yflag1;
231218 }
219+
220+ vtx0 = vtx1;
221+ vty0 = vty1;
222+
223+ vtx1 = x;
224+ vty1 = y;
232225 }
233226 while (code != agg::path_cmd_stop &&
234227 (code & agg::path_cmd_end_poly) != agg::path_cmd_end_poly);
@@ -238,10 +231,10 @@ point_in_path_impl(const void* const points_, const size_t s0,
238231 tx = *(double *)(points + s0 * i);
239232 ty = *(double *)(points + s0 * i + s1);
240233
241- yflag1[i] = (vty1[i] >= ty);
242- if (yflag0[i] != yflag1[i] ) {
243- if (((vty1[i] - ty) * (vtx0[i] - vtx1[i] ) >=
244- (vtx1[i] - tx) * (vty0[i] - vty1[i] )) == yflag1[i] ) {
234+ yflag1 = (vty1 >= ty);
235+ if (yflag0[i] != yflag1) {
236+ if (((vty1 - ty) * (vtx0 - vtx1) >=
237+ (vtx1 - tx) * (vty0 - vty1)) == yflag1) {
245238 inside_flag[i] ^= 1 ;
246239 }
247240 }
@@ -260,11 +253,6 @@ point_in_path_impl(const void* const points_, const size_t s0,
260253 exit:
261254
262255 free (yflag0);
263- free (yflag1);
264- free (vtx0);
265- free (vty0);
266- free (vtx1);
267- free (vty1);
268256}
269257
270258inline void
0 commit comments