diff --git a/src/Mod/Path/App/Voronoi.cpp b/src/Mod/Path/App/Voronoi.cpp index b124bb52d2..4a3382306b 100644 --- a/src/Mod/Path/App/Voronoi.cpp +++ b/src/Mod/Path/App/Voronoi.cpp @@ -293,7 +293,7 @@ void Voronoi::colorColinear(Voronoi::color_type color, double degree) { void Voronoi::resetColor(Voronoi::color_type color) { for (auto it = vd->cells().begin(); it != vd->cells().end(); ++it) { - if (color == -1 || it->color() == color) { + if (color == 0 || it->color() == color) { it->color(0); } } diff --git a/src/Mod/Path/App/VoronoiPy.xml b/src/Mod/Path/App/VoronoiPy.xml index 30c0576b92..d330d6ccca 100644 --- a/src/Mod/Path/App/VoronoiPy.xml +++ b/src/Mod/Path/App/VoronoiPy.xml @@ -83,5 +83,25 @@ assign color 0 to all elements with the given color + + + Get list of all input points. + + + + + Return number of input points + + + + + Get list of all input segments. + + + + + Return number of input segments + + diff --git a/src/Mod/Path/App/VoronoiPyImp.cpp b/src/Mod/Path/App/VoronoiPyImp.cpp index f9afffa33f..77dcb76f15 100644 --- a/src/Mod/Path/App/VoronoiPyImp.cpp +++ b/src/Mod/Path/App/VoronoiPyImp.cpp @@ -253,6 +253,54 @@ PyObject* VoronoiPy::resetColor(PyObject *args) { return Py_None; } +PyObject* VoronoiPy::getPoints(PyObject *args) { + double z = 0; + if (!PyArg_ParseTuple(args, "|d", &z)) { + throw Py::RuntimeError("Optional z argument (double) accepted"); + } + Voronoi *vo = getVoronoiPtr(); + Py::List list; + for (auto it = vo->vd->points.begin(); it != vo->vd->points.end(); ++it) { + list.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(vo->vd->scaledVector(*it, z))))); + } + return Py::new_reference_to(list); +} + +PyObject* VoronoiPy::getSegments(PyObject *args) { + double z = 0; + if (!PyArg_ParseTuple(args, "|d", &z)) { + throw Py::RuntimeError("Optional z argument (double) accepted"); + } + Voronoi *vo = getVoronoiPtr(); + Py::List list; + for (auto it = vo->vd->segments.begin(); it != vo->vd->segments.end(); ++it) { + PyObject *p0 = new Base::VectorPy(new Base::Vector3d(vo->vd->scaledVector(low(*it), z))); + PyObject *p1 = new Base::VectorPy(new Base::Vector3d(vo->vd->scaledVector(high(*it), z))); + PyObject *tp = PyTuple_New(2); + PyTuple_SetItem(tp, 0, p0); + PyTuple_SetItem(tp, 1, p1); + list.append(Py::asObject(tp)); + } + return Py::new_reference_to(list); +} + +PyObject* VoronoiPy::numPoints(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) { + throw Py::RuntimeError("no arguments accepted"); + } + return PyLong_FromLong(getVoronoiPtr()->vd->points.size()); +} + +PyObject* VoronoiPy::numSegments(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) { + throw Py::RuntimeError("no arguments accepted"); + } + return PyLong_FromLong(getVoronoiPtr()->vd->segments.size()); +} + + // custom attributes get/set PyObject *VoronoiPy::getCustomAttributes(const char* /*attr*/) const