1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-15 22:19:07 +00:00

Little optimization for molestPath()

This commit is contained in:
fgenesis 2013-12-10 03:48:40 +01:00
parent 70286954a0
commit 204152a783
2 changed files with 8 additions and 20 deletions

View file

@ -220,17 +220,10 @@ void VectorPath::splice(const VectorPath &path, int sz)
} }
} }
void VectorPath::removeNodes(int startInclusive, int endInclusive) void VectorPath::removeNodes(unsigned int startInclusive, unsigned int endInclusive)
{ {
std::vector<VectorPathNode> copy = pathNodes; // end iterator is exclusive, so max. end + 1
pathNodes.clear(); pathNodes.erase(pathNodes.begin() + startInclusive, pathNodes.begin() + std::min<size_t>(pathNodes.size(), endInclusive+1));
for (int i = 0; i < copy.size(); i++)
{
if (i < startInclusive || i > endInclusive)
{
pathNodes.push_back(copy[i]);
}
}
} }
void VectorPath::prepend(const VectorPath &path) void VectorPath::prepend(const VectorPath &path)
@ -273,15 +266,10 @@ void VectorPath::cut(int n)
} }
} }
void VectorPath::removeNode(int t) void VectorPath::removeNode(unsigned int t)
{ {
std::vector<VectorPathNode> copy = pathNodes; if(t < pathNodes.size())
pathNodes.clear(); pathNodes.erase(pathNodes.begin() + t);
for (int i = 0; i < copy.size(); i++)
{
if (i != t)
pathNodes.push_back(copy[i]);
}
} }
Vector VectorPath::getValue(float usePercent) Vector VectorPath::getValue(float usePercent)

View file

@ -426,11 +426,11 @@ public:
void splice(const VectorPath &path, int sz); void splice(const VectorPath &path, int sz);
void prepend(const VectorPath &path); void prepend(const VectorPath &path);
void append(const VectorPath &path); void append(const VectorPath &path);
void removeNode(int i); void removeNode(unsigned int i);
void calculatePercentages(); void calculatePercentages();
float getLength(); float getLength();
void realPercentageCalc(); void realPercentageCalc();
void removeNodes(int startInclusive, int endInclusive); void removeNodes(unsigned int startInclusive, unsigned int endInclusive);
float getSubSectionLength(int startIncl, int endIncl); float getSubSectionLength(int startIncl, int endIncl);
protected: protected:
std::vector <VectorPathNode> pathNodes; std::vector <VectorPathNode> pathNodes;