Skip to content

Commit

Permalink
Merge pull request #4087 from mdboom/collection-picking
Browse files Browse the repository at this point in the history
Fix #4076. Change how result is stored in point_in_path/point_on_path.
  • Loading branch information
efiring committed Feb 11, 2015
2 parents ee4f072 + 0a5eea4 commit 9e700a9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_collections.py
Expand Up @@ -6,6 +6,8 @@

import six

import io

from nose.tools import assert_equal
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
Expand Down Expand Up @@ -559,6 +561,23 @@ def get_transform(self):
ax.axis([-1, 1, -1, 1])


@cleanup
def test_picking():
fig, ax = plt.subplots()
col = ax.scatter([0], [0], [1000])
fig.savefig(io.BytesIO(), dpi=fig.dpi)

class MouseEvent(object):
pass
event = MouseEvent()
event.x = 325
event.y = 240

found, indices = col.contains(event)
assert found
assert_array_equal(indices['ind'], [0])


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
15 changes: 8 additions & 7 deletions src/_path.h
Expand Up @@ -209,7 +209,7 @@ inline void points_in_path(PointArray &points,
typedef agg::conv_contour<curve_t> contour_t;

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

Expand All @@ -236,8 +236,8 @@ inline bool point_in_path(
point.push_back(y);
points.push_back(point);

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

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

Expand All @@ -257,7 +257,7 @@ void points_on_path(PointArray &points,
typedef agg::conv_stroke<curve_t> stroke_t;

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

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

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

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

Expand Down Expand Up @@ -406,7 +406,7 @@ void point_in_path_collection(double x,
agg::trans_affine &offset_trans,
bool filled,
e_offset_position offset_position,
std::vector<size_t> &result)
std::vector<int> &result)
{
size_t Npaths = paths.size();

Expand All @@ -432,6 +432,7 @@ void point_in_path_collection(double x,
subtrans(1, 1),
subtrans(0, 2),
subtrans(1, 2));
trans *= master_transform;
} else {
trans = master_transform;
}
Expand Down
6 changes: 3 additions & 3 deletions src/_path_wrapper.cpp
Expand Up @@ -309,7 +309,7 @@ static PyObject *Py_point_in_path_collection(PyObject *self, PyObject *args, PyO
agg::trans_affine offset_trans;
int filled;
e_offset_position offset_position;
std::vector<size_t> result;
std::vector<int> result;

if (!PyArg_ParseTuple(args,
"dddO&OO&O&O&iO&:point_in_path_collection",
Expand Down Expand Up @@ -354,8 +354,8 @@ static PyObject *Py_point_in_path_collection(PyObject *self, PyObject *args, PyO
}

npy_intp dims[] = {(npy_intp)result.size() };
numpy::array_view<size_t, 1> pyresult(dims);
memcpy(pyresult.data(), &result[0], result.size() * sizeof(size_t));
numpy::array_view<int, 1> pyresult(dims);
memcpy(pyresult.data(), &result[0], result.size() * sizeof(int));
return pyresult.pyobj();
}

Expand Down

0 comments on commit 9e700a9

Please sign in to comment.