Skip to content

Commit

Permalink
points_in_path etc. should return bool.
Browse files Browse the repository at this point in the history
Fix #3824
  • Loading branch information
mdboom committed Nov 21, 2014
1 parent 20425e2 commit 2c1bc6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_path.py
Expand Up @@ -36,8 +36,10 @@ def test_contains_points_negative_radius():

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

assert np.all(path.contains_points(points, radius=-0.5) == expected)
assert result.dtype == np.bool
assert np.all(result == expected)


@image_comparison(baseline_images=['path_clipping'],
Expand Down
30 changes: 15 additions & 15 deletions src/_path.h
Expand Up @@ -67,7 +67,7 @@ struct XY
template <class PathIterator, class PointArray, class ResultArray>
void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &inside_flag)
{
int yflag1;
bool yflag1;
double vtx0, vty0, vtx1, vty1;
double tx, ty;
double sx, sy;
Expand All @@ -77,13 +77,13 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins

size_t n = points.size();

std::vector<int> yflag0(n);
std::vector<int> subpath_flag(n);
std::vector<bool> yflag0(n);
std::vector<bool> subpath_flag(n);

path.rewind(0);

for (i = 0; i < n; ++i) {
inside_flag[i] = 0;
inside_flag[i] = false;
}

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

subpath_flag[i] = 0;
subpath_flag[i] = false;
}
}

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

Expand Down Expand Up @@ -181,11 +181,11 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
yflag1 = (vty1 >= ty);
if (yflag0[i] != yflag1) {
if (((vty1 - ty) * (vtx0 - vtx1) >= (vtx1 - tx) * (vty0 - vty1)) == yflag1) {
subpath_flag[i] ^= 1;
subpath_flag[i] = subpath_flag[i] ^ true;
}
}
inside_flag[i] |= subpath_flag[i];
if (inside_flag[i] == 0) {
inside_flag[i] = inside_flag[i] || subpath_flag[i];
if (inside_flag[i] == false) {
all_done = false;
}
}
Expand All @@ -210,7 +210,7 @@ inline void points_in_path(PointArray &points,

size_t i;
for (i = 0; i < result.size(); ++i) {
result[i] = 0;
result[i] = false;
}

if (path.total_vertices() < 3) {
Expand All @@ -236,8 +236,8 @@ inline bool point_in_path(
point.push_back(y);
points.push_back(point);

std::vector<uint8_t> result(1);
result[0] = 0;
std::vector<bool> result(1);
result[0] = false;

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

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

size_t i;
for (i = 0; i < result.size(); ++i) {
result[i] = 0;
result[i] = false;
}

transformed_path_t trans_path(path, trans);
Expand All @@ -279,8 +279,8 @@ inline bool point_on_path(
point.push_back(y);
points.push_back(point);

std::vector<uint8_t> result(1);
result[0] = 0;
std::vector<bool> result(1);
result[0] = false;

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

Expand Down
4 changes: 2 additions & 2 deletions src/_path_wrapper.cpp
Expand Up @@ -80,7 +80,7 @@ static PyObject *Py_points_in_path(PyObject *self, PyObject *args, PyObject *kwd
}

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

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

Expand Down Expand Up @@ -139,7 +139,7 @@ static PyObject *Py_points_on_path(PyObject *self, PyObject *args, PyObject *kwd
}

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

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

Expand Down

0 comments on commit 2c1bc6b

Please sign in to comment.