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

Skip to content

Commit 9e700a9

Browse files
committed
Merge pull request #4087 from mdboom/collection-picking
Fix #4076. Change how result is stored in point_in_path/point_on_path.
2 parents ee4f072 + 0a5eea4 commit 9e700a9

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

lib/matplotlib/tests/test_collections.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import six
88

9+
import io
10+
911
from nose.tools import assert_equal
1012
import numpy as np
1113
from numpy.testing import assert_array_equal, assert_array_almost_equal
@@ -559,6 +561,23 @@ def get_transform(self):
559561
ax.axis([-1, 1, -1, 1])
560562

561563

564+
@cleanup
565+
def test_picking():
566+
fig, ax = plt.subplots()
567+
col = ax.scatter([0], [0], [1000])
568+
fig.savefig(io.BytesIO(), dpi=fig.dpi)
569+
570+
class MouseEvent(object):
571+
pass
572+
event = MouseEvent()
573+
event.x = 325
574+
event.y = 240
575+
576+
found, indices = col.contains(event)
577+
assert found
578+
assert_array_equal(indices['ind'], [0])
579+
580+
562581
if __name__ == '__main__':
563582
import nose
564583
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

src/_path.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ inline void points_in_path(PointArray &points,
209209
typedef agg::conv_contour<curve_t> contour_t;
210210

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

@@ -236,8 +236,8 @@ inline bool point_in_path(
236236
point.push_back(y);
237237
points.push_back(point);
238238

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

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

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

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

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

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

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

@@ -406,7 +406,7 @@ void point_in_path_collection(double x,
406406
agg::trans_affine &offset_trans,
407407
bool filled,
408408
e_offset_position offset_position,
409-
std::vector<size_t> &result)
409+
std::vector<int> &result)
410410
{
411411
size_t Npaths = paths.size();
412412

@@ -432,6 +432,7 @@ void point_in_path_collection(double x,
432432
subtrans(1, 1),
433433
subtrans(0, 2),
434434
subtrans(1, 2));
435+
trans *= master_transform;
435436
} else {
436437
trans = master_transform;
437438
}

src/_path_wrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static PyObject *Py_point_in_path_collection(PyObject *self, PyObject *args, PyO
309309
agg::trans_affine offset_trans;
310310
int filled;
311311
e_offset_position offset_position;
312-
std::vector<size_t> result;
312+
std::vector<int> result;
313313

314314
if (!PyArg_ParseTuple(args,
315315
"dddO&OO&O&O&iO&:point_in_path_collection",
@@ -354,8 +354,8 @@ static PyObject *Py_point_in_path_collection(PyObject *self, PyObject *args, PyO
354354
}
355355

356356
npy_intp dims[] = {(npy_intp)result.size() };
357-
numpy::array_view<size_t, 1> pyresult(dims);
358-
memcpy(pyresult.data(), &result[0], result.size() * sizeof(size_t));
357+
numpy::array_view<int, 1> pyresult(dims);
358+
memcpy(pyresult.data(), &result[0], result.size() * sizeof(int));
359359
return pyresult.pyobj();
360360
}
361361

0 commit comments

Comments
 (0)