From 85fda0372261ecfeaa3942c0f8232b53baa267a3 Mon Sep 17 00:00:00 2001 From: Lukas Wagner Date: Tue, 5 Jun 2018 18:14:17 +0200 Subject: [PATCH] refs #24: use vector instead of array for positions --- src/algorithms/voronoi.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/algorithms/voronoi.cpp b/src/algorithms/voronoi.cpp index 0e74eef..5804451 100644 --- a/src/algorithms/voronoi.cpp +++ b/src/algorithms/voronoi.cpp @@ -43,7 +43,7 @@ QImage* Voronoi::createMosaic(const QImage& input, int maxNumOfMolluscs) auto sites = jcv_diagram_get_sites(&diagram); - auto positions = new MolluscPosition[diagram.numsites]; + auto positions = std::vector(); for (auto i = 0; i < diagram.numsites; ++i) { @@ -82,7 +82,7 @@ QImage* Voronoi::createMosaic(const QImage& input, int maxNumOfMolluscs) auto dimY = (int)(maxY - minY); auto dim = std::min(dimX, dimY); - new(positions + i) MolluscPosition{ (int)x, (int)y, dim, dim, 0, QColor(input.pixel((int)x, (int)y)) }; + positions.push_back(MolluscPosition{ (int)x, (int)y, dim, dim, 0, QColor(input.pixel((int)x, (int)y)) }); } // draw molluscs @@ -93,13 +93,13 @@ QImage* Voronoi::createMosaic(const QImage& input, int maxNumOfMolluscs) for (auto i = 0; i < diagram.numsites; ++i) { - auto pos = &positions[i]; + auto pos = positions[i]; - auto mollusc = getClosestColor(m_molluscs, toVec3(pos->color)); + auto mollusc = getClosestColor(m_molluscs, toVec3(pos.color)); // todo: better drawing with save/translate/rotate/restore if (mollusc.m_imageName.compare("NONE") != 0) - painter.drawPixmap(pos->x - pos->width / 2, pos->y - pos->height / 2, pos->width, pos->height, mollusc.m_image); + painter.drawPixmap(pos.x - pos.width / 2, pos.y - pos.height / 2, pos.width, pos.height, mollusc.m_image); } // clean up