Added equal/not equal comparison to voronoi python objects with unit tests.

This commit is contained in:
Markus Lampert
2020-10-13 20:34:03 -07:00
parent 00a1aa6225
commit d3615f7e54
5 changed files with 101 additions and 12 deletions

View File

@@ -75,14 +75,14 @@ int VoronoiCellPy::PyInit(PyObject* args, PyObject* /*kwd*/)
PyObject* VoronoiCellPy::richCompare(PyObject *lhs, PyObject *rhs, int op) {
PyObject *cmp = Py_False;
PyObject *cmp = (op == Py_EQ) ? Py_False : Py_True;
if ( PyObject_TypeCheck(lhs, &VoronoiCellPy::Type)
&& PyObject_TypeCheck(rhs, &VoronoiCellPy::Type)
&& op == Py_EQ) {
&& (op == Py_EQ || op == Py_NE)) {
const VoronoiCell *vl = static_cast<VoronoiCellPy*>(lhs)->getVoronoiCellPtr();
const VoronoiCell *vr = static_cast<VoronoiCellPy*>(rhs)->getVoronoiCellPtr();
if (vl->index == vr->index && vl->dia == vr->dia) {
cmp = Py_True;
cmp = (op == Py_EQ) ? Py_True : Py_False;
}
}
Py_INCREF(cmp);