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

Skip to content

Commit 2c1bc6b

Browse files
committed
points_in_path etc. should return bool.
Fix #3824
1 parent 20425e2 commit 2c1bc6b

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

lib/matplotlib/tests/test_path.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ def test_contains_points_negative_radius():
3636

3737
points = [(0.0, 0.0), (1.25, 0.0), (0.9, 0.9)]
3838
expected = [True, False, False]
39+
result = path.contains_points(points, radius=-0.5)
3940

40-
assert np.all(path.contains_points(points, radius=-0.5) == expected)
41+
assert result.dtype == np.bool
42+
assert np.all(result == expected)
4143

4244

4345
@image_comparison(baseline_images=['path_clipping'],

src/_path.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct XY
6767
template <class PathIterator, class PointArray, class ResultArray>
6868
void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &inside_flag)
6969
{
70-
int yflag1;
70+
bool yflag1;
7171
double vtx0, vty0, vtx1, vty1;
7272
double tx, ty;
7373
double sx, sy;
@@ -77,13 +77,13 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
7777

7878
size_t n = points.size();
7979

80-
std::vector<int> yflag0(n);
81-
std::vector<int> subpath_flag(n);
80+
std::vector<bool> yflag0(n);
81+
std::vector<bool> subpath_flag(n);
8282

8383
path.rewind(0);
8484

8585
for (i = 0; i < n; ++i) {
86-
inside_flag[i] = 0;
86+
inside_flag[i] = false;
8787
}
8888

8989
unsigned code = 0;
@@ -106,7 +106,7 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
106106
// get test bit for above/below X axis
107107
yflag0[i] = (vty0 >= ty);
108108

109-
subpath_flag[i] = 0;
109+
subpath_flag[i] = false;
110110
}
111111
}
112112

@@ -152,7 +152,7 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
152152
// Haigh-Hutchinson's different polygon inclusion
153153
// tests.
154154
if (((vty1 - ty) * (vtx0 - vtx1) >= (vtx1 - tx) * (vty0 - vty1)) == yflag1) {
155-
subpath_flag[i] ^= 1;
155+
subpath_flag[i] = subpath_flag[i] ^ true;
156156
}
157157
}
158158

@@ -181,11 +181,11 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
181181
yflag1 = (vty1 >= ty);
182182
if (yflag0[i] != yflag1) {
183183
if (((vty1 - ty) * (vtx0 - vtx1) >= (vtx1 - tx) * (vty0 - vty1)) == yflag1) {
184-
subpath_flag[i] ^= 1;
184+
subpath_flag[i] = subpath_flag[i] ^ true;
185185
}
186186
}
187-
inside_flag[i] |= subpath_flag[i];
188-
if (inside_flag[i] == 0) {
187+
inside_flag[i] = inside_flag[i] || subpath_flag[i];
188+
if (inside_flag[i] == false) {
189189
all_done = false;
190190
}
191191
}
@@ -210,7 +210,7 @@ inline void points_in_path(PointArray &points,
210210

211211
size_t i;
212212
for (i = 0; i < result.size(); ++i) {
213-
result[i] = 0;
213+
result[i] = false;
214214
}
215215

216216
if (path.total_vertices() < 3) {
@@ -236,8 +236,8 @@ inline bool point_in_path(
236236
point.push_back(y);
237237
points.push_back(point);
238238

239-
std::vector<uint8_t> result(1);
240-
result[0] = 0;
239+
std::vector<bool> result(1);
240+
result[0] = false;
241241

242242
points_in_path(points, r, path, trans, result);
243243

@@ -258,7 +258,7 @@ void points_on_path(PointArray &points,
258258

259259
size_t i;
260260
for (i = 0; i < result.size(); ++i) {
261-
result[i] = 0;
261+
result[i] = false;
262262
}
263263

264264
transformed_path_t trans_path(path, trans);
@@ -279,8 +279,8 @@ inline bool point_on_path(
279279
point.push_back(y);
280280
points.push_back(point);
281281

282-
std::vector<uint8_t> result(1);
283-
result[0] = 0;
282+
std::vector<bool> result(1);
283+
result[0] = false;
284284

285285
points_on_path(points, r, path, trans, result);
286286

src/_path_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static PyObject *Py_points_in_path(PyObject *self, PyObject *args, PyObject *kwd
8080
}
8181

8282
npy_intp dims[] = { points.dim(0) };
83-
numpy::array_view<uint8_t, 1> results(dims);
83+
numpy::array_view<bool, 1> results(dims);
8484

8585
CALL_CPP("points_in_path", (points_in_path(points, r, path, trans, results)));
8686

@@ -139,7 +139,7 @@ static PyObject *Py_points_on_path(PyObject *self, PyObject *args, PyObject *kwd
139139
}
140140

141141
npy_intp dims[] = { points.dim(0) };
142-
numpy::array_view<uint8_t, 1> results(dims);
142+
numpy::array_view<bool, 1> results(dims);
143143

144144
CALL_CPP("points_on_path", (points_on_path(points, r, path, trans, results)));
145145

0 commit comments

Comments
 (0)