Skip to content

Commit

Permalink
Some algorithm optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert authored and sliptonic committed Sep 28, 2020
1 parent 07f3e6c commit d68b506
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Mod/Path/App/Voronoi.cpp
Expand Up @@ -190,7 +190,7 @@ void Voronoi::construct()
}

void Voronoi::colorExterior(const Voronoi::diagram_type::edge_type *edge, std::size_t colorValue) {
if (edge->color() == colorValue) {
if (edge->color()) {
// end recursion
return;
}
Expand All @@ -210,7 +210,7 @@ void Voronoi::colorExterior(const Voronoi::diagram_type::edge_type *edge, std::s

void Voronoi::colorExterior(Voronoi::color_type color) {
for (diagram_type::const_edge_iterator it = vd->edges().begin(); it != vd->edges().end(); ++it) {
if (!it->is_finite()) {
if (it->is_infinite()) {
colorExterior(&(*it), color);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/Mod/Path/App/VoronoiPyImp.cpp
Expand Up @@ -173,7 +173,7 @@ Py::List VoronoiPy::getCells(void) const {
}

static bool callbackWithVertex(Voronoi::diagram_type *dia, PyObject *callback, const Voronoi::diagram_type::vertex_type *v, bool &isExterior) {
if (!isExterior) {
if (!isExterior && v->color() == 0) {
PyObject *vx = new VoronoiVertexPy(new VoronoiVertex(dia, v));
PyObject *arglist = Py_BuildValue("(O)", vx);
PyObject *result = PyEval_CallObject(callback, arglist);
Expand Down Expand Up @@ -201,11 +201,12 @@ PyObject* VoronoiPy::colorExterior(PyObject *args) {
if (e->is_finite() && e->color() == 0) {
const Voronoi::diagram_type::vertex_type *v0 = e->vertex0();
const Voronoi::diagram_type::vertex_type *v1 = e->vertex1();
bool isExterior = false;
if (!callbackWithVertex(vo->vd, callback, v0, isExterior) || !callbackWithVertex(vo->vd, callback, v1, isExterior)) {
bool is0 = false;
bool is1 = false;
if (!callbackWithVertex(vo->vd, callback, v0, is0) || !callbackWithVertex(vo->vd, callback, v1, is1)) {
return NULL;
}
if (isExterior) {
if (is0 && is1) {
vo->colorExterior(&(*e), color);
}
}
Expand Down

0 comments on commit d68b506

Please sign in to comment.