Rename existing interpolate -> resample

This commit is contained in:
John Firebaugh
2014-08-05 17:19:33 -07:00
parent 1a475ec269
commit 2660b7bd1b
4 changed files with 20 additions and 20 deletions

61
src/geometry/resample.cpp Normal file
View File

@@ -0,0 +1,61 @@
#include <mbgl/geometry/resample.hpp>
#include <mbgl/util/math.hpp>
#include <cmath>
namespace mbgl {
const float minScale = 0.5f;
const std::array<std::vector<float>, 4> minScaleArrays = {{
/*1:*/ { minScale },
/*2:*/ { minScale, 2 },
/*4:*/ { minScale, 4, 2, 4 },
/*8:*/ { minScale, 8, 4, 8, 2, 8, 4, 8 }
}};
Anchors resample(const std::vector<Coordinate> &vertices, float spacing,
const float /*minScale*/, float maxScale, const float tilePixelRatio,
const int start) {
maxScale = std::round(std::fmax(std::fmin(8.0f, maxScale / 2.0f), 1.0f));
spacing *= tilePixelRatio / maxScale;
const size_t index = util::clamp<size_t>(std::floor(std::log(maxScale) / std::log(2)), 0, minScaleArrays.size() - 1);
const std::vector<float> &minScales = minScaleArrays[index];
const size_t len = minScales.size();
float distance = 0.0f;
float markedDistance = 0.0f;
int added = start;
Anchors points;
auto end = vertices.end() - 1;
int i = 0;
for (auto it = vertices.begin(); it != end; it++, i++) {
const Coordinate &a = *(it), b = *(it + 1);
float segmentDist = util::dist<float>(a, b);
float angle = util::angle_to(b, a);
while (markedDistance + spacing < distance + segmentDist) {
markedDistance += spacing;
float t = (markedDistance - distance) / segmentDist,
x = util::interp(a.x, b.x, t), y = util::interp(a.y, b.y, t),
s = minScales[added % len];
if (x >= 0 && x < 4096 && y >= 0 && y < 4096) {
points.emplace_back(x, y, angle, s, i);
}
added++;
}
distance += segmentDist;
}
return points;
}
}