summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-08-27 14:28:56 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-08-27 14:28:56 +0200
commit953e5524a99325ffb049f466b85ce13a62dc327a (patch)
tree36e1db7f68c94f1ad0135eed0dd1b3292c4a4ca3
parenta55be0217bdc2b4e15500f9a5cd4aba207d33fc7 (diff)
downloadqtlocation-mapboxgl-953e5524a99325ffb049f466b85ce13a62dc327a.tar.gz
fix basepath for headless stylesheets
-rw-r--r--include/mbgl/util/url.hpp1
-rw-r--r--src/renderer/painter_symbol.cpp63
-rw-r--r--src/util/url.cpp21
-rw-r--r--test/fixtures/fixture_request.cpp14
-rw-r--r--test/headless.cpp17
5 files changed, 60 insertions, 56 deletions
diff --git a/include/mbgl/util/url.hpp b/include/mbgl/util/url.hpp
index 14d9dd3160..a7e5291ec5 100644
--- a/include/mbgl/util/url.hpp
+++ b/include/mbgl/util/url.hpp
@@ -7,6 +7,7 @@ namespace mbgl {
namespace util {
std::string percentEncode(const std::string&);
+std::string percentDecode(const std::string&);
}
}
diff --git a/src/renderer/painter_symbol.cpp b/src/renderer/painter_symbol.cpp
index 66961b3183..c2d62bec7a 100644
--- a/src/renderer/painter_symbol.cpp
+++ b/src/renderer/painter_symbol.cpp
@@ -56,45 +56,38 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay
const timestamp currentTime = util::now();
std::deque<FrameSnapshot> &history = frameHistory.history;
+ if (history.size() >= 2) {
+ // Remove frames until only one is outside the duration, or until there are only three
+ while (history.size() > 3 && history[1].t + duration < currentTime) {
+ history.pop_front();
+ }
- // Remove frames until only one is outside the duration, or until there are only three
- while (history.size() > 3 && history[1].t + duration < currentTime) {
- history.pop_front();
- }
+ if (history[1].t + duration < currentTime) {
+ history[0].z = history[1].z;
+ }
- if (history[1].t + duration < currentTime) {
- history[0].z = history[1].z;
+ // Find the range of zoom levels we want to fade between
+ float startingZ = history.front().z;
+ const FrameSnapshot lastFrame = history.back();
+ float endingZ = lastFrame.z;
+ float lowZ = std::fmin(startingZ, endingZ);
+ float highZ = std::fmax(startingZ, endingZ);
+
+ // Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one
+ // duration
+ float zoomDiff = endingZ - history[1].z, timeDiff = lastFrame.t - history[1].t;
+ float fadedist = zoomDiff / (timeDiff / duration);
+
+ // At end of a zoom when the zoom stops changing continue pretending to zoom at that speed
+ // bump is how much farther it would have been if it had continued zooming at the same rate
+ float bump = (currentTime - lastFrame.t) / duration * fadedist;
+
+ textShader->setFadeDist(fadedist * 10);
+ textShader->setMinFadeZoom(std::floor(lowZ * 10));
+ textShader->setMaxFadeZoom(std::floor(highZ * 10));
+ textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10);
}
- assert("there should never be less than three frames in the history" &&
- (history.size() >= 3));
-
- // Find the range of zoom levels we want to fade between
- float startingZ = history.front().z;
- const FrameSnapshot lastFrame = history.back();
- float endingZ = lastFrame.z;
- float lowZ = std::fmin(startingZ, endingZ);
- float highZ = std::fmax(startingZ, endingZ);
-
- // Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one
- // duration
- float zoomDiff = endingZ - history[1].z, timeDiff = lastFrame.t - history[1].t;
- float fadedist = zoomDiff / (timeDiff / duration);
-
-#if defined(DEBUG)
-// if (std::isnan(fadedist))
-// fprintf(stderr, "fadedist should never be NaN\n");
-#endif
-
- // At end of a zoom when the zoom stops changing continue pretending to zoom at that speed
- // bump is how much farther it would have been if it had continued zooming at the same rate
- float bump = (currentTime - lastFrame.t) / duration * fadedist;
-
- textShader->setFadeDist(fadedist * 10);
- textShader->setMinFadeZoom(std::floor(lowZ * 10));
- textShader->setMaxFadeZoom(std::floor(highZ * 10));
- textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10);
-
// This defines the gamma around the SDF cutoff value.
const float sdfGamma = 1.0f / 10.0f;
diff --git a/src/util/url.cpp b/src/util/url.cpp
index b1a721d860..4f5113e8b9 100644
--- a/src/util/url.cpp
+++ b/src/util/url.cpp
@@ -4,6 +4,7 @@
#include <iomanip>
#include <sstream>
#include <string>
+#include <cstdlib>
namespace mbgl {
namespace util {
@@ -25,5 +26,25 @@ std::string percentEncode(const std::string& input) {
return encoded.str();
}
+std::string percentDecode(const std::string& input) {
+ std::string decoded;
+
+ auto it = input.begin();
+ const auto end = input.end();
+ char hex[3] = "00";
+
+ while (it != end) {
+ auto cur = std::find(it, end, '%');
+ decoded.append(it, cur);
+ it = cur;
+ if (cur != end) {
+ it += input.copy(hex, 2, cur - input.begin() + 1) + 1;
+ decoded += static_cast<char>(std::strtoul(hex, nullptr, 16));
+ }
+ }
+
+ return decoded;
+}
+
}
}
diff --git a/test/fixtures/fixture_request.cpp b/test/fixtures/fixture_request.cpp
index 1a7ed2ccc3..7e351ecfac 100644
--- a/test/fixtures/fixture_request.cpp
+++ b/test/fixtures/fixture_request.cpp
@@ -1,12 +1,15 @@
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/request.hpp>
#include <mbgl/util/uv_detail.hpp>
+#include <mbgl/util/url.hpp>
#include <mbgl/platform/log.hpp>
const std::string base_directory = []{
std::string fn = __FILE__;
fn.erase(fn.find_last_of("/"));
- return fn;
+ fn.erase(fn.find_last_of("/"));
+ fn.erase(fn.find_last_of("/"));
+ return fn + "/node_modules/mapbox-gl-test-suite/";
}();
@@ -23,14 +26,11 @@ platform::request_http(const std::string &url,
l = uv_default_loop();
}
- std::string clean_url = base_directory + "/" + url;
- auto pos = clean_url.find("://");
- if (pos != std::string::npos) {
- clean_url.replace(pos, 3, "/");
+ std::string clean_url = util::percentDecode(url);
+ if (clean_url.find("local://") == 0) {
+ clean_url = base_directory + clean_url.substr(8);
}
- std::replace(clean_url.begin(), clean_url.end(), '+', ' ');
-
std::shared_ptr<Request> req = std::make_shared<Request>(url, callback, loop);
int err;
diff --git a/test/headless.cpp b/test/headless.cpp
index a2f58e98d9..2453f1bb37 100644
--- a/test/headless.cpp
+++ b/test/headless.cpp
@@ -18,17 +18,12 @@
const std::string base_directory = []{
std::string fn = __FILE__;
fn.erase(fn.find_last_of("/"));
- return fn + "/../node_modules/mapbox-gl-test-suite/";
+ fn.erase(fn.find_last_of("/"));
+ return fn + "/node_modules/mapbox-gl-test-suite/";
}();
class HeadlessTest : public ::testing::TestWithParam<std::string> {};
-void ResolveLocalURL(rapidjson::Value& value, rapidjson::Document& doc) {
- std::string str { value.GetString(), value.GetStringLength() };
- str.replace(0, 8, base_directory); // local://
- value.SetString(str.c_str(), str.length(), doc.GetAllocator());
-}
-
TEST_P(HeadlessTest, render) {
using namespace mbgl;
@@ -43,12 +38,6 @@ TEST_P(HeadlessTest, render) {
ASSERT_EQ(false, styleDoc.HasParseError());
ASSERT_EQ(true, styleDoc.IsObject());
- if (styleDoc.HasMember("sprite")) {
- ResolveLocalURL(styleDoc["sprite"], styleDoc);
- }
-
- ResolveLocalURL(styleDoc["sources"]["mapbox"]["tiles"][rapidjson::SizeType(0)], styleDoc);
-
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
styleDoc.Accept(writer);
@@ -91,7 +80,7 @@ TEST_P(HeadlessTest, render) {
}
}
- map.setStyleJSON(style);
+ map.setStyleJSON(style, base_directory);
map.setAppliedClasses(classes);
view.resize(width, height);