Skip to content

Commit b86ecee

Browse files
committed
Remove PyCXX from _point_in_path_collection()
1 parent a8036dc commit b86ecee

File tree

1 file changed

+67
-15
lines changed

1 file changed

+67
-15
lines changed

src/_path.cpp

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,37 @@ PyObject *_get_path_collection_extents(PyObject *self, PyObject *_args)
877877
//_path_module::point_in_path_collection(const Py::Tuple& args)
878878
PyObject *_point_in_path_collection(PyObject *self, PyObject *_args)
879879
{
880+
double x, y, radius;
881+
PyObject *_master_transform, *_paths, *_transforms, *_offsets, *_offset_trans, *_filled;
882+
const char *_offset_position;
883+
if (!PyArg_ParseTuple(_args, "dddOOOOOOs", &x, &y, &radius,
884+
&_master_transform, &_paths, &_transforms, &_offsets, &_offset_trans, &_filled,
885+
&_offset_position)) {
886+
return NULL;
887+
}
888+
agg::trans_affine master_transform = py_to_agg_transformation_matrix
889+
(_master_transform, false);
890+
agg::trans_affine offset_trans = py_to_agg_transformation_matrix
891+
(_offset_trans, false);
892+
893+
PyObject* __paths = PySequence_Fast(_paths, "paths must be a sequence");
894+
if (__paths == NULL)
895+
{
896+
return NULL;
897+
}
898+
PyObject* __transforms = PySequence_Fast(_transforms, "transforms must be a sequence");
899+
if (__transforms == NULL)
900+
{
901+
Py_DECREF(__paths);
902+
return NULL;
903+
}
904+
PyObject** paths_arr = PySequence_Fast_ITEMS(__paths);
905+
PyObject** transforms_arr = PySequence_Fast_ITEMS(__transforms);
906+
907+
bool filled = PyObject_IsTrue(_filled) != 0;
908+
std::string offset_position(_offset_position);
909+
910+
/*
880911
const Py::Tuple args(_args);
881912
args.verify_length(10);
882913
@@ -891,23 +922,29 @@ PyObject *_point_in_path_collection(PyObject *self, PyObject *_args)
891922
agg::trans_affine offset_trans = py_to_agg_transformation_matrix(args[7].ptr());
892923
bool filled = Py::Boolean(args[8]);
893924
std::string offset_position = Py::String(args[9]).encode("utf-8");
894-
925+
*/
895926
bool data_offsets = (offset_position == "data");
896927

897928
PyArrayObject* offsets = (PyArrayObject*)PyArray_FromObject(
898-
offsets_obj.ptr(), PyArray_DOUBLE, 0, 2);
929+
_offsets, PyArray_DOUBLE, 0, 2);
930+
//PyArrayObject* offsets = (PyArrayObject*)PyArray_FromObject(
931+
// offsets_obj.ptr(), PyArray_DOUBLE, 0, 2);
899932
if (!offsets ||
900933
(PyArray_NDIM(offsets) == 2 && PyArray_DIM(offsets, 1) != 2) ||
901934
(PyArray_NDIM(offsets) == 1 && PyArray_DIM(offsets, 0) != 0))
902935
{
903936
Py_XDECREF(offsets);
904-
throw Py::ValueError("Offsets array must be Nx2");
937+
PyErr_SetString(PyExc_ValueError, "Offsets array must be Nx2");
938+
return NULL;
939+
//throw Py::ValueError("Offsets array must be Nx2");
905940
}
906941

907-
size_t Npaths = paths.length();
942+
size_t Npaths = PySequence_Fast_GET_SIZE(__paths);
943+
//size_t Npaths = paths.length();
908944
size_t Noffsets = PyArray_DIM(offsets, 0);
909945
size_t N = std::max(Npaths, Noffsets);
910-
size_t Ntransforms = std::min(transforms_obj.length(), N);
946+
size_t Ntransforms = std::min<size_t>(PySequence_Fast_GET_SIZE(__transforms), N);
947+
//size_t Ntransforms = std::min(transforms_obj.length(), N);
911948
size_t i;
912949

913950
// Convert all of the transforms up front
@@ -917,17 +954,23 @@ PyObject *_point_in_path_collection(PyObject *self, PyObject *_args)
917954
for (i = 0; i < Ntransforms; ++i)
918955
{
919956
agg::trans_affine trans = py_to_agg_transformation_matrix
920-
(transforms_obj[i].ptr(), false);
957+
(transforms_arr[i], false);
958+
//agg::trans_affine trans = py_to_agg_transformation_matrix
959+
// (transforms_obj[i].ptr(), false);
921960
trans *= master_transform;
922961
transforms.push_back(trans);
923962
}
924963

925-
Py::List result;
926964
agg::trans_affine trans;
927965

966+
PyObject* result = PyList_New(0);
967+
if (result == NULL) goto Fail;
968+
//Py::List result;
969+
928970
for (i = 0; i < N; ++i)
929971
{
930-
PathIterator path(paths[i % Npaths]);
972+
PathIterator path(Py::Object(paths_arr[i % Npaths], false));
973+
//PathIterator path(paths[i % Npaths]);
931974

932975
if (Ntransforms)
933976
{
@@ -952,19 +995,28 @@ PyObject *_point_in_path_collection(PyObject *self, PyObject *_args)
952995

953996
if (filled)
954997
{
955-
if (::point_in_path(x, y, radius, path, trans))
956-
result.append(Py::Int((int)i));
998+
if (::point_in_path(x, y, radius, path, trans) &&
999+
PyList_Append(result, PyInt_FromLong((int)i)) == -1) goto Fail;
1000+
//if (::point_in_path(x, y, radius, path, trans))
1001+
// result.append(Py::Int((int)i));
9571002
}
9581003
else
9591004
{
960-
if (::point_on_path(x, y, radius, path, trans))
961-
result.append(Py::Int((int)i));
1005+
if (::point_on_path(x, y, radius, path, trans) &&
1006+
PyList_Append(result, PyInt_FromLong((int)i)) == -1) goto Fail;
1007+
//if (::point_on_path(x, y, radius, path, trans))
1008+
// result.append(Py::Int((int)i));
9621009
}
9631010
}
9641011

965-
//return result;
966-
Py_INCREF(result.ptr());
967-
return result.ptr();
1012+
Fail:
1013+
Py_DECREF(__paths);
1014+
Py_DECREF(__transforms);
1015+
Py_DECREF(offsets);
1016+
1017+
return result;
1018+
//Py_INCREF(result.ptr());
1019+
//return result.ptr();
9681020
}
9691021

9701022
bool

0 commit comments

Comments
 (0)