From 9647c7c7ac24d8135c6840192e896ce6703c9e8d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 19 Feb 2018 13:09:31 -0800 Subject: [PATCH 1/2] [core] Stringify expression syntax, not function syntax --- src/mbgl/style/conversion/stringify.hpp | 131 ++--------------------- test/style/conversion/stringify.test.cpp | 25 ++--- 2 files changed, 19 insertions(+), 137 deletions(-) diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp index 7924a442c46..7b7727d7c4d 100644 --- a/src/mbgl/style/conversion/stringify.hpp +++ b/src/mbgl/style/conversion/stringify.hpp @@ -290,138 +290,19 @@ void stringify(Writer& writer, const Undefined&) { writer.Null(); } -template -void stringify(Writer& writer, const CategoricalValue& v) { - CategoricalValue::visit(v, [&] (const auto& v_) { stringify(writer, v_); }); -} - -template -class StringifyStops { -public: - Writer& writer; - - template - void operator()(const ExponentialStops& f) { - writer.Key("type"); - writer.String("exponential"); - writer.Key("base"); - writer.Double(f.base); - writer.Key("stops"); - stringifyStops(f.stops); - } - - template - void operator()(const IntervalStops& f) { - writer.Key("type"); - writer.String("interval"); - writer.Key("stops"); - stringifyStops(f.stops); - } - - template - void operator()(const CategoricalStops& f) { - writer.Key("type"); - writer.String("categorical"); - writer.Key("stops"); - stringifyStops(f.stops); - } - - template - void operator()(const IdentityStops&) { - writer.Key("type"); - writer.String("identity"); - } - - template - void operator()(const CompositeExponentialStops& f) { - writer.Key("type"); - writer.String("exponential"); - writer.Key("base"); - writer.Double(f.base); - writer.Key("stops"); - stringifyCompositeStops(f.stops); - } - - template - void operator()(const CompositeIntervalStops& f) { - writer.Key("type"); - writer.String("interval"); - writer.Key("stops"); - stringifyCompositeStops(f.stops); - } - - template - void operator()(const CompositeCategoricalStops& f) { - writer.Key("type"); - writer.String("categorical"); - writer.Key("stops"); - stringifyCompositeStops(f.stops); - } - -private: - template - void stringifyStops(const std::map& stops) { - writer.StartArray(); - for (const auto& stop : stops) { - writer.StartArray(); - stringify(writer, stop.first); - stringify(writer, stop.second); - writer.EndArray(); - } - writer.EndArray(); - } - - template - void stringifyCompositeStops(const std::map& stops) { - writer.StartArray(); - for (const auto& outer : stops) { - for (const auto& inner : outer.second) { - writer.StartArray(); - writer.StartObject(); - writer.Key("zoom"); - writer.Double(outer.first); - writer.Key("value"); - stringify(writer, inner.first); - writer.EndObject(); - stringify(writer, inner.second); - writer.EndArray(); - } - } - writer.EndArray(); - } -}; - template -void stringify(Writer& writer, const CameraFunction& f) { - writer.StartObject(); - CameraFunction::Stops::visit(f.stops, StringifyStops { writer }); - writer.EndObject(); +void stringify(Writer& writer, const CameraFunction& fn) { + stringify(writer, fn.getExpression().serialize()); } template -void stringify(Writer& writer, const SourceFunction& f) { - writer.StartObject(); - writer.Key("property"); - writer.String(f.property); - SourceFunction::Stops::visit(f.stops, StringifyStops { writer }); - if (f.defaultValue) { - writer.Key("default"); - stringify(writer, *f.defaultValue); - } - writer.EndObject(); +void stringify(Writer& writer, const SourceFunction& fn) { + stringify(writer, fn.getExpression().serialize()); } template -void stringify(Writer& writer, const CompositeFunction& f) { - writer.StartObject(); - writer.Key("property"); - writer.String(f.property); - CompositeFunction::Stops::visit(f.stops, StringifyStops { writer }); - if (f.defaultValue) { - writer.Key("default"); - stringify(writer, *f.defaultValue); - } - writer.EndObject(); +void stringify(Writer& writer, const CompositeFunction& fn) { + stringify(writer, fn.getExpression().serialize()); } template diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index 0b2940a0e0b..cb3b62dc62f 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -81,22 +81,22 @@ TEST(Stringify, Filter) { TEST(Stringify, CameraFunction) { ASSERT_EQ(stringify(CameraFunction(ExponentialStops { {{0, 1}}, 2 })), - "{\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}"); + "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]"); ASSERT_EQ(stringify(CameraFunction(IntervalStops { {{0, 1}} })), - "{\"type\":\"interval\",\"stops\":[[0.0,1.0]]}"); + "[\"step\",[\"zoom\"],0.0,1.0]"); } TEST(Stringify, SourceFunction) { ASSERT_EQ(stringify(SourceFunction("property", ExponentialStops { {{0, 1}}, 2 })), - "{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}"); + "[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]"); ASSERT_EQ(stringify(SourceFunction("property", IntervalStops { {{0, 1}} })), - "{\"property\":\"property\",\"type\":\"interval\",\"stops\":[[0.0,1.0]]}"); + "[\"step\",[\"number\",[\"get\",\"property\"]],0.0,1.0]"); ASSERT_EQ(stringify(SourceFunction("property", CategoricalStops { {{CategoricalValue(true), 1}} })), - "{\"property\":\"property\",\"type\":\"categorical\",\"stops\":[[true,1.0]]}"); + "[\"case\",[\"boolean\",[\"get\",\"property\"]],1.0,[\"error\"]]"); ASSERT_EQ(stringify(SourceFunction("property", IdentityStops {})), - "{\"property\":\"property\",\"type\":\"identity\"}"); + "[\"number\",[\"get\",\"property\"]]"); ASSERT_EQ(stringify(SourceFunction("property", IdentityStops {}, 0.0f)), - "{\"property\":\"property\",\"type\":\"identity\",\"default\":0.0}"); + "[\"number\",[\"get\",\"property\"]]"); } TEST(Stringify, CompositeFunction) { @@ -108,16 +108,17 @@ TEST(Stringify, CompositeFunction) { }, 2 }, 0.0f)), - "{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0," - "\"stops\":[" - "[{\"zoom\":0.0,\"value\":0.0},1.0]," - "[{\"zoom\":1.0,\"value\":0.0},1.0]],\"default\":0.0}"); + "[\"interpolate\"," + "[\"exponential\",1.0]," + "[\"zoom\"]," + "0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]," + "1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]]"); } TEST(Stringify, PropertyValue) { ASSERT_EQ(stringify(PropertyValue(1)), "1.0"); ASSERT_EQ(stringify(PropertyValue(CameraFunction(ExponentialStops { {{0, 1}}, 2 }))), - "{\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}"); + "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]"); } TEST(Stringify, Layout) { From af73758f09cf7a96ce726bc994389119cb673884 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 19 Feb 2018 13:09:31 -0800 Subject: [PATCH 2/2] [core] Update mapbox-gl-js --- mapbox-gl-js | 2 +- platform/node/test/ignores.json | 2 ++ src/mbgl/shaders/line_pattern.cpp | 10 ++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mapbox-gl-js b/mapbox-gl-js index 703bb35eb35..4cd5570ad3e 160000 --- a/mapbox-gl-js +++ b/mapbox-gl-js @@ -1 +1 @@ -Subproject commit 703bb35eb35ab045f2e90af2aa29d985474db293 +Subproject commit 4cd5570ad3ed3e0ad71e2f795e795a78f5ccf603 diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index da79ac8a416..840daa20498 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -1,4 +1,6 @@ { + "query-tests/circle-pitch-scale/viewport-inside-align-map": "https://github.com/mapbox/mapbox-gl-native/issues/10615", + "query-tests/circle-pitch-scale/viewport-inside-align-viewport": "https://github.com/mapbox/mapbox-gl-native/issues/10615", "query-tests/geometry/multilinestring": "needs investigation", "query-tests/geometry/multipolygon": "needs investigation", "query-tests/geometry/polygon": "needs investigation", diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index f8d785ade93..be88255e3cc 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -215,8 +215,14 @@ void main() { float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); - float y_a = 0.5 + (v_normal.y * v_width2.s / u_pattern_size_a.y); - float y_b = 0.5 + (v_normal.y * v_width2.s / u_pattern_size_b.y); + + // v_normal.y is 0 at the midpoint of the line, -1 at the lower edge, 1 at the upper edge + // we clamp the line width outset to be between 0 and half the pattern height plus padding (2.0) + // to ensure we don't sample outside the designated symbol on the sprite sheet. + // 0.5 is added to shift the component to be bounded between 0 and 1 for interpolation of + // the texture coordinate + float y_a = 0.5 + (v_normal.y * clamp(v_width2.s, 0.0, (u_pattern_size_a.y + 2.0) / 2.0) / u_pattern_size_a.y); + float y_b = 0.5 + (v_normal.y * clamp(v_width2.s, 0.0, (u_pattern_size_b.y + 2.0) / 2.0) / u_pattern_size_b.y); vec2 pos_a = mix(u_pattern_tl_a / u_texsize, u_pattern_br_a / u_texsize, vec2(x_a, y_a)); vec2 pos_b = mix(u_pattern_tl_b / u_texsize, u_pattern_br_b / u_texsize, vec2(x_b, y_b));