Reduce reallocations and memory usage in gyroid
This commit is contained in:
parent
b9901f1730
commit
5932881291
1 changed files with 3 additions and 0 deletions
|
@ -35,6 +35,7 @@ static inline Polyline make_wave(
|
||||||
{
|
{
|
||||||
std::vector<Vec2d> points = one_period;
|
std::vector<Vec2d> points = one_period;
|
||||||
double period = points.back()(0);
|
double period = points.back()(0);
|
||||||
|
points.reserve(one_period.size() * floor(width / period));
|
||||||
points.pop_back();
|
points.pop_back();
|
||||||
int n = points.size();
|
int n = points.size();
|
||||||
do {
|
do {
|
||||||
|
@ -44,6 +45,7 @@ static inline Polyline make_wave(
|
||||||
|
|
||||||
// and construct the final polyline to return:
|
// and construct the final polyline to return:
|
||||||
Polyline polyline;
|
Polyline polyline;
|
||||||
|
polyline.points.reserve(points.size());
|
||||||
for (auto& point : points) {
|
for (auto& point : points) {
|
||||||
point(1) += offset;
|
point(1) += offset;
|
||||||
point(1) = clamp(0., height, double(point(1)));
|
point(1) = clamp(0., height, double(point(1)));
|
||||||
|
@ -60,6 +62,7 @@ static std::vector<Vec2d> make_one_period(double width, double scaleFactor, doub
|
||||||
std::vector<Vec2d> points;
|
std::vector<Vec2d> points;
|
||||||
double dx = M_PI_2; // exact coordinates on main inflexion lobes
|
double dx = M_PI_2; // exact coordinates on main inflexion lobes
|
||||||
double limit = std::min(2*M_PI, width);
|
double limit = std::min(2*M_PI, width);
|
||||||
|
points.reserve(ceil(limit / tolerance / 3));
|
||||||
for (double x = 0.; x < limit + EPSILON; x += dx) { // so the last point is there too
|
for (double x = 0.; x < limit + EPSILON; x += dx) { // so the last point is there too
|
||||||
x = std::min(x, limit);
|
x = std::min(x, limit);
|
||||||
points.emplace_back(Vec2d(x, f(x, z_sin, z_cos, vertical, flip)));
|
points.emplace_back(Vec2d(x, f(x, z_sin, z_cos, vertical, flip)));
|
||||||
|
|
Loading…
Reference in a new issue