Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7226a10

Browse files
committed
Skip over zero-length subpaths. Calculate for each subpath and then "or" those results together.
1 parent 98e37e8 commit 7226a10

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/_path.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ point_in_path_impl(const void* const points_, const size_t s0,
128128
npy_bool* const inside_flag)
129129
{
130130
int *yflag0;
131+
int *subpath_flag;
131132
int yflag1;
132133
double vtx0, vty0, vtx1, vty1;
133134
double tx, ty;
@@ -138,6 +139,7 @@ point_in_path_impl(const void* const points_, const size_t s0,
138139
const char *const points = (const char * const)points_;
139140

140141
yflag0 = (int *)malloc(n * sizeof(int));
142+
subpath_flag = (int *)malloc(n * sizeof(int));
141143

142144
path.rewind(0);
143145

@@ -151,6 +153,10 @@ point_in_path_impl(const void* const points_, const size_t s0,
151153
if (code != agg::path_cmd_move_to)
152154
{
153155
code = path.vertex(&x, &y);
156+
if (code == agg::path_cmd_stop ||
157+
(code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) {
158+
continue;
159+
}
154160
}
155161

156162
sx = vtx0 = vtx1 = x;
@@ -162,7 +168,7 @@ point_in_path_impl(const void* const points_, const size_t s0,
162168
// get test bit for above/below X axis
163169
yflag0[i] = (vty0 >= ty);
164170

165-
inside_flag[i] = 0;
171+
subpath_flag[i] = 0;
166172
}
167173

168174
do
@@ -208,7 +214,7 @@ point_in_path_impl(const void* const points_, const size_t s0,
208214
// tests.
209215
if (((vty1 - ty) * (vtx0 - vtx1) >=
210216
(vtx1 - tx) * (vty0 - vty1)) == yflag1) {
211-
inside_flag[i] ^= 1;
217+
subpath_flag[i] ^= 1;
212218
}
213219
}
214220

@@ -235,10 +241,10 @@ point_in_path_impl(const void* const points_, const size_t s0,
235241
if (yflag0[i] != yflag1) {
236242
if (((vty1 - ty) * (vtx0 - vtx1) >=
237243
(vtx1 - tx) * (vty0 - vty1)) == yflag1) {
238-
inside_flag[i] ^= 1;
244+
subpath_flag[i] ^= 1;
239245
}
240246
}
241-
247+
inside_flag[i] |= subpath_flag[i];
242248
if (inside_flag[i] == 0) {
243249
all_done = 0;
244250
}
@@ -253,6 +259,7 @@ point_in_path_impl(const void* const points_, const size_t s0,
253259
exit:
254260

255261
free(yflag0);
262+
free(subpath_flag);
256263
}
257264

258265
inline void

0 commit comments

Comments
 (0)