diff --git a/src/core/pal/labelposition.cpp b/src/core/pal/labelposition.cpp index 68ec0eeffb0..6bc7bbfc7e9 100644 --- a/src/core/pal/labelposition.cpp +++ b/src/core/pal/labelposition.cpp @@ -476,7 +476,7 @@ bool LabelPosition::countFullOverlapCallback( LabelPosition *lp, void *ctx ) LabelPosition *lp2 = context->lp; double *cost = context->cost; int *nbOv = context->nbOv; - double *inactiveCost = context->inactiveCost; + std::vector< double > &inactiveCost = *context->inactiveCost; if ( lp2->isInConflict( lp ) ) { ( *nbOv ) ++; diff --git a/src/core/pal/labelposition.h b/src/core/pal/labelposition.h index 9519f2daf85..291a054e536 100644 --- a/src/core/pal/labelposition.h +++ b/src/core/pal/labelposition.h @@ -281,8 +281,7 @@ namespace pal LabelPosition *lp = nullptr; int *nbOv = nullptr; double *cost = nullptr; - double *inactiveCost = nullptr; - //int *feat; + std::vector< double > *inactiveCost = nullptr; }; /* diff --git a/src/core/pal/pal.cpp b/src/core/pal/pal.cpp index 5bdbb05de0a..520e3c71b23 100644 --- a/src/core/pal/pal.cpp +++ b/src/core/pal/pal.cpp @@ -325,9 +325,9 @@ std::unique_ptr Pal::extract( const QgsRectangle &extent, const QgsGeom prob->mFeatureCount = features.size(); prob->mTotalCandidates = 0; - prob->mFeatNbLp = new int [prob->mFeatureCount]; - prob->mFeatStartId = new int [prob->mFeatureCount]; - prob->mInactiveCost = new double[prob->mFeatureCount]; + prob->mFeatNbLp.resize( prob->mFeatureCount ); + prob->mFeatStartId.resize( prob->mFeatureCount ); + prob->mInactiveCost.resize( prob->mFeatureCount ); if ( !features.empty() ) { diff --git a/src/core/pal/problem.cpp b/src/core/pal/problem.cpp index b8ba4f0a73c..df9f4d36e39 100644 --- a/src/core/pal/problem.cpp +++ b/src/core/pal/problem.cpp @@ -57,13 +57,7 @@ inline void delete_chain( Chain *chain ) Problem::Problem() = default; -Problem::~Problem() -{ - delete[] mFeatStartId; - delete[] mFeatNbLp; - - delete[] mInactiveCost; -} +Problem::~Problem() = default; void Problem::reduce() { @@ -302,7 +296,7 @@ struct ChainContext QLinkedList *currentChain; QLinkedList *conflicts; double *delta_tmp = nullptr; - double *inactiveCost = nullptr; + std::vector< double > *inactiveCost = nullptr; } ; @@ -346,7 +340,7 @@ bool chainCallback( LabelPosition *lp, void *context ) if ( !ctx->conflicts->contains( feat ) ) { ctx->conflicts->append( feat ); - *ctx->delta_tmp += lp->cost() + ctx->inactiveCost[rfeat]; + *ctx->delta_tmp += lp->cost() + ( * ctx->inactiveCost )[rfeat]; } } return true; @@ -386,7 +380,7 @@ inline Chain *Problem::chain( int seed ) context.featWrap = nullptr; context.borderSize = 0; context.tmpsol = &tmpsol; - context.inactiveCost = mInactiveCost; + context.inactiveCost = &mInactiveCost; context.feat = nullptr; context.currentChain = ¤tChain; context.conflicts = &conflicts; @@ -786,7 +780,7 @@ void Problem::solution_cost() int nbOv; LabelPosition::CountContext context; - context.inactiveCost = mInactiveCost; + context.inactiveCost = &mInactiveCost; context.nbOv = &nbOv; context.cost = &mSol.totalCost; double amin[2]; diff --git a/src/core/pal/problem.h b/src/core/pal/problem.h index d87220a4e2f..b8522f5029c 100644 --- a/src/core/pal/problem.h +++ b/src/core/pal/problem.h @@ -183,10 +183,9 @@ namespace pal std::vector< std::unique_ptr< LabelPosition > > mPositionsWithNoCandidates; - //int *feat; // [nblp] - int *mFeatStartId = nullptr; // [nbft] - int *mFeatNbLp = nullptr; // [nbft] - double *mInactiveCost = nullptr; // + std::vector< int > mFeatStartId; + std::vector< int > mFeatNbLp; + std::vector< double > mInactiveCost; class Sol {