1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Clean up excessive operations and logs

This commit is contained in:
Tomasz Zieliński 2024-05-08 15:51:42 +02:00
parent 37d062f1eb
commit 2297e09fcb
3 changed files with 22 additions and 19 deletions

View File

@ -523,6 +523,15 @@ namespace vstd
}
}
// Removes all duplicate elements from the vector
template<typename T>
void unique(std::vector<T> &vec)
{
std::sort(vec.begin(), vec.end());
auto newEnd = std::unique(vec.begin(), vec.end());
vec.erase(newEnd, vec.end());
}
template<typename InputRange, typename OutputIterator, typename Predicate>
OutputIterator copy_if(const InputRange &input, OutputIterator result, Predicate pred)
{

View File

@ -44,6 +44,11 @@ bool Point2D::operator < (const Point2D& other) const
return y() < other.y();
}
bool Point2D::operator == (const Point2D& other) const
{
return vstd::isAlmostEqual(x(), other.x()) && vstd::isAlmostEqual(y(), other.y());
}
std::string Point2D::toString() const
{
//Performance is important here
@ -169,30 +174,18 @@ std::set<Point2D> PenroseTiling::generatePenroseTiling(size_t numZones, CRandomG
split(t, points, indices, DEPTH);
}
// Remove duplicates
vstd::unique(points);
std::set<Point2D> uniquePoints(points.begin(), points.end());
std::vector<Point2D> uniquePointsVec(uniquePoints.begin(), uniquePoints.end());
logGlobal->info("Generated %d vertices and %d unique vertices", points.size(), uniquePointsVec.size());
// Find center of the mass, shift that center to (0.5, 0.5)
Point2D center = Point2D(0.0f, 0.0f);
for (const auto & point : uniquePointsVec)
// Shift center to (0.5, 0.5)
for (auto & point : points)
{
center = center + point;
};
center = center / uniquePointsVec.size();
// This center is very close to (0.0, 0.0), anyway
logGlobal->info("Penrose tiling center: %s", center.toString().c_str());
for (auto & point : uniquePointsVec)
{
point = point - center + Point2D(0.5f, 0.5f);
point = point + Point2D(0.5f, 0.5f);
};
// For 8X8 map, only 650 out of 15971 points are in the range
// For 8XM8 map, only 650 out of 15971 points are in the range
vstd::copy_if(uniquePointsVec, vstd::set_inserter(finalPoints), [](const Point2D point)
vstd::copy_if(points, vstd::set_inserter(finalPoints), [](const Point2D point)
{
return vstd::isbetween(point.x(), 0.f, 1.0f) && vstd::isbetween(point.y(), 0.f, 1.0f);
});

View File

@ -34,6 +34,7 @@ public:
Point2D rotated(float radians) const;
bool operator < (const Point2D& other) const;
bool operator == (const Point2D& other) const;
std::string toString() const;
};