diff --git a/src/Mod/Path/App/Voronoi.cpp b/src/Mod/Path/App/Voronoi.cpp index b24191d401..96442ede5e 100644 --- a/src/Mod/Path/App/Voronoi.cpp +++ b/src/Mod/Path/App/Voronoi.cpp @@ -43,28 +43,24 @@ TYPESYSTEM_SOURCE(Path::Voronoi , Base::BaseClass); // Helpers -#if 0 -static const std::size_t EXTERNAL_COLOR = 1; - -static void color_exterior(const Voronoi::diagram_type::edge_type *edge) { - if (edge->color() == EXTERNAL_COLOR) { +static void colorExterior(const Voronoi::diagram_type::edge_type *edge, std::size_t colorValue) { + if (edge->color() == colorValue) { // end recursion return; } - edge->color(EXTERNAL_COLOR); - edge->twin()->color(EXTERNAL_COLOR); + edge->color(colorValue); + edge->twin()->color(colorValue); auto v = edge->vertex1(); if (v == NULL || !edge->is_primary()) { return; } - v->color(EXTERNAL_COLOR); + v->color(colorValue); auto e = v->incident_edge(); do { - color_exterior(e); + colorExterior(e, colorValue); e = e->rot_next(); } while (e != v->incident_edge()); } -#endif // Constructors & destructors @@ -147,3 +143,22 @@ void Voronoi::construct() construct_voronoi(vd->points.begin(), vd->points.end(), vd->segments.begin(), vd->segments.end(), (voronoi_diagram_type*)vd); vd->reIndex(); } + +void Voronoi::colorExterior(int color) { + for (diagram_type::const_edge_iterator it = vd->edges().begin(); it != vd->edges().end(); ++it) { + if (!it->is_finite()) { + ::colorExterior(&(*it), color); + } + } +} + +void Voronoi::colorTwins(int color) { + for (diagram_type::const_edge_iterator it = vd->edges().begin(); it != vd->edges().end(); ++it) { + if (!it->color()) { + auto twin = it->twin(); + if (!twin->color()) { + twin->color(color); + } + } + } +} diff --git a/src/Mod/Path/App/Voronoi.h b/src/Mod/Path/App/Voronoi.h index 5be8018170..586d8e0b23 100644 --- a/src/Mod/Path/App/Voronoi.h +++ b/src/Mod/Path/App/Voronoi.h @@ -89,8 +89,13 @@ namespace Path long numEdges() const; long numVertices() const; + void colorExterior(int color); + void colorTwins(int color); + + private: // attributes Base::Reference vd; + friend class VoronoiPy; }; } //namespace Path diff --git a/src/Mod/Path/App/VoronoiPy.xml b/src/Mod/Path/App/VoronoiPy.xml index b38bf6872b..b6227aaf01 100644 --- a/src/Mod/Path/App/VoronoiPy.xml +++ b/src/Mod/Path/App/VoronoiPy.xml @@ -63,5 +63,15 @@ constructs the voronoi diagram from the input collections + + + assign given color to all exterior edges and vertices + + + + + assign given color to all twins of edges (which one is considered a twin is arbitrary) + + diff --git a/src/Mod/Path/App/VoronoiPyImp.cpp b/src/Mod/Path/App/VoronoiPyImp.cpp index 403961fc2e..6c0bd9eafd 100644 --- a/src/Mod/Path/App/VoronoiPyImp.cpp +++ b/src/Mod/Path/App/VoronoiPyImp.cpp @@ -169,6 +169,28 @@ Py::List VoronoiPy::getCells(void) const { return list; } +PyObject* VoronoiPy::colorExterior(PyObject *args) { + int color = 0; + if (!PyArg_ParseTuple(args, "i", &color)) { + throw Py::RuntimeError("colorExterior requires an integer (color) argument"); + } + getVoronoiPtr()->colorExterior(color); + + Py_INCREF(Py_None); + return Py_None; +} + +PyObject* VoronoiPy::colorTwins(PyObject *args) { + int color = 0; + if (!PyArg_ParseTuple(args, "i", &color)) { + throw Py::RuntimeError("colorTwins requires an integer (color) argument"); + } + getVoronoiPtr()->colorTwins(color); + + Py_INCREF(Py_None); + return Py_None; +} + // custom attributes get/set PyObject *VoronoiPy::getCustomAttributes(const char* /*attr*/) const