From 92124d3aa1f53e40b174d82e29771bd292bc2001 Mon Sep 17 00:00:00 2001 From: artemp Date: Mon, 3 Nov 2014 15:44:27 +0000 Subject: [PATCH 01/22] make util::utf8_to_utf32::convert() static --- include/mbgl/util/utf.hpp | 3 +-- src/renderer/symbol_bucket.cpp | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/include/mbgl/util/utf.hpp b/include/mbgl/util/utf.hpp index d36cfae7e..d6ba2a1f2 100644 --- a/include/mbgl/util/utf.hpp +++ b/include/mbgl/util/utf.hpp @@ -11,8 +11,7 @@ namespace util { class utf8_to_utf32 { public: - explicit utf8_to_utf32() {} - std::u32string convert(std::string const& utf8) + static std::u32string convert(std::string const& utf8) { boost::u8_to_u32_iterator begin(utf8.begin()); boost::u8_to_u32_iterator end(utf8.end()); diff --git a/src/renderer/symbol_bucket.cpp b/src/renderer/symbol_bucket.cpp index 542c109db..37ff4a0a6 100644 --- a/src/renderer/symbol_bucket.cpp +++ b/src/renderer/symbol_bucket.cpp @@ -52,8 +52,6 @@ std::vector SymbolBucket::processFeatures(const VectorTileLayer & return features; } - util::utf8_to_utf32 ucs4conv; - // Determine and load glyph ranges std::set ranges; @@ -72,7 +70,7 @@ std::vector SymbolBucket::processFeatures(const VectorTileLayer & u8string = platform::lowercase(u8string); } - ft.label = ucs4conv.convert(u8string); + ft.label = util::utf8_to_utf32::convert(u8string); if (ft.label.size()) { // Loop through all characters of this text and collect unique codepoints. From 1e2c5f988e9e2a6cdd91d7d6644ffd17211cde25 Mon Sep 17 00:00:00 2001 From: artemp Date: Mon, 3 Nov 2014 16:00:40 +0000 Subject: [PATCH 02/22] add -s,--style command line option to specify path to the style e.g ./build/Release/mapbox-gl -s ./styles/styles/bright-v5.json --- linux/main.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/linux/main.cpp b/linux/main.cpp index 10d5d4582..b28ad84d1 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -11,7 +11,6 @@ #include - GLFWView *view = nullptr; void quit_handler(int) { @@ -28,16 +27,32 @@ int main(int argc, char *argv[]) { mbgl::Log::Set(); int fullscreen_flag = 0; + std::string style; const struct option long_options[] = { - {"fullscreen", no_argument, &fullscreen_flag, 1}, + {"fullscreen", no_argument, &fullscreen_flag, 'f'}, + {"style", required_argument, 0, 's'}, {0, 0, 0, 0} }; while (true) { int option_index = 0; - int c = getopt_long(argc, argv, "f", long_options, &option_index); - if (c == -1) break; + int opt = getopt_long(argc, argv, "fs:", long_options, &option_index); + if (opt == -1) break; + switch (opt) + { + case 0: + if (long_options[option_index].flag != 0) + break; + case 'f': + // handle fullscreen_flag + break; + case 's': + style = std::string("file://") + std::string(optarg); + default: + break; + } + } // sigint handling @@ -65,7 +80,9 @@ int main(int argc, char *argv[]) { } // Load style - const std::string style = std::string("file://") + uv::cwd() + std::string("/../../styles/styles/bright-v5.json"); + if (style.empty()) + style = std::string("file://") + uv::cwd() + std::string("/../../styles/styles/bright-v5.json"); + map.setStyleURL(style); int ret = view->run(); From 4efb441008e361042c943410df486cebddf44586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 4 Nov 2014 12:45:01 +0100 Subject: [PATCH 03/22] Run tests using http requests We now start a local HTTP server on port 2900 that serves the test fixtures. This is the same port we also use in the JS test suite fixes #532 --- test/fixtures/fixture_request.cpp | 72 ------------------------------- test/headless.cpp | 64 +++++++++++++++++++++------ test/suite | 2 +- test/test.gyp | 2 - 4 files changed, 52 insertions(+), 88 deletions(-) delete mode 100644 test/fixtures/fixture_request.cpp diff --git a/test/fixtures/fixture_request.cpp b/test/fixtures/fixture_request.cpp deleted file mode 100644 index cc01760ae..000000000 --- a/test/fixtures/fixture_request.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - - -const std::string base_directory = []{ - std::string fn = __FILE__; - fn.erase(fn.find_last_of("/")); - fn.erase(fn.find_last_of("/")); - fn.erase(fn.find_last_of("/")); - return fn + "/test/suite/"; -}(); - -namespace mbgl { - -void HTTPRequestBaton::start(const util::ptr &baton) { - assert(uv_thread_self() == baton->thread_id); - - std::string clean_url = util::percentDecode(baton->path); - if (clean_url.find("local://") == 0) { - clean_url = base_directory + clean_url.substr(8); - } - - baton->response = std::make_unique(); - FILE *file = fopen(clean_url.c_str(),"rb"); - if (file != NULL) { - fseek(file, 0, SEEK_END); - const size_t size = ftell(file); - fseek(file, 0, SEEK_SET); - baton->response->data.resize(size); - const size_t read = fread(&baton->response->data[0], 1, size, file); - fclose(file); - - if (read == size) { - baton->response->code = 200; - baton->type = HTTPResponseType::Successful; - } else { - baton->response->code = 500; - baton->type = HTTPResponseType::PermanentError; - baton->response->message = "Read bytes differed from file size"; - } - } else { - baton->type = HTTPResponseType::PermanentError; - baton->response->code = 404; - } - - uv_async_send(baton->async); -} - -void HTTPRequestBaton::stop(const util::ptr &/*baton*/) { - fprintf(stderr, "HTTP request cannot be canceled because it is answered immediately"); - abort(); -} - -namespace platform { - -std::string defaultCacheDatabase() { - // Disables the cache. - return ""; -} - -} - -} diff --git a/test/headless.cpp b/test/headless.cpp index 4605d7f28..98aee6beb 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -15,22 +15,58 @@ #include "./fixtures/fixture_log.hpp" #include +#include +#include -const std::string base_directory = []{ - std::string fn = __FILE__; - fn.erase(fn.find_last_of("/")); - fn.erase(fn.find_last_of("/")); - return fn + "/test/suite/"; -}(); +std::string base_directory; -auto display_ = std::make_shared(); + +class ServerEnvironment : public ::testing::Environment { +public: + virtual void SetUp() { + pid = fork(); + if (pid < 0) { + throw std::runtime_error("Cannot create web server"); + } else if (pid == 0) { + int ret = execve((base_directory + "bin/server.py").c_str(), nullptr, nullptr); + // This call should not return. In case execve failed, we exit anyway. + if (ret < 0) { + fprintf(stderr, "Failed to start server: %s\n", strerror(errno)); + } + exit(0); + } else { + display = std::make_shared(); + } + } + virtual void TearDown() { + ASSERT_TRUE(pid); + kill(pid, SIGHUP); + } + + std::shared_ptr display; + +private: + pid_t pid = 0; +}; + + +ServerEnvironment* env = nullptr; + + +GTEST_API_ int main(int argc, char *argv[]) { + base_directory = std::string(dirname(argv[0])) + "/" + dirname(const_cast(__FILE__)) + "/suite/"; + testing::InitGoogleTest(&argc, argv); + env = new ServerEnvironment(); + ::testing::AddGlobalTestEnvironment(env); + return RUN_ALL_TESTS(); +} class HeadlessTest : public ::testing::TestWithParam {}; TEST_P(HeadlessTest, render) { using namespace mbgl; - const std::string &base = GetParam(); + const std::string& base = GetParam(); std::string style = util::read_file(base_directory + "tests/" + base + "/style.json"); std::string info = util::read_file(base_directory + "tests/" + base + "/info.json"); @@ -55,8 +91,10 @@ TEST_P(HeadlessTest, render) { Log::Set(); for (auto it = infoDoc.MemberBegin(), end = infoDoc.MemberEnd(); it != end; it++) { - const std::string name { it->name.GetString(), it->name.GetStringLength() }; - const rapidjson::Value &value = it->value; + const std::string name { + it->name.GetString(), it->name.GetStringLength() + }; + const rapidjson::Value& value = it->value; ASSERT_TRUE(value.IsObject()); if (value.HasMember("center")) ASSERT_TRUE(value["center"].IsArray()); @@ -72,16 +110,16 @@ TEST_P(HeadlessTest, render) { std::vector classes; if (value.HasMember("classes")) { - const rapidjson::Value &js_classes = value["classes"]; + const rapidjson::Value& js_classes = value["classes"]; ASSERT_TRUE(js_classes.IsArray()); for (rapidjson::SizeType i = 0; i < js_classes.Size(); i++) { - const rapidjson::Value &js_class = js_classes[i]; + const rapidjson::Value& js_class = js_classes[i]; ASSERT_TRUE(js_class.IsString()); classes.push_back({ js_class.GetString(), js_class.GetStringLength() }); } } - HeadlessView view(display_); + HeadlessView view(env->display); Map map(view); map.setStyleJSON(style, base_directory); diff --git a/test/suite b/test/suite index 1651a3df4..8f03d5dab 160000 --- a/test/suite +++ b/test/suite @@ -1 +1 @@ -Subproject commit 1651a3df444ff83c98f6eff00679d6b84dc8845e +Subproject commit 8f03d5dabfb7ec6447696b25691794280f399477 diff --git a/test/test.gyp b/test/test.gyp index 8ae475d1c..96e0917a5 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -162,9 +162,7 @@ 'product_name': 'test_headless', 'type': 'executable', 'sources': [ - './main.cpp', './headless.cpp', - './fixtures/fixture_request.cpp', './fixtures/fixture_log.cpp', ], 'conditions': [ From b6c10e44c08fb7cdb16f8be80fc29e8054eafc05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 4 Nov 2014 13:58:31 +0100 Subject: [PATCH 04/22] pass array with a single nullptr instead of nullptr for compatibility --- test/headless.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/headless.cpp b/test/headless.cpp index 98aee6beb..26aff177f 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -28,7 +28,7 @@ public: if (pid < 0) { throw std::runtime_error("Cannot create web server"); } else if (pid == 0) { - int ret = execve((base_directory + "bin/server.py").c_str(), nullptr, nullptr); + int ret = execve((base_directory + "bin/server.py").c_str(), { nullptr }, { nullptr }); // This call should not return. In case execve failed, we exit anyway. if (ret < 0) { fprintf(stderr, "Failed to start server: %s\n", strerror(errno)); From 75889d812402ac2b75d891576a1c37cb43c8eaf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 4 Nov 2014 06:44:50 -0800 Subject: [PATCH 05/22] replace strftime_l with our custom formatter --- include/mbgl/util/time.hpp | 6 ++++++ platform/default/http_request_baton_curl.cpp | 14 ++++---------- src/util/time.cpp | 13 +++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/mbgl/util/time.hpp b/include/mbgl/util/time.hpp index 9d61edf75..e8afbeff6 100644 --- a/include/mbgl/util/time.hpp +++ b/include/mbgl/util/time.hpp @@ -1,7 +1,9 @@ #ifndef MBGL_UTIL_TIME #define MBGL_UTIL_TIME +#include #include +#include namespace mbgl { @@ -15,6 +17,10 @@ namespace util { // comparisons between different timestamps produce meaningful values. timestamp now(); + +// Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT" +std::string rfc1123(std::time_t time); + } // used for time conversions diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index 0c3d2b43f..80eed2767 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -9,8 +10,6 @@ #include #include #include -#include -#include // This file contains code from http://curl.haxx.se/libcurl/c/multi-uv.html: @@ -369,9 +368,6 @@ void start_request(void *const ptr) { util::ptr &baton = *baton_guard.get(); assert(baton); - // Create a C locale - static locale_t locale = newlocale(LC_ALL_MASK, nullptr, nullptr); - CURL *handle = nullptr; if (!handles.empty()) { handle = handles.front(); @@ -390,11 +386,9 @@ void start_request(void *const ptr) { const std::string header = std::string("If-None-Match: ") + baton->response->etag; context->headers = curl_slist_append(context->headers, header.c_str()); } else if (baton->response->modified) { - const time_t modified = baton->response->modified; - struct tm *timeinfo = std::gmtime(&modified); - char buffer[64]; - strftime_l(buffer, 64, "If-Modified-Since: %a, %d %b %Y %H:%M:%S GMT", timeinfo, locale); - context->headers = curl_slist_append(context->headers, buffer); + const std::string time = std::string("If-Modified-Since: ") + + util::rfc1123(baton->response->modified); + context->headers = curl_slist_append(context->headers, time.c_str()); } } diff --git a/src/util/time.cpp b/src/util/time.cpp index 4cd8077f9..1953975b1 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -8,5 +8,18 @@ timestamp now() { return uv_hrtime(); } +static const char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + +std::string rfc1123(std::time_t time) { + std::tm info; + gmtime_r(&time, &info); + char buffer[30]; + snprintf(buffer, 30, "%s, %02d %s %4d %02d:%02d:%02d GMT", week[info.tm_wday], info.tm_mday, + months[info.tm_mon], 1900 + info.tm_year, info.tm_hour, info.tm_min, info.tm_sec); + return buffer; +} + } } From 67eae5724a8e1caa36ca492ebe5f7e0d01b42ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 4 Nov 2014 06:45:06 -0800 Subject: [PATCH 06/22] use execv and pass non-inline argument for gcc --- test/headless.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/headless.cpp b/test/headless.cpp index 26aff177f..361f3a9fc 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -28,7 +28,8 @@ public: if (pid < 0) { throw std::runtime_error("Cannot create web server"); } else if (pid == 0) { - int ret = execve((base_directory + "bin/server.py").c_str(), { nullptr }, { nullptr }); + char *arg[] = { nullptr }; + int ret = execv((base_directory + "bin/server.py").c_str(), arg); // This call should not return. In case execve failed, we exit anyway. if (ret < 0) { fprintf(stderr, "Failed to start server: %s\n", strerror(errno)); From 885d61e5def90678c89235e7b79750375f180220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 4 Nov 2014 06:45:21 -0800 Subject: [PATCH 07/22] use dirname() on copies of the parameter only glibc's dirname() modifies the parameter --- test/headless.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/headless.cpp b/test/headless.cpp index 361f3a9fc..657bab4c3 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -55,7 +55,11 @@ ServerEnvironment* env = nullptr; GTEST_API_ int main(int argc, char *argv[]) { - base_directory = std::string(dirname(argv[0])) + "/" + dirname(const_cast(__FILE__)) + "/suite/"; + // Note: glibc's dirname() **modifies** the argument and can't handle static strings. + std::string argv0 { argv[0] }; argv0 = dirname(const_cast(argv0.c_str())); + std::string file { __FILE__ }; file = dirname(const_cast(file.c_str())); + base_directory = argv0 + "/" + file + "/suite/"; + testing::InitGoogleTest(&argc, argv); env = new ServerEnvironment(); ::testing::AddGlobalTestEnvironment(env); From e5f7e3e96cbdf1559affe0fbd818ddafbe478d82 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 4 Nov 2014 14:53:45 +0000 Subject: [PATCH 08/22] add basic toupper/tolower text conversions tests #309 --- test/test.gyp | 23 +++++++++++++++++++++-- test/text_conversions.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 test/text_conversions.cpp diff --git a/test/test.gyp b/test/test.gyp index 8ae475d1c..fa799b655 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -60,7 +60,7 @@ '../mapboxgl.gyp:mbgl-standalone', ], 'conditions': [ - ['OS == "mac"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)' ] } + ['OS == "mac"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)'] } }, { 'libraries': [ '<@(ldflags)' ], }] @@ -188,7 +188,25 @@ '<(platform_library)', ] }, - + { 'target_name': 'text_conversions', + 'product_name': 'test_text_conversions', + 'type': 'executable', + 'sources': [ + './main.cpp', + './text_conversions.cpp', + ], + 'dependencies': [ + '../deps/gtest/gtest.gyp:gtest', + '../mapboxgl.gyp:mbgl-standalone', + '<(platform_library)', + ], + 'conditions': [ + ['OS == "mac"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)', '-framework Foundation' ] } + }, { + 'libraries': [ '<@(ldflags)'], + }] + ] + }, # Build all targets { 'target_name': 'test', 'type': 'none', @@ -202,6 +220,7 @@ 'headless', 'style_parser', 'comparisons', + 'text_conversions', ], } ] diff --git a/test/text_conversions.cpp b/test/text_conversions.cpp new file mode 100644 index 000000000..4f71d6a61 --- /dev/null +++ b/test/text_conversions.cpp @@ -0,0 +1,37 @@ +#include +#include "gtest/gtest.h" + +#include +#include + +using namespace mbgl; + +TEST(TextConversions, to_upper) { + EXPECT_EQ(std::string("STREET"), platform::uppercase("strEEt")); // EN + EXPECT_EQ(std::string("ROAD"), platform::uppercase("rOAd")); // EN + + EXPECT_EQ(std::string("STRASSE"), platform::uppercase("straße")); // DE + EXPECT_EQ(std::string("MASSE"), platform::uppercase("maße")); // DE + EXPECT_EQ(std::string("WEISSKOPFSEEADLER"), platform::uppercase("weißkopfseeadler")); // DE + + EXPECT_EQ(std::string("AZƏRBAYCAN"), platform::uppercase("Azərbaycan")); // AZ + + EXPECT_EQ(std::string("ὈΔΥΣΣΕΎΣ"), platform::uppercase("Ὀδυσσεύς")); // GR +} + + +TEST(TextConversions, to_lower) { + EXPECT_EQ(std::string("street"), platform::lowercase("strEEt")); // EN + EXPECT_EQ(std::string("road"), platform::lowercase("rOAd")); // EN + + EXPECT_EQ(std::string("straße"), platform::lowercase("Straße")); // DE + EXPECT_EQ(std::string("strasse"), platform::lowercase("STRASSE")); // DE + EXPECT_EQ(std::string("masse"), platform::lowercase("MASSE")); // DE + EXPECT_EQ(std::string("weisskopfseeadler"), platform::lowercase("weiSSkopfseeadler")); // DE + + EXPECT_EQ(std::string("azərbaycan"), platform::lowercase("AZƏRBAYCAN")); // AZ + + //EXPECT_EQ(std::string("ὀδυσσεύσ"), platform::lowercase("ὈΔΥΣΣΕΎΣ")); // GR + // nunicode can't map last Σ to word-ending ς + +} From 76066c6afda6c5472399d29ced8970363e4b9a33 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 4 Nov 2014 14:56:12 +0000 Subject: [PATCH 09/22] format --- test/test.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.gyp b/test/test.gyp index fa799b655..b9d91a374 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -42,7 +42,7 @@ '../mapboxgl.gyp:mbgl-standalone', ], 'conditions': [ - ['OS == "mac"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)' ] } + ['OS == "mac"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)'] } }, { 'libraries': [ '<@(ldflags)' ], }] From 0e3f111a79ecd81f0bd4663daa0a1cb6deca161d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 4 Nov 2014 16:35:08 +0100 Subject: [PATCH 10/22] also use custom formatter for OS X --- platform/darwin/http_request_baton_cocoa.mm | 13 +++---------- test/suite | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/platform/darwin/http_request_baton_cocoa.mm b/platform/darwin/http_request_baton_cocoa.mm index a9992fad8..03fa3bb82 100644 --- a/platform/darwin/http_request_baton_cocoa.mm +++ b/platform/darwin/http_request_baton_cocoa.mm @@ -1,14 +1,13 @@ #include #include #include +#include #include #include #import -#include -#include namespace mbgl { @@ -21,9 +20,6 @@ void HTTPRequestBaton::start(const util::ptr &ptr) { // Starts the request. util::ptr baton = ptr; - // Create a C locale - static locale_t locale = newlocale(LC_ALL_MASK, nullptr, nullptr); - dispatch_once(&request_initialize, ^{ NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; sessionConfig.timeoutIntervalForResource = 30; @@ -39,11 +35,8 @@ void HTTPRequestBaton::start(const util::ptr &ptr) { if (!baton->response->etag.empty()) { [request addValue:@(baton->response->etag.c_str()) forHTTPHeaderField:@"If-None-Match"]; } else if (baton->response->modified) { - const time_t modified = baton->response->modified; - struct tm *timeinfo = std::gmtime(&modified); - char buffer[32]; - strftime_l(buffer, 32, "%a, %d %b %Y %H:%M:%S GMT", timeinfo, locale); - [request addValue:@(buffer) forHTTPHeaderField:@"If-Modified-Since"]; + const std::string time = util::rfc1123(baton->response->modified); + [request addValue:@(time.c_str()) forHTTPHeaderField:@"If-Modified-Since"]; } } diff --git a/test/suite b/test/suite index 8f03d5dab..0f5f8f302 160000 --- a/test/suite +++ b/test/suite @@ -1 +1 @@ -Subproject commit 8f03d5dabfb7ec6447696b25691794280f399477 +Subproject commit 0f5f8f302202261c19810ea856fdcfb624989731 From 0d6bca0e7e46588f57b178a4593fdb02f5c4592f Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Sun, 26 Oct 2014 17:31:06 -0400 Subject: [PATCH 11/22] line-offset -> line-gap-width --- include/mbgl/style/property_key.hpp | 2 +- include/mbgl/style/style_properties.hpp | 2 +- src/renderer/painter_line.cpp | 3 ++- src/style/property_fallback.cpp | 2 +- src/style/style_layer.cpp | 2 +- src/style/style_parser.cpp | 4 ++-- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/mbgl/style/property_key.hpp b/include/mbgl/style/property_key.hpp index cbf9ad2ac..efeebf024 100644 --- a/include/mbgl/style/property_key.hpp +++ b/include/mbgl/style/property_key.hpp @@ -21,7 +21,7 @@ enum class PropertyKey { LineTranslateY, LineTranslateAnchor, LineWidth, - LineOffset, + LineGapWidth, LineBlur, LineDashArray, // for transitions only LineDashLand, diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp index 0a5e99341..c44b7c34c 100644 --- a/include/mbgl/style/style_properties.hpp +++ b/include/mbgl/style/style_properties.hpp @@ -34,7 +34,7 @@ struct LineProperties { std::array translate = {{ 0, 0 }}; TranslateAnchorType translateAnchor = TranslateAnchorType::Map; float width = 1; - float offset = 0; + float gap_width = 0; float blur = 0; std::array dash_array = {{ 1, -1 }}; std::string image; diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index 9893f032d..93d8db1a5 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -17,7 +17,8 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c float antialiasing = 1 / state.getPixelRatio(); float width = properties.width; - float offset = properties.offset / 2; + float offset = properties.gap_width / 2; + offset = offset == 0 ? offset : offset + width / 2; float blur = properties.blur + antialiasing; // These are the radii of the line. We are limiting it to 16, which will result diff --git a/src/style/property_fallback.cpp b/src/style/property_fallback.cpp index 572c4b7a8..965baf6c4 100644 --- a/src/style/property_fallback.cpp +++ b/src/style/property_fallback.cpp @@ -18,7 +18,7 @@ const std::map PropertyFallbackValue::properties = { { PropertyKey::LineTranslateY, defaultStyleProperties().translate[1] }, { PropertyKey::LineTranslateAnchor, defaultStyleProperties().translateAnchor }, { PropertyKey::LineWidth, defaultStyleProperties().width }, - { PropertyKey::LineOffset, defaultStyleProperties().offset }, + { PropertyKey::LineGapWidth, defaultStyleProperties().gap_width }, { PropertyKey::LineBlur, defaultStyleProperties().blur }, { PropertyKey::LineDashLand, defaultStyleProperties().dash_array[0] }, { PropertyKey::LineDashGap, defaultStyleProperties().dash_array[1] }, diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index ded73c044..e58756afa 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -183,7 +183,7 @@ void StyleLayer::applyStyleProperties(const float z, const times applyTransitionedStyleProperty(PropertyKey::LineTranslateY, line.translate[1], z, now); applyStyleProperty(PropertyKey::LineTranslateAnchor, line.translateAnchor, z, now); applyTransitionedStyleProperty(PropertyKey::LineWidth, line.width, z, now); - applyTransitionedStyleProperty(PropertyKey::LineOffset, line.offset, z, now); + applyTransitionedStyleProperty(PropertyKey::LineGapWidth, line.gap_width, z, now); applyTransitionedStyleProperty(PropertyKey::LineBlur, line.blur, z, now); applyTransitionedStyleProperty(PropertyKey::LineDashLand, line.dash_array[0], z, now); applyTransitionedStyleProperty(PropertyKey::LineDashGap, line.dash_array[1], z, now); diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 47ff0c30a..5c4ed0cb1 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -586,8 +586,8 @@ void StyleParser::parseStyle(JSVal value, ClassProperties &klass) { parseOptionalProperty("line-translate-anchor", Key::LineTranslateAnchor, klass, value); parseOptionalProperty>("line-width", Key::LineWidth, klass, value); parseOptionalProperty("line-width-transition", Key::LineWidth, klass, value); - parseOptionalProperty>("line-offset", Key::LineOffset, klass, value); - parseOptionalProperty("line-offset-transition", Key::LineOffset, klass, value); + parseOptionalProperty>("line-gap-width", Key::LineGapWidth, klass, value); + parseOptionalProperty("line-gap-width-transition", Key::LineGapWidth, klass, value); parseOptionalProperty>("line-blur", Key::LineBlur, klass, value); parseOptionalProperty("line-blur-transition", Key::LineBlur, klass, value); parseOptionalProperty>("line-dasharray", { Key::LineDashLand, Key::LineDashGap }, klass, value); From 3d18160fe4fa08520dc508cf51283534669e0ec4 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Sun, 26 Oct 2014 17:48:06 -0400 Subject: [PATCH 12/22] More concise --- src/renderer/painter_line.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index 93d8db1a5..bf8e1b060 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -17,8 +17,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c float antialiasing = 1 / state.getPixelRatio(); float width = properties.width; - float offset = properties.gap_width / 2; - offset = offset == 0 ? offset : offset + width / 2; + float offset = properties.gap_width == 0 ? 0 : (properties.gap_width + width) / 2; float blur = properties.blur + antialiasing; // These are the radii of the line. We are limiting it to 16, which will result From 37922605f810b3ce5075b6dd049ddb0cda62f1c3 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Sun, 26 Oct 2014 18:05:56 -0400 Subject: [PATCH 13/22] Axe the 16-px line width limit --- src/renderer/painter_line.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index bf8e1b060..d2094f083 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -20,10 +20,8 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c float offset = properties.gap_width == 0 ? 0 : (properties.gap_width + width) / 2; float blur = properties.blur + antialiasing; - // These are the radii of the line. We are limiting it to 16, which will result - // in a point size of 64 on retina. - float inset = std::fmin((std::fmax(-1, offset - width / 2 - antialiasing / 2) + 1), 16.0f); - float outset = std::fmin(offset + width / 2 + antialiasing / 2, 16.0f); + float inset = std::fmax(-1, offset - width / 2 - antialiasing / 2) + 1; + float outset = offset + width / 2 + antialiasing / 2; Color color = properties.color; color[0] *= properties.opacity; From dc834aec914cc0afaf31dffd0064d54dee05b751 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Mon, 27 Oct 2014 16:41:08 -0400 Subject: [PATCH 14/22] v6: min-zoom -> minzoom, max-zoom -> maxzoom --- src/style/style_parser.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 5c4ed0cb1..6dd2e678c 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -719,21 +719,21 @@ void StyleParser::parseBucket(JSVal value, util::ptr &layer) { parseRender(value_render, layer); } - if (value.HasMember("min-zoom")) { - JSVal min_zoom = value["min-zoom"]; + if (value.HasMember("minzoom")) { + JSVal min_zoom = value["minzoom"]; if (min_zoom.IsNumber()) { layer->bucket->min_zoom = min_zoom.GetDouble(); } else { - Log::Warning(Event::ParseStyle, "min-zoom of layer %s must be numeric", layer->id.c_str()); + Log::Warning(Event::ParseStyle, "minzoom of layer %s must be numeric", layer->id.c_str()); } } - if (value.HasMember("max-zoom")) { - JSVal max_zoom = value["max-zoom"]; + if (value.HasMember("maxzoom")) { + JSVal max_zoom = value["maxzoom"]; if (max_zoom.IsNumber()) { layer->bucket->min_zoom = max_zoom.GetDouble(); } else { - Log::Warning(Event::ParseStyle, "max-zoom of layer %s must be numeric", layer->id.c_str()); + Log::Warning(Event::ParseStyle, "maxzoom of layer %s must be numeric", layer->id.c_str()); } } } From f25cf706891edd2db63b0ea34918cc87bb631c20 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Mon, 27 Oct 2014 16:47:08 -0400 Subject: [PATCH 15/22] Reinstate 16px line width limit --- src/renderer/painter_line.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index d2094f083..4bf50569a 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -20,8 +20,8 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c float offset = properties.gap_width == 0 ? 0 : (properties.gap_width + width) / 2; float blur = properties.blur + antialiasing; - float inset = std::fmax(-1, offset - width / 2 - antialiasing / 2) + 1; - float outset = offset + width / 2 + antialiasing / 2; + float inset = std::fmin((std::fmax(-1, offset - width / 2 - antialiasing / 2) + 1), 16.0f); + float outset = std::fmin(offset + width / 2 + antialiasing / 2, 16.0f); Color color = properties.color; color[0] *= properties.opacity; From c151f12997d2560353cf7692d033fb123440a8b0 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 28 Oct 2014 11:17:03 -0400 Subject: [PATCH 16/22] Implement v6 filters --- include/mbgl/map/vector_tile.hpp | 9 +- include/mbgl/style/filter_comparison.hpp | 65 ---- .../mbgl/style/filter_comparison_private.hpp | 23 -- include/mbgl/style/filter_expression.hpp | 147 ++++++-- .../mbgl/style/filter_expression_private.hpp | 169 +++++---- include/mbgl/style/style_parser.hpp | 4 - include/mbgl/style/value.hpp | 2 + include/mbgl/style/value_comparison.hpp | 36 +- src/map/vector_tile.cpp | 131 ++----- src/style/filter_comparison.cpp | 143 ------- src/style/filter_expression.cpp | 159 +++++--- src/style/style_parser.cpp | 89 +---- src/style/value.cpp | 22 ++ test/comparisons.cpp | 349 ++++-------------- test/variant.cpp | 345 +++++++---------- 15 files changed, 592 insertions(+), 1101 deletions(-) delete mode 100644 include/mbgl/style/filter_comparison.hpp delete mode 100644 include/mbgl/style/filter_comparison_private.hpp delete mode 100644 src/style/filter_comparison.cpp diff --git a/include/mbgl/map/vector_tile.hpp b/include/mbgl/map/vector_tile.hpp index 1bbe64530..2d02ba3a0 100644 --- a/include/mbgl/map/vector_tile.hpp +++ b/include/mbgl/map/vector_tile.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -44,14 +45,14 @@ public: VectorTileTagExtractor(const VectorTileLayer &layer); void setTags(const pbf &pbf); - std::vector getValues(const std::string &key) const; - void setType(FilterExpression::GeometryType type); - FilterExpression::GeometryType getType() const; + mapbox::util::optional getValue(const std::string &key) const; + void setType(FeatureType type); + FeatureType getType() const; private: const VectorTileLayer &layer_; pbf tags_; - FilterExpression::GeometryType type_ = FilterExpression::GeometryType::Any; + FeatureType type_ = FeatureType::Unknown; }; /* diff --git a/include/mbgl/style/filter_comparison.hpp b/include/mbgl/style/filter_comparison.hpp deleted file mode 100644 index 1b0a9b548..000000000 --- a/include/mbgl/style/filter_comparison.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef MBGL_STYLE_FILTER_COMPARISON -#define MBGL_STYLE_FILTER_COMPARISON - -#include - -#include -#include -#include - -namespace mbgl { - -class FilterComparison { -public: - enum class Operator : uint8_t { - Equal, - NotEqual, - Greater, - GreaterEqual, - Less, - LessEqual, - In, - NotIn - }; - - class Instance { - public: - Instance(Operator op_, std::vector &&values_) - : op(op_), values(values_) {} - - bool compare(const std::vector &property_values) const; - - private: - Operator op = Operator::Equal; - std::vector values; - - friend std::ostream& operator <<(std::ostream &, const Instance &); - }; - -public: - FilterComparison(const std::string &field_) : field(field_) {}; - - const std::string &getField() const; - template inline bool compare(const Extractor &extractor) const; - - template - inline void add(Args&& ...args) { - instances.emplace_back(::std::forward(args)...); - } - -private: - std::string field; - std::vector instances; - - friend std::ostream& operator <<(std::ostream &, const FilterComparison &); -}; - -std::ostream& operator <<(std::ostream &s, const FilterComparison &comparison); -std::ostream& operator <<(std::ostream &s, const FilterComparison::Instance &instance); - - -FilterComparison::Operator parseFilterComparisonOperator(const std::string &op); - -} - -#endif diff --git a/include/mbgl/style/filter_comparison_private.hpp b/include/mbgl/style/filter_comparison_private.hpp deleted file mode 100644 index 648683242..000000000 --- a/include/mbgl/style/filter_comparison_private.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef MBGL_STYLE_FILTER_COMPARISON_PRIVATE -#define MBGL_STYLE_FILTER_COMPARISON_PRIVATE - -#include "filter_comparison.hpp" - -namespace mbgl { - -template -inline bool FilterComparison::compare(const Extractor &extractor) const { - const std::vector values = extractor.getValues(field); - - // All instances are ANDed together. - for (const Instance &instance : instances) { - if (!instance.compare(values)) { - return false; - } - } - return true; -} - -} - -#endif diff --git a/include/mbgl/style/filter_expression.hpp b/include/mbgl/style/filter_expression.hpp index 915d3931d..8c6f44777 100644 --- a/include/mbgl/style/filter_expression.hpp +++ b/include/mbgl/style/filter_expression.hpp @@ -1,54 +1,125 @@ #ifndef MBGL_STYLE_FILTER_EXPRESSION #define MBGL_STYLE_FILTER_EXPRESSION -#include -#include +#include -#include +#include + +#include +#include namespace mbgl { -class FilterExpression { -public: - typedef mapbox::util::recursive_wrapper Wrapper; +typedef mapbox::util::variant< + struct NullExpression, + struct EqualsExpression, + struct NotEqualsExpression, + struct LessThanExpression, + struct LessThanEqualsExpression, + struct GreaterThanExpression, + struct GreaterThanEqualsExpression, + struct InExpression, + struct NotInExpression, + struct AnyExpression, + struct AllExpression, + struct NoneExpression + > FilterExpression; - enum class Operator : uint8_t { - And, - Or, - Xor, - Nor - }; +FilterExpression parseFilterExpression(const rapidjson::Value&); - enum class GeometryType : uint8_t { - Any, - Point, - LineString, - Polygon - }; +template +bool evaluate(const FilterExpression&, const Extractor&); -public: - FilterExpression() = default; - FilterExpression(Operator op_) : op(op_) {}; - - bool empty() const; - - template bool compare(const Extractor &extractor) const; - void add(const FilterComparison &comparison); - void add(const FilterExpression &expression); - void setGeometryType(GeometryType g); - -private: - Operator op = Operator::And; - GeometryType type = GeometryType::Any; - std::vector comparisons; - std::vector expressions; - - friend std::ostream& operator <<(std::ostream &, const FilterExpression &); +struct NullExpression { + template + bool evaluate(const Extractor&) const { return true; } }; -std::ostream& operator <<(std::ostream &s, const FilterExpression &expression); +struct EqualsExpression { + std::string key; + Value value; + + template + bool evaluate(const Extractor&) const; +}; + +struct NotEqualsExpression { + std::string key; + Value value; + + template + bool evaluate(const Extractor&) const; +}; + +struct LessThanExpression { + std::string key; + Value value; + + template + bool evaluate(const Extractor&) const; +}; + +struct LessThanEqualsExpression { + std::string key; + Value value; + + template + bool evaluate(const Extractor&) const; +}; + +struct GreaterThanExpression { + std::string key; + Value value; + + template + bool evaluate(const Extractor&) const; +}; + +struct GreaterThanEqualsExpression { + std::string key; + Value value; + + template + bool evaluate(const Extractor&) const; +}; + +struct InExpression { + std::string key; + std::vector values; + + template + bool evaluate(const Extractor&) const; +}; + +struct NotInExpression { + std::string key; + std::vector values; + + template + bool evaluate(const Extractor&) const; +}; + +struct AnyExpression { + std::vector expressions; + + template + bool evaluate(const Extractor&) const; +}; + +struct AllExpression { + std::vector expressions; + + template + bool evaluate(const Extractor&) const; +}; + +struct NoneExpression { + std::vector expressions; + + template + bool evaluate(const Extractor&) const; +}; -FilterExpression::GeometryType parseGeometryType(const std::string &geometry); } #endif diff --git a/include/mbgl/style/filter_expression_private.hpp b/include/mbgl/style/filter_expression_private.hpp index 9379d250b..381f8f617 100644 --- a/include/mbgl/style/filter_expression_private.hpp +++ b/include/mbgl/style/filter_expression_private.hpp @@ -1,75 +1,118 @@ -#ifndef MBGL_STYLE_FILTER_EXPRESSION_PRIVATE -#define MBGL_STYLE_FILTER_EXPRESSION_PRIVATE - -#include "filter_expression.hpp" -#include "filter_comparison_private.hpp" +#include +#include namespace mbgl { -template -bool FilterExpression::compare(const Extractor &extractor) const { - if (type != GeometryType::Any && extractor.getType() != type && extractor.getType() != GeometryType::Any) { - return false; - } +template +struct Evaluator : public mapbox::util::static_visitor +{ + const Extractor& extractor; - switch (op) { - case Operator::And: - for (const FilterComparison &comparison : comparisons) { - if (!comparison.compare(extractor)) { - return false; - } - } - for (const FilterExpression &expression: expressions) { - if (!expression.compare(extractor)) { - return false; - } - } - return true; - case Operator::Or: - for (const FilterComparison &comparison : comparisons) { - if (comparison.compare(extractor)) { - return true; - } - } - for (const FilterExpression &expression: expressions) { - if (expression.compare(extractor)) { - return true; - } - } + Evaluator(const Extractor& extractor_) + : extractor(extractor_) {} + + template + bool operator()(const E& e) const { return e.evaluate(extractor); } +}; + +template +bool evaluate(const FilterExpression& expression, const Extractor& extractor) { + return mapbox::util::apply_visitor(Evaluator(extractor), expression); +}; + +template +bool EqualsExpression::evaluate(const Extractor& extractor) const { + mapbox::util::optional actual = extractor.getValue(key); + return actual && util::relaxed_equal(*actual, value); +} + +template +bool NotEqualsExpression::evaluate(const Extractor& extractor) const { + mapbox::util::optional actual = extractor.getValue(key); + return !actual || util::relaxed_not_equal(*actual, value); +} + +template +bool LessThanExpression::evaluate(const Extractor& extractor) const { + mapbox::util::optional actual = extractor.getValue(key); + return actual && util::relaxed_less(*actual, value); +} + +template +bool LessThanEqualsExpression::evaluate(const Extractor& extractor) const { + mapbox::util::optional actual = extractor.getValue(key); + return actual && util::relaxed_less_equal(*actual, value); +} + +template +bool GreaterThanExpression::evaluate(const Extractor& extractor) const { + mapbox::util::optional actual = extractor.getValue(key); + return actual && util::relaxed_greater(*actual, value); +} + +template +bool GreaterThanEqualsExpression::evaluate(const Extractor& extractor) const { + mapbox::util::optional actual = extractor.getValue(key); + return actual && util::relaxed_greater_equal(*actual, value); +} + +template +bool InExpression::evaluate(const Extractor& extractor) const { + mapbox::util::optional actual = extractor.getValue(key); + if (!actual) return false; - case Operator::Xor: { - int count = 0; - for (const FilterComparison &comparison : comparisons) { - count += comparison.compare(extractor); - if (count > 1) { - return false; - } + for (const auto& v: values) { + if (util::relaxed_equal(*actual, v)) { + return true; } - for (const FilterExpression &expression: expressions) { - count += expression.compare(extractor); - if (count > 1) { - return false; - } - } - return count == 1; } - case Operator::Nor: - for (const FilterComparison &comparison : comparisons) { - if (comparison.compare(extractor)) { - return false; - } - } - for (const FilterExpression &expression: expressions) { - if (expression.compare(extractor)) { - return false; - } - } - return true; - default: + return false; +} + +template +bool NotInExpression::evaluate(const Extractor& extractor) const { + mapbox::util::optional actual = extractor.getValue(key); + if (!actual) return true; + for (const auto& v: values) { + if (util::relaxed_equal(*actual, v)) { + return false; + } } + return true; +} + +template +bool AnyExpression::evaluate(const Extractor& extractor) const { + Evaluator evaluator(extractor); + for (const auto& e: expressions) { + if (mapbox::util::apply_visitor(evaluator, e)) { + return true; + } + } + return false; +} + +template +bool AllExpression::evaluate(const Extractor& extractor) const { + Evaluator evaluator(extractor); + for (const auto& e: expressions) { + if (!mapbox::util::apply_visitor(evaluator, e)) { + return false; + } + } + return true; +} + +template +bool NoneExpression::evaluate(const Extractor& extractor) const { + Evaluator evaluator(extractor); + for (const auto& e: expressions) { + if (mapbox::util::apply_visitor(evaluator, e)) { + return false; + } + } + return true; } } - -#endif diff --git a/include/mbgl/style/style_parser.hpp b/include/mbgl/style/style_parser.hpp index fc253bb1d..a1c57cf2d 100644 --- a/include/mbgl/style/style_parser.hpp +++ b/include/mbgl/style/style_parser.hpp @@ -85,11 +85,7 @@ private: template T parseFunctionArgument(JSVal value); - - FilterExpression parseFilter(JSVal, FilterExpression::Operator op); FilterExpression parseFilter(JSVal); - Value parseValue(JSVal value); - std::vector parseValues(JSVal values); private: std::unordered_map constants; diff --git a/include/mbgl/style/value.hpp b/include/mbgl/style/value.hpp index b981f1db9..87d6f4cda 100644 --- a/include/mbgl/style/value.hpp +++ b/include/mbgl/style/value.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -14,6 +15,7 @@ typedef mapbox::util::variant Valu std::string toString(const Value &value); Value parseValue(pbf data); +Value parseValue(const rapidjson::Value&); namespace util { inline bool parseNumericString(const std::string &str, double &result) { diff --git a/include/mbgl/style/value_comparison.hpp b/include/mbgl/style/value_comparison.hpp index 41c1d4412..98e29afa7 100644 --- a/include/mbgl/style/value_comparison.hpp +++ b/include/mbgl/style/value_comparison.hpp @@ -15,35 +15,35 @@ template struct relaxed_operator_visitor { typedef bool result_type; - inline bool operator()(bool lhs, bool rhs) const { return Operator()(lhs, rhs); } + template + inline bool operator()(T0, T1) const { return false; } - template ::value>::type> - inline bool operator()(bool lhs, T rhs) const { return Operator()(T(lhs), rhs); } - - template ::value>::type> - inline bool operator()(T lhs, bool rhs) const { return Operator()(lhs, T(rhs)); } + template + inline bool operator()(T lhs, T rhs) const { return Operator()(lhs, rhs); } inline bool operator()(int64_t lhs, uint64_t rhs) const { - return lhs < 0 ? false : Operator()(uint64_t(lhs), rhs); + return Operator()(double(lhs), double(rhs)); } + + inline bool operator()(int64_t lhs, double rhs) const { + return Operator()(double(lhs), rhs); + } + inline bool operator()(uint64_t lhs, int64_t rhs) const { - return rhs < 0 ? false : Operator()(lhs, uint64_t(rhs)); + return Operator()(double(lhs), double(rhs)); } - template ::value>::type> - inline bool operator()(const std::string &lhs, T rhs) const { - double value; - return parseNumericString(lhs, value) ? Operator()(value, double(rhs)) : false; + inline bool operator()(uint64_t lhs, double rhs) const { + return Operator()(double(lhs), rhs); } - template ::value>::type> - inline bool operator()(T lhs, const std::string &rhs) const { - double value; - return parseNumericString(rhs, value) ? Operator()(double(lhs), value) : false; + inline bool operator()(double lhs, uint64_t rhs) const { + return Operator()(lhs, double(rhs)); } - template - inline bool operator()(T0 lhs, T1 rhs) const { return Operator()(lhs, rhs); } + inline bool operator()(double lhs, int64_t rhs) const { + return Operator()(lhs, double(rhs)); + } }; struct relaxed_equal_operator { diff --git a/src/map/vector_tile.cpp b/src/map/vector_tile.cpp index 8f097c829..ac7134fb0 100644 --- a/src/map/vector_tile.cpp +++ b/src/map/vector_tile.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -123,81 +122,6 @@ FilteredVectorTileLayer::iterator::iterator(const FilteredVectorTileLayer& paren operator++(); } -//bool FilteredVectorTileLayer::iterator::matchesFilterExpression(const FilterExpression &filterExpression, const pbf &tags_pbf) { -// if (filterExpression.empty()) { -// return true; -// } -// -// -// -// -// if (filterExpression.is>()) { -// return matchesFilter(filterExpression.get>().get(), tags_pbf); -// } else if (filterExpression.is>()) { -// return matchesExpression(filterExpression.get>().get(), tags_pbf); -// } else if (filterExpression.is()) { -// return true; -// } else { -// return false; -// } -// return true; -//} - -// -//bool FilteredVectorTileLayer::iterator::matchesFilter(const PropertyFilter &filter, const pbf &const_tags_pbf) { -// auto field_it = parent.layer.key_index.find(filter.field); -// if (field_it != parent.layer.key_index.end()) { -// const uint32_t filter_key = field_it->second; -// -// // Now loop through all the key/value pair tags. -// // tags are packed varints. They should have an even length. -// pbf tags_pbf = const_tags_pbf; -// while (tags_pbf) { -// uint32_t tag_key = tags_pbf.varint(); -// if (!tags_pbf) { -// // This should not happen; otherwise the vector tile -// // is invalid. -// throw std::runtime_error("uneven number of feature tag ids"); -// } -// uint32_t tag_val = tags_pbf.varint(); -// -// if (tag_key == filter_key) { -// if (parent.layer.values.size() > tag_val) { -// const Value &value = parent.layer.values[tag_val]; -// return filter.compare(value); -// } else { -// throw std::runtime_error("feature references out of range value"); -// } -// } -// } -// } -// -// // The feature doesn't contain the field that we're looking to compare. -// // Depending on the filter, this may still be okay. -// return filter.isMissingFieldOkay(); -//} -// -//bool FilteredVectorTileLayer::iterator::matchesExpression(const PropertyExpression &expression, const pbf &tags_pbf) { -// if (expression.op == ExpressionOperator::Or) { -// for (const PropertyFilterExpression &filterExpression : expression.operands) { -// if (matchesFilterExpression(filterExpression, tags_pbf)) { -// return true; -// } -// } -// return false; -// } else if (expression.op == ExpressionOperator::And) { -// for (const PropertyFilterExpression &filterExpression : expression.operands) { -// if (!matchesFilterExpression(filterExpression, tags_pbf)) { -// return false; -// } -// } -// return true; -// } else { -// return false; -// } -//} -// - VectorTileTagExtractor::VectorTileTagExtractor(const VectorTileLayer &layer) : layer_(layer) {} @@ -205,8 +129,12 @@ void VectorTileTagExtractor::setTags(const pbf &pbf) { tags_ = pbf; } -std::vector VectorTileTagExtractor::getValues(const std::string &key) const { - std::vector values; +mapbox::util::optional VectorTileTagExtractor::getValue(const std::string &key) const { + if (key == "$type") { + return Value(uint64_t(type_)); + } + + mapbox::util::optional value; auto field_it = layer_.key_index.find(key); if (field_it != layer_.key_index.end()) { @@ -221,14 +149,14 @@ std::vector VectorTileTagExtractor::getValues(const std::string &key) con if (!tags_pbf) { // This should not happen; otherwise the vector tile is invalid. fprintf(stderr, "[WARNING] uneven number of feature tag ids\n"); - return values; + return value; } // Note: We need to run this command in all cases, even if the keys don't match. tag_val = tags_pbf.varint(); if (tag_key == filter_key) { if (layer_.values.size() > tag_val) { - values.emplace_back(layer_.values[tag_val]); + value = layer_.values[tag_val]; } else { fprintf(stderr, "[WARNING] feature references out of range value\n"); break; @@ -237,16 +165,14 @@ std::vector VectorTileTagExtractor::getValues(const std::string &key) con } } - return values; + return value; } -void VectorTileTagExtractor::setType(FilterExpression::GeometryType type) { +void VectorTileTagExtractor::setType(FeatureType type) { type_ = type; } -FilterExpression::GeometryType VectorTileTagExtractor::getType() const { - return type_; -} +template bool mbgl::evaluate(const FilterExpression&, const VectorTileTagExtractor&); void FilteredVectorTileLayer::iterator::operator++() { valid = false; @@ -256,36 +182,21 @@ void FilteredVectorTileLayer::iterator::operator++() { while (data.next(2)) { // feature feature = data.message(); pbf feature_pbf = feature; - bool matched = false; - // Treat the absence of any expression filters as a match. - if (expression.empty()) { - matched = true; - } + VectorTileTagExtractor extractor(parent.layer); - if (!matched) { - VectorTileTagExtractor extractor(parent.layer); - - // Retrieve the basic information - while (feature_pbf.next()) { - if (feature_pbf.tag == 2) { // tags - extractor.setTags(feature_pbf.message()); - } else if (feature_pbf.tag == 3) { // geometry type - switch (FeatureType(feature_pbf.varint())) { - case FeatureType::Point: extractor.setType(FilterExpression::GeometryType::Point); break; - case FeatureType::LineString: extractor.setType(FilterExpression::GeometryType::LineString); break; - case FeatureType::Polygon: extractor.setType(FilterExpression::GeometryType::Polygon); break; - default: break; - } - } else { - feature_pbf.skip(); - } + // Retrieve the basic information + while (feature_pbf.next()) { + if (feature_pbf.tag == 2) { // tags + extractor.setTags(feature_pbf.message()); + } else if (feature_pbf.tag == 3) { // geometry type + extractor.setType(FeatureType(feature_pbf.varint())); + } else { + feature_pbf.skip(); } - - matched = expression.compare(extractor); } - if (matched) { + if (evaluate(expression, extractor)) { valid = true; return; // data loop } else { diff --git a/src/style/filter_comparison.cpp b/src/style/filter_comparison.cpp deleted file mode 100644 index b3f3a9ef0..000000000 --- a/src/style/filter_comparison.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include -#include - -#include - -#include - -namespace mbgl { - - -inline bool includes(const Value &property_value, const std::vector &filter_values) { - for (const Value &filter_value : filter_values) { - if (util::relaxed_equal(property_value, filter_value)) { - return true; - } - } - return false; -} - -template -inline bool compare(const Value &property_value, const std::vector &filter_values, const Comparer &comparer) { - for (const Value &filter_value : filter_values) { - if (!comparer(property_value, filter_value)) { - return false; - } - } - return true; -} - -template -inline bool all(const std::vector &property_values, const std::vector &filter_values, const Comparer &comparer) { - for (const Value &property_value : property_values) { - if (!compare(property_value, filter_values, comparer)) { - return false; - } - } - return true; -} - - -inline bool set_equal(const std::vector &property_values, const std::vector &filter_values) { - for (const Value &property_value : property_values) { - if (!includes(property_value, filter_values)) { - return false; - } - } - if (property_values.size() == filter_values.size()) { - // Optimization: When the count is the same, the set is guaranteed to be identical. - return true; - } - // Otherwise, check again for identical reverse-mapped values. - for (const Value &filter_value : filter_values) { - if (!includes(filter_value, property_values)) { - return false; - } - } - return true; -} - - -bool FilterComparison::Instance::compare(const std::vector &property_values) const { - switch (op) { - case Operator::Equal: - return set_equal(property_values, values); - case Operator::NotEqual: - return !set_equal(property_values, values); - case Operator::In: - for (const Value &property_value : property_values) { - if (includes(property_value, values)) { - return true; - } - } - return false; - case Operator::NotIn: - for (const Value &property_value : property_values) { - if (!includes(property_value, values)) { - return true; - } - } - return false; - case Operator::Greater: - return all(property_values, values, util::relaxed_greater); - case Operator::GreaterEqual: - return all(property_values, values, util::relaxed_greater_equal); - case Operator::Less: - return all(property_values, values, util::relaxed_less); - case Operator::LessEqual: - return all(property_values, values, util::relaxed_less_equal); - default: - return false; - } -} - - -const std::string &FilterComparison::getField() const { - return field; -} - -std::ostream& operator <<(std::ostream &s, const FilterComparison &comparison) { - s << "comparison" << std::endl; - for (const FilterComparison::Instance &instance : comparison.instances) { - s << " - " << comparison.field << " " << instance << std::endl; - } - return s; -} - - -std::ostream& operator <<(std::ostream &s, const FilterComparison::Instance &instance) { - switch (instance.op) { - case FilterComparison::Operator::Equal: s << "=="; break; - case FilterComparison::Operator::NotEqual: s << "!="; break; - case FilterComparison::Operator::Greater: s << ">"; break; - case FilterComparison::Operator::GreaterEqual: s << ">="; break; - case FilterComparison::Operator::Less: s << "<"; break; - case FilterComparison::Operator::LessEqual: s << "<="; break; - case FilterComparison::Operator::In: s << "in"; break; - case FilterComparison::Operator::NotIn: s << "!in"; break; - } - - s << " [ "; - for (const Value &value : instance.values) { - s << toString(value) << " "; - } - s << "]"; - return s; -} - - -FilterComparison::Operator parseFilterComparisonOperator(const std::string &op) { - if (op == "==") return FilterComparison::Operator::Equal; - if (op == "!=") return FilterComparison::Operator::NotEqual; - if (op == ">") return FilterComparison::Operator::Greater; - if (op == ">=") return FilterComparison::Operator::GreaterEqual; - if (op == "<") return FilterComparison::Operator::Less; - if (op == "<=") return FilterComparison::Operator::LessEqual; - if (op == "in") return FilterComparison::Operator::In; - if (op == "!in") return FilterComparison::Operator::NotIn; - return FilterComparison::Operator::Equal; -} - -template bool FilterComparison::compare(const VectorTileTagExtractor &extractor) const; - -} diff --git a/src/style/filter_expression.cpp b/src/style/filter_expression.cpp index ff4073b12..7d4f60b3e 100644 --- a/src/style/filter_expression.cpp +++ b/src/style/filter_expression.cpp @@ -1,66 +1,123 @@ -#include #include - -#include - -#include +#include namespace mbgl { -std::ostream& operator <<(std::ostream &s, FilterExpression::Operator op) { - switch (op) { - case FilterExpression::Operator::And: s << "AND"; break; - case FilterExpression::Operator::Or: s << "OR"; break; - case FilterExpression::Operator::Xor: s << "XOR"; break; - case FilterExpression::Operator::Nor: s << "NOR"; break; +Value parseFeatureType(const Value& value) { + if (value == std::string("Point")) { + return Value(uint64_t(FeatureType::Point)); + } else if (value == std::string("LineString")) { + return Value(uint64_t(FeatureType::LineString)); + } else if (value == std::string("Polygon")) { + return Value(uint64_t(FeatureType::Polygon)); + } else { + Log::Warning(Event::ParseStyle, "value for $type filter must be Point, LineString, or Polygon"); + return Value(uint64_t(FeatureType::Unknown)); } - return s; } +template +FilterExpression parseBinaryFilter(const rapidjson::Value& value) { + FilterExpression empty; -std::ostream& operator <<(std::ostream &s, FilterExpression::GeometryType type) { - switch (type) { - case FilterExpression::GeometryType::Point: s << "Point"; break; - case FilterExpression::GeometryType::LineString: s << "LineString"; break; - case FilterExpression::GeometryType::Polygon: s << "Polygon"; break; - case FilterExpression::GeometryType::Any: s << ""; break; + if (value.Size() < 3) { + Log::Warning(Event::ParseStyle, "filter expression must have 3 elements"); + return empty; } - return s; -} -bool FilterExpression::empty() const { - return type == GeometryType::Any && comparisons.empty() && expressions.empty(); -} - -void FilterExpression::add(const FilterComparison &comparison) { - comparisons.emplace_back(comparison); -} - -void FilterExpression::add(const FilterExpression &expression) { - expressions.emplace_back(expression); -} - -void FilterExpression::setGeometryType(GeometryType g) { - type = g; -} - -FilterExpression::GeometryType parseGeometryType(const std::string &geometry) { - if (geometry == "Point") return FilterExpression::GeometryType::Point; - if (geometry == "LineString") return FilterExpression::GeometryType::LineString; - if (geometry == "Polygon") return FilterExpression::GeometryType::Polygon; - return FilterExpression::GeometryType::Any; -} - -std::ostream& operator <<(std::ostream &s, const FilterExpression &expression) { - s << "expression " << expression.op << std::endl; - s << " - $type = " << expression.type << std::endl; - for (const FilterComparison &comparison : expression.comparisons) { - s << comparison; + if (!value[1u].IsString()) { + Log::Warning(Event::ParseStyle, "filter expression key must be a string"); + return empty; } - s << "end expression" << std::endl; - return s; + + Expression expression; + expression.key = { value[1u].GetString(), value[1u].GetStringLength() }; + expression.value = parseValue(value[2u]); + + if (expression.key == "$type") { + expression.value = parseFeatureType(expression.value); + } + + return expression; } -template bool FilterExpression::compare(const VectorTileTagExtractor &extractor) const; +template +FilterExpression parseSetFilter(const rapidjson::Value& value) { + FilterExpression empty; + + if (value.Size() < 2) { + Log::Warning(Event::ParseStyle, "filter expression must at least 2 elements"); + return empty; + } + + if (!value[1u].IsString()) { + Log::Warning(Event::ParseStyle, "filter expression key must be a string"); + return empty; + } + + Expression expression; + expression.key = { value[1u].GetString(), value[1u].GetStringLength() }; + for (rapidjson::SizeType i = 2; i < value.Size(); ++i) { + expression.values.push_back(parseValue(value[i])); + } + return expression; +} + +template +FilterExpression parseCompoundFilter(const rapidjson::Value& value) { + Expression expression; + for (rapidjson::SizeType i = 1; i < value.Size(); ++i) { + expression.expressions.push_back(parseFilterExpression(value[i])); + } + return expression; +} + +FilterExpression parseFilterExpression(const rapidjson::Value& value) { + FilterExpression empty; + + if (!value.IsArray()) { + Log::Warning(Event::ParseStyle, "filter expression must be an array"); + return empty; + } + + if (value.Size() < 1) { + Log::Warning(Event::ParseStyle, "filter expression must have at least 1 element"); + return empty; + } + + if (!value[0u].IsString()) { + Log::Warning(Event::ParseStyle, "filter operator must be a string"); + return empty; + } + + std::string op = { value[0u].GetString(), value[0u].GetStringLength() }; + + if (op == "==") { + return parseBinaryFilter(value); + } else if (op == "!=") { + return parseBinaryFilter(value); + } else if (op == ">") { + return parseBinaryFilter(value); + } else if (op == ">=") { + return parseBinaryFilter(value); + } else if (op == "<") { + return parseBinaryFilter(value); + } else if (op == "<=") { + return parseBinaryFilter(value); + } else if (op == "in") { + return parseSetFilter(value); + } else if (op == "!in") { + return parseSetFilter(value); + } else if (op == "all") { + return parseCompoundFilter(value); + } else if (op == "any") { + return parseCompoundFilter(value); + } else if (op == "none") { + return parseCompoundFilter(value); + } else { + Log::Warning(Event::ParseStyle, "filter operator must be one of \"==\", \"!=\", \">\", \">=\", \"<\", \"<=\", \"in\", \"!in\", \"all\", \"any\", \"none\""); + return empty; + } +} } diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 6dd2e678c..9f2307441 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -711,7 +711,7 @@ void StyleParser::parseBucket(JSVal value, util::ptr &layer) { if (value.HasMember("filter")) { JSVal value_filter = replaceConstant(value["filter"]); - layer->bucket->filter = parseFilter(value_filter); + layer->bucket->filter = parseFilterExpression(value_filter); } if (value.HasMember("render")) { @@ -738,93 +738,6 @@ void StyleParser::parseBucket(JSVal value, util::ptr &layer) { } } -FilterExpression StyleParser::parseFilter(JSVal value) { - return parseFilter(value, value.IsArray() ? FilterExpression::Operator::Or : FilterExpression::Operator::And); -} - -FilterExpression StyleParser::parseFilter(JSVal value, FilterExpression::Operator op) { - FilterExpression expression(op); - if (value.IsObject()) { - rapidjson::Value::ConstMemberIterator itr = value.MemberBegin(); - for (; itr != value.MemberEnd(); ++itr) { - const std::string name { itr->name.GetString(), itr->name.GetStringLength() }; - if (name == "&") { - expression.add(parseFilter(replaceConstant(itr->value), FilterExpression::Operator::And)); - } else if (name == "|") { - expression.add(parseFilter(replaceConstant(itr->value), FilterExpression::Operator::Or)); - } else if (name == "^") { - expression.add(parseFilter(replaceConstant(itr->value), FilterExpression::Operator::Xor)); - } else if (name == "!") { - expression.add(parseFilter(replaceConstant(itr->value), FilterExpression::Operator::Nor)); - } else if (name == "$type") { - JSVal type = replaceConstant(itr->value); - if (type.IsString()) { - expression.setGeometryType(parseGeometryType({ type.GetString(), type.GetStringLength() })); - } - } else { - FilterComparison comparison(name); - JSVal filterValue = replaceConstant(itr->value); - if (filterValue.IsObject()) { - rapidjson::Value::ConstMemberIterator filter_itr = filterValue.MemberBegin(); - for (; filter_itr != filterValue.MemberEnd(); ++filter_itr) { - comparison.add( - parseFilterComparisonOperator({ filter_itr->name.GetString(), filter_itr->name.GetStringLength() }), - parseValues(replaceConstant(filter_itr->value)) - ); - } - } else if (filterValue.IsArray()) { - comparison.add(FilterComparison::Operator::In, parseValues(filterValue)); - } else { - comparison.add(FilterComparison::Operator::Equal, std::vector({ parseValue(filterValue) })); - } - expression.add(comparison); - } - } - } else if (value.IsArray()) { - for (rapidjson::SizeType i = 0; i < value.Size(); i++) { - expression.add(parseFilter(replaceConstant(value[i]))); - } - } else { - Log::Warning(Event::ParseStyle, "expression must be either an array or an object"); - } - - return expression; -} - -Value StyleParser::parseValue(JSVal value) { - switch (value.GetType()) { - case rapidjson::kNullType: - case rapidjson::kFalseType: - return false; - - case rapidjson::kTrueType: - return true; - - case rapidjson::kStringType: - return std::string { value.GetString(), value.GetStringLength() }; - - case rapidjson::kNumberType: - if (value.IsUint64()) return value.GetUint64(); - if (value.IsInt64()) return value.GetInt64(); - return value.GetDouble(); - - default: - return false; - } -} - -std::vector StyleParser::parseValues(JSVal value) { - std::vector values; - if (value.IsArray()) { - for (rapidjson::SizeType i = 0; i < value.Size(); i++) { - values.emplace_back(parseValue(replaceConstant(value[i]))); - } - } else { - values.emplace_back(parseValue(value)); - } - return values; -} - void StyleParser::parseRender(JSVal value, util::ptr &layer) { if (!value.IsObject()) { Log::Warning(Event::ParseStyle, "render property of layer '%s' must be an object", layer->id.c_str()); diff --git a/src/style/value.cpp b/src/style/value.cpp index 5cd32376a..bda9a089a 100644 --- a/src/style/value.cpp +++ b/src/style/value.cpp @@ -42,3 +42,25 @@ std::string mbgl::toString(const mbgl::Value& value) { else if (value.is()) return boost::lexical_cast(value.get()); else return "null"; } + +mbgl::Value mbgl::parseValue(const rapidjson::Value& value) { + switch (value.GetType()) { + case rapidjson::kNullType: + case rapidjson::kFalseType: + return false; + + case rapidjson::kTrueType: + return true; + + case rapidjson::kStringType: + return std::string { value.GetString(), value.GetStringLength() }; + + case rapidjson::kNumberType: + if (value.IsUint64()) return value.GetUint64(); + if (value.IsInt64()) return value.GetInt64(); + return value.GetDouble(); + + default: + return false; + } +} diff --git a/test/comparisons.cpp b/test/comparisons.cpp index 4ffcf2e2e..9b74d6e36 100644 --- a/test/comparisons.cpp +++ b/test/comparisons.cpp @@ -1,306 +1,103 @@ #include #include "gtest/gtest.h" -#include +#include +#include #include #include +using namespace mbgl; +typedef std::multimap Properties; -class MockExtractor { +class Extractor { public: - inline MockExtractor(const std::multimap &values_) : values(values_) {} - inline MockExtractor() {} + inline Extractor(const Properties& properties_, FeatureType type_) + : properties(properties_) + , type(type_) + {} - inline std::vector getValues(const std::string &key) const { - std::vector result; - // Find all values with the requested key. - const auto ret = values.equal_range(key); - for (auto it = ret.first; it != ret.second; it++) { - // Append the newly found value to the forward list. - result.emplace_back(it->second); - } - return result; + mapbox::util::optional getValue(const std::string &key) const { + if (key == "$type") + return Value(uint64_t(type)); + auto it = properties.find(key); + if (it == properties.end()) + return mapbox::util::optional(); + return it->second; + } + + FeatureType getType() const { + return type; } private: - const std::multimap values; + const Properties properties; + FeatureType type; }; - -TEST(FilterComparison, EqualsSingleStringValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::Equal, std::vector { std::string("bar") }); - // comparison is { "test": { "==": "bar" } } - - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("booz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor())); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("barst") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(-18932) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", uint64_t(18932) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(32.8) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); +FilterExpression parse(const char * expression) { + rapidjson::Document doc; + doc.Parse<0>(expression); + return parseFilterExpression(doc); } - -TEST(FilterComparison, EqualsSingleDoubleValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::Equal, std::vector { double(32.8) }); - // comparison is { "test": { "==": 32.8 } } - - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(32.8) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("32.8") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", double(32.8) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(32.8) }, { "test", std::string("booz") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", double(32.8) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor())); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(32.9) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(-18932) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", uint64_t(18932) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); +bool evaluate(const FilterExpression& expression, const Properties& properties, FeatureType type = FeatureType::Unknown) { + return mbgl::evaluate(expression, Extractor(properties, type)); } -TEST(FilterComparison, EqualsSingleUintValue) { - using namespace mbgl; +TEST(FilterComparison, EqualsString) { + FilterExpression f = parse("[\"==\", \"foo\", \"bar\"]"); + ASSERT_TRUE(evaluate(f, {{ "foo", std::string("bar") }})); + ASSERT_FALSE(evaluate(f, {{ "foo", std::string("baz") }})); +}; - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::Equal, std::vector { uint64_t(42) }); - // comparison is { "test": { "==": 42 } } - - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", uint64_t(42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("42") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", uint64_t(42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", uint64_t(42) }, { "test", std::string("booz") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", uint64_t(42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor())); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(43) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(-18932) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", uint64_t(18932) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); +TEST(FilterComparison, EqualsNumber) { + FilterExpression f = parse("[\"==\", \"foo\", 0]"); + ASSERT_TRUE(evaluate(f, {{ "foo", int64_t(0) }})); + ASSERT_TRUE(evaluate(f, {{ "foo", uint64_t(0) }})); + ASSERT_TRUE(evaluate(f, {{ "foo", double(0) }})); + ASSERT_FALSE(evaluate(f, {{ "foo", int64_t(1) }})); + ASSERT_FALSE(evaluate(f, {{ "foo", uint64_t(1) }})); + ASSERT_FALSE(evaluate(f, {{ "foo", double(1) }})); + ASSERT_FALSE(evaluate(f, {{ "foo", std::string("0") }})); + ASSERT_FALSE(evaluate(f, {{ "foo", false }})); + ASSERT_FALSE(evaluate(f, {{ "foo", true }})); + ASSERT_FALSE(evaluate(f, {{}})); } -TEST(FilterComparison, EqualsSingleIntValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::Equal, std::vector { int64_t(-42) }); - // comparison is { "test": { "==": -42 } } - - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(-42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(-42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("-42") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", int64_t(-42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(-42) }, { "test", std::string("booz") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", int64_t(-42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor())); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(-43) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(-43) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", uint64_t(-42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); +TEST(FilterComparison, EqualsType) { + FilterExpression f = parse("[\"==\", \"$type\", \"LineString\"]"); + ASSERT_FALSE(evaluate(f, {{}}, FeatureType::Point)); + ASSERT_TRUE(evaluate(f, {{}}, FeatureType::LineString)); } -TEST(FilterComparison, EqualsSingleBoolValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::Equal, std::vector { bool(true) }); - // comparison is { "test": { "==": true } } - - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(1) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", uint64_t(1) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(1) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("1") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", bool(true) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(true) }, { "test", std::string("booz") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", bool(true) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor())); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(-18932) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", uint64_t(18932) }}))); +TEST(FilterComparison, Any) { + ASSERT_FALSE(evaluate(parse("[\"any\"]"), {{}})); + ASSERT_TRUE(evaluate(parse("[\"any\", [\"==\", \"foo\", 1]]"), + {{ std::string("foo"), int64_t(1) }})); + ASSERT_FALSE(evaluate(parse("[\"any\", [\"==\", \"foo\", 0]]"), + {{ std::string("foo"), int64_t(1) }})); + ASSERT_TRUE(evaluate(parse("[\"any\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]"), + {{ std::string("foo"), int64_t(1) }})); } - - -TEST(FilterComparison, EqualsMultipleStringValues) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::Equal, std::vector { std::string("bar"), std::string("baz") }); - // comparison is { "test": { "==": ["bar", "baz"]̇ } } - - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("baz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("baz") }, { "test", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("baz") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("baz") }, { "test", std::string("boo") }}))); +TEST(FilterComparison, All) { + ASSERT_TRUE(evaluate(parse("[\"all\"]"), {{}})); + ASSERT_TRUE(evaluate(parse("[\"all\", [\"==\", \"foo\", 1]]"), + {{ std::string("foo"), int64_t(1) }})); + ASSERT_FALSE(evaluate(parse("[\"all\", [\"==\", \"foo\", 0]]"), + {{ std::string("foo"), int64_t(1) }})); + ASSERT_FALSE(evaluate(parse("[\"all\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]"), + {{ std::string("foo"), int64_t(1) }})); } -TEST(FilterComparison, EqualsMultipleIdenticalStringValues) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::Equal, std::vector { std::string("bar"), std::string("bar") }); - // comparison is { "test": { "==": ["bar", "bar"]̇ } } - - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("baz") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("baz") }}))); -} - - - -TEST(FilterComparison, NotEqualsSingleStringValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::NotEqual, std::vector { std::string("bar") }); - // comparison is { "test": { "!=": "bar" } } - - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", std::string("bar") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("booz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", std::string("bar") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor())); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("barst") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(-18932) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", uint64_t(18932) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(32.8) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); -} - - -TEST(FilterComparison, NotEqualsSingleDoubleValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::NotEqual, std::vector { double(32.8) }); - // comparison is { "test": { "!=": 32.8 } } - - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(32.8) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("32.8") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", double(32.8) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(32.8) }, { "test", std::string("booz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", double(32.8) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor())); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(32.9) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(-18932) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", uint64_t(18932) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); -} - -TEST(FilterComparison, NotEqualsSingleUintValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::NotEqual, std::vector { uint64_t(42) }); - // comparison is { "test": { "!=": 42 } } - - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", uint64_t(42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("42") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", uint64_t(42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", uint64_t(42) }, { "test", std::string("booz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", uint64_t(42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor())); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(43) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(-18932) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", uint64_t(18932) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); -} - - -TEST(FilterComparison, NotEqualsSingleIntValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::NotEqual, std::vector { int64_t(-42) }); - // comparison is { "test": { "!=": -42 } } - - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(-42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(-42) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("-42") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", int64_t(-42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(-42) }, { "test", std::string("booz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", int64_t(-42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor())); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(-43) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", double(-43) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", uint64_t(-42) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); -} - - -TEST(FilterComparison, NotEqualsSingleBoolValue) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::NotEqual, std::vector { bool(true) }); - // comparison is { "test": { "!=": true } } - - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", bool(true) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", int64_t(1) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", uint64_t(1) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", double(1) }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("1") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "other", std::string("bar") }, { "test", bool(true) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(true) }, { "test", std::string("booz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "other", bool(true) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor())); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", bool(false) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", int64_t(-18932) }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", uint64_t(18932) }}))); -} - - - -TEST(FilterComparison, NotEqualsMultipleStringValues) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::NotEqual, std::vector { std::string("bar"), std::string("baz") }); - // comparison is { "test": { "!=": ["bar", "baz"]̇ } } - - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("baz") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("baz") }, { "test", std::string("bar") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("baz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("baz") }, { "test", std::string("boo") }}))); -} - - - -TEST(FilterComparison, NotEqualsMultipleIdenticalStringValues) { - using namespace mbgl; - - FilterComparison comparison("test"); - comparison.add(FilterComparison::Operator::NotEqual, std::vector { std::string("bar"), std::string("bar") }); - // comparison is { "test": { "!=": ["bar", "bar"]̇ } } - - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }}))); - ASSERT_FALSE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("bar") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("baz") }}))); - ASSERT_TRUE(comparison.compare(MockExtractor({{ "test", std::string("bar") }, { "test", std::string("baz") }}))); +TEST(FilterComparison, None) { + ASSERT_TRUE(evaluate(parse("[\"none\"]"), {{}})); + ASSERT_FALSE(evaluate(parse("[\"none\", [\"==\", \"foo\", 1]]"), + {{ std::string("foo"), int64_t(1) }})); + ASSERT_TRUE(evaluate(parse("[\"none\", [\"==\", \"foo\", 0]]"), + {{ std::string("foo"), int64_t(1) }})); + ASSERT_FALSE(evaluate(parse("[\"none\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]"), + {{ std::string("foo"), int64_t(1) }})); } diff --git a/test/variant.cpp b/test/variant.cpp index 4557465cf..e4caba9f2 100644 --- a/test/variant.cpp +++ b/test/variant.cpp @@ -17,110 +17,26 @@ TEST(Variant, toString) { EXPECT_EQ("false", toString( false )); } - -TEST(Variant, RelaxedEqualityStringToBool) { - // 1-ish values are true - EXPECT_TRUE(util::relaxed_equal(std::string("1"), bool(true))); - EXPECT_TRUE(util::relaxed_equal(std::string("1.0"), bool(true))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 1"), bool(true))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 0x1"), bool(true))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 0X1"), bool(true))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 1.0"), bool(true))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 1 "), bool(true))); - - EXPECT_TRUE(util::relaxed_equal(bool(true), std::string("1"))); - EXPECT_TRUE(util::relaxed_equal(bool(true), std::string("1.0"))); - EXPECT_TRUE(util::relaxed_equal(bool(true), std::string(" 1"))); - EXPECT_TRUE(util::relaxed_equal(bool(true), std::string(" 0x1"))); - EXPECT_TRUE(util::relaxed_equal(bool(true), std::string(" 0X1"))); - EXPECT_TRUE(util::relaxed_equal(bool(true), std::string(" 1.0"))); - EXPECT_TRUE(util::relaxed_equal(bool(true), std::string(" 1 "))); - - // 0-ish values are false - EXPECT_TRUE(util::relaxed_equal(std::string("0"), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string("0.0"), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 0"), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 0x0"), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 0X0"), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 0.0"), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string(" 0 "), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string(""), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string(" "), bool(false))); - - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string("0"))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string("0.0"))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string(" 0"))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string(" 0x0"))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string(" 0X0"))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string(" 0.0"))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string(" 0 "))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string(""))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string(" "))); - - - // other string values are neither true nor false - EXPECT_FALSE(util::relaxed_equal(std::string(" 1.0 g"), bool(true))); - EXPECT_FALSE(util::relaxed_equal(std::string("foo"), bool(true))); - EXPECT_FALSE(util::relaxed_equal(std::string("true"), bool(true))); - EXPECT_FALSE(util::relaxed_equal(std::string("false"), bool(true))); - EXPECT_FALSE(util::relaxed_equal(std::string(" inf "), bool(true))); - EXPECT_FALSE(util::relaxed_equal(std::string(" inFINITY "), bool(true))); - EXPECT_FALSE(util::relaxed_equal(std::string(" nan "), bool(true))); - EXPECT_FALSE(util::relaxed_equal(std::string(" NAN "), bool(true))); - - EXPECT_FALSE(util::relaxed_equal(bool(true), std::string(" 1.0 g"))); - EXPECT_FALSE(util::relaxed_equal(bool(true), std::string("foo"))); - EXPECT_FALSE(util::relaxed_equal(bool(true), std::string("true"))); - EXPECT_FALSE(util::relaxed_equal(bool(true), std::string("false"))); - EXPECT_FALSE(util::relaxed_equal(bool(true), std::string(" inf "))); - EXPECT_FALSE(util::relaxed_equal(bool(true), std::string(" inFINITY "))); - EXPECT_FALSE(util::relaxed_equal(bool(true), std::string(" nan "))); - EXPECT_FALSE(util::relaxed_equal(bool(true), std::string(" NAN "))); - - - EXPECT_FALSE(util::relaxed_equal(std::string(" 1.0 g"), bool(false))); - EXPECT_FALSE(util::relaxed_equal(std::string("foo"), bool(false))); - EXPECT_FALSE(util::relaxed_equal(std::string("true"), bool(false))); - EXPECT_FALSE(util::relaxed_equal(std::string("false"), bool(false))); - EXPECT_FALSE(util::relaxed_equal(std::string(" inf "), bool(false))); - EXPECT_FALSE(util::relaxed_equal(std::string(" inFINITY "), bool(false))); - EXPECT_FALSE(util::relaxed_equal(std::string(" nan "), bool(false))); - EXPECT_FALSE(util::relaxed_equal(std::string(" NAN "), bool(false))); - - EXPECT_FALSE(util::relaxed_equal(bool(false), std::string(" 1.0 g"))); - EXPECT_FALSE(util::relaxed_equal(bool(false), std::string("foo"))); - EXPECT_FALSE(util::relaxed_equal(bool(false), std::string("true"))); - EXPECT_FALSE(util::relaxed_equal(bool(false), std::string("false"))); - EXPECT_FALSE(util::relaxed_equal(bool(false), std::string(" inf "))); - EXPECT_FALSE(util::relaxed_equal(bool(false), std::string(" inFINITY "))); - EXPECT_FALSE(util::relaxed_equal(bool(false), std::string(" nan "))); - EXPECT_FALSE(util::relaxed_equal(bool(false), std::string(" NAN "))); -} - TEST(Variant, RelaxedEquality) { // Compare to bool EXPECT_TRUE(util::relaxed_equal(bool(false), bool(false))); - EXPECT_TRUE(util::relaxed_equal(bool(false), int64_t(0))); - EXPECT_TRUE(util::relaxed_equal(bool(false), uint64_t(0))); - EXPECT_TRUE(util::relaxed_equal(bool(false), double(0))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string("0"))); - EXPECT_TRUE(util::relaxed_equal(bool(false), std::string(""))); - EXPECT_TRUE(util::relaxed_equal(bool(true), bool(true))); - EXPECT_TRUE(util::relaxed_equal(bool(true), int64_t(1))); - EXPECT_TRUE(util::relaxed_equal(bool(true), uint64_t(1))); - EXPECT_TRUE(util::relaxed_equal(bool(true), double(1))); - EXPECT_TRUE(util::relaxed_equal(bool(true), std::string("1"))); - - EXPECT_FALSE(util::relaxed_equal(bool(false), bool(true))); + EXPECT_FALSE(util::relaxed_equal(bool(false), int64_t(0))); + EXPECT_FALSE(util::relaxed_equal(bool(false), uint64_t(0))); + EXPECT_FALSE(util::relaxed_equal(bool(false), double(0))); + EXPECT_FALSE(util::relaxed_equal(bool(false), std::string("0"))); + EXPECT_FALSE(util::relaxed_equal(bool(false), std::string(""))); EXPECT_FALSE(util::relaxed_equal(bool(false), int64_t(386))); EXPECT_FALSE(util::relaxed_equal(bool(false), int64_t(-7042))); EXPECT_FALSE(util::relaxed_equal(bool(false), uint64_t(386))); EXPECT_FALSE(util::relaxed_equal(bool(false), double(3.145))); EXPECT_FALSE(util::relaxed_equal(bool(false), std::string("386"))); EXPECT_FALSE(util::relaxed_equal(bool(false), std::string("test"))); - + EXPECT_FALSE(util::relaxed_equal(bool(true), int64_t(1))); + EXPECT_FALSE(util::relaxed_equal(bool(true), uint64_t(1))); + EXPECT_FALSE(util::relaxed_equal(bool(true), double(1))); + EXPECT_FALSE(util::relaxed_equal(bool(true), std::string("1"))); EXPECT_FALSE(util::relaxed_equal(bool(true), bool(false))); EXPECT_FALSE(util::relaxed_equal(bool(true), int64_t(386))); EXPECT_FALSE(util::relaxed_equal(bool(true), int64_t(-7042))); @@ -135,10 +51,9 @@ TEST(Variant, RelaxedEquality) { EXPECT_TRUE(util::relaxed_equal(int64_t(-7042), int64_t(-7042))); EXPECT_TRUE(util::relaxed_equal(int64_t(386), uint64_t(386))); EXPECT_TRUE(util::relaxed_equal(int64_t(386), double(386))); - EXPECT_TRUE(util::relaxed_equal(int64_t(386), std::string("386"))); - EXPECT_TRUE(util::relaxed_equal(int64_t(1), bool(true))); - EXPECT_TRUE(util::relaxed_equal(int64_t(0), bool(false))); - + EXPECT_FALSE(util::relaxed_equal(int64_t(386), std::string("386"))); + EXPECT_FALSE(util::relaxed_equal(int64_t(1), bool(true))); + EXPECT_FALSE(util::relaxed_equal(int64_t(0), bool(false))); EXPECT_FALSE(util::relaxed_equal(int64_t(386), int64_t(387))); EXPECT_FALSE(util::relaxed_equal(int64_t(-7042), int64_t(-7043))); EXPECT_FALSE(util::relaxed_equal(int64_t(386), uint64_t(387))); @@ -151,16 +66,14 @@ TEST(Variant, RelaxedEquality) { EXPECT_FALSE(util::relaxed_equal(int64_t(1), std::string("false"))); EXPECT_FALSE(util::relaxed_equal(int64_t(0), std::string("true"))); - // Compare to uint64_t EXPECT_TRUE(util::relaxed_equal(uint64_t(386), int64_t(386))); EXPECT_TRUE(util::relaxed_equal(uint64_t(386), uint64_t(386))); EXPECT_TRUE(util::relaxed_equal(uint64_t(0), uint64_t(0))); EXPECT_TRUE(util::relaxed_equal(uint64_t(386), double(386))); - EXPECT_TRUE(util::relaxed_equal(uint64_t(386), std::string("386"))); - EXPECT_TRUE(util::relaxed_equal(uint64_t(1), bool(true))); - EXPECT_TRUE(util::relaxed_equal(uint64_t(0), bool(false))); - + EXPECT_FALSE(util::relaxed_equal(uint64_t(386), std::string("386"))); + EXPECT_FALSE(util::relaxed_equal(uint64_t(1), bool(true))); + EXPECT_FALSE(util::relaxed_equal(uint64_t(0), bool(false))); EXPECT_FALSE(util::relaxed_equal(uint64_t(386), int64_t(387))); EXPECT_FALSE(util::relaxed_equal(uint64_t(386), uint64_t(387))); EXPECT_FALSE(util::relaxed_equal(uint64_t(0), uint64_t(1))); @@ -173,17 +86,15 @@ TEST(Variant, RelaxedEquality) { EXPECT_FALSE(util::relaxed_equal(uint64_t(1), std::string("false"))); EXPECT_FALSE(util::relaxed_equal(uint64_t(0), std::string("true"))); - // Compare to double EXPECT_TRUE(util::relaxed_equal(double(3.159385), double(3.159385))); EXPECT_TRUE(util::relaxed_equal(double(386), int64_t(386))); EXPECT_TRUE(util::relaxed_equal(double(386), uint64_t(386))); EXPECT_TRUE(util::relaxed_equal(double(0), uint64_t(0))); EXPECT_TRUE(util::relaxed_equal(double(386), double(386))); - EXPECT_TRUE(util::relaxed_equal(double(386), std::string("386"))); - EXPECT_TRUE(util::relaxed_equal(double(1), bool(true))); - EXPECT_TRUE(util::relaxed_equal(double(0), bool(false))); - + EXPECT_FALSE(util::relaxed_equal(double(386), std::string("386"))); + EXPECT_FALSE(util::relaxed_equal(double(1), bool(true))); + EXPECT_FALSE(util::relaxed_equal(double(0), bool(false))); EXPECT_FALSE(util::relaxed_equal(double(3.159385), double(3.159383))); EXPECT_FALSE(util::relaxed_equal(double(386), int64_t(387))); EXPECT_FALSE(util::relaxed_equal(double(386), uint64_t(387))); @@ -205,16 +116,14 @@ TEST(Variant, RelaxedEquality) { EXPECT_FALSE(util::relaxed_equal(double(0), std::string("true"))); EXPECT_FALSE(util::relaxed_equal(double(0), std::string("TRUE"))); - // Compare to string EXPECT_TRUE(util::relaxed_equal(std::string("lord"), std::string("lord"))); - EXPECT_TRUE(util::relaxed_equal(std::string("386"), int64_t(386))); - EXPECT_TRUE(util::relaxed_equal(std::string("-386"), int64_t(-386))); - EXPECT_TRUE(util::relaxed_equal(std::string("386"), uint64_t(386))); - EXPECT_TRUE(util::relaxed_equal(std::string("386.36"), double(386.36))); - EXPECT_TRUE(util::relaxed_equal(std::string(""), bool(false))); - EXPECT_TRUE(util::relaxed_equal(std::string("1"), bool(true))); - + EXPECT_FALSE(util::relaxed_equal(std::string("386"), int64_t(386))); + EXPECT_FALSE(util::relaxed_equal(std::string("-386"), int64_t(-386))); + EXPECT_FALSE(util::relaxed_equal(std::string("386"), uint64_t(386))); + EXPECT_FALSE(util::relaxed_equal(std::string("386.36"), double(386.36))); + EXPECT_FALSE(util::relaxed_equal(std::string(""), bool(false))); + EXPECT_FALSE(util::relaxed_equal(std::string("1"), bool(true))); EXPECT_FALSE(util::relaxed_equal(std::string("lord"), std::string("baron"))); EXPECT_FALSE(util::relaxed_equal(std::string("386"), int64_t(387))); EXPECT_FALSE(util::relaxed_equal(std::string("-386"), int64_t(-387))); @@ -239,46 +148,46 @@ TEST(Variant, RelaxedEquality) { TEST(Variant, RelaxedGreater) { EXPECT_TRUE(util::relaxed_greater(std::string("387"), std::string("386"))); - EXPECT_TRUE(util::relaxed_greater(uint64_t(387), std::string("386"))); - EXPECT_TRUE(util::relaxed_greater(int64_t(387), std::string("386"))); - EXPECT_TRUE(util::relaxed_greater(double(387), std::string("386"))); - EXPECT_TRUE(util::relaxed_greater(bool(true), std::string("0"))); + EXPECT_FALSE(util::relaxed_greater(uint64_t(387), std::string("386"))); + EXPECT_FALSE(util::relaxed_greater(int64_t(387), std::string("386"))); + EXPECT_FALSE(util::relaxed_greater(double(387), std::string("386"))); + EXPECT_FALSE(util::relaxed_greater(bool(true), std::string("0"))); - EXPECT_TRUE(util::relaxed_greater(std::string("387"), uint64_t(386))); + EXPECT_FALSE(util::relaxed_greater(std::string("387"), uint64_t(386))); EXPECT_TRUE(util::relaxed_greater(uint64_t(387), uint64_t(386))); EXPECT_TRUE(util::relaxed_greater(int64_t(387), uint64_t(386))); EXPECT_TRUE(util::relaxed_greater(double(387), uint64_t(386))); - EXPECT_TRUE(util::relaxed_greater(bool(true), uint64_t(0))); + EXPECT_FALSE(util::relaxed_greater(bool(true), uint64_t(0))); - EXPECT_TRUE(util::relaxed_greater(std::string("387"), int64_t(386))); + EXPECT_FALSE(util::relaxed_greater(std::string("387"), int64_t(386))); EXPECT_TRUE(util::relaxed_greater(uint64_t(387), int64_t(386))); EXPECT_TRUE(util::relaxed_greater(int64_t(387), int64_t(386))); EXPECT_TRUE(util::relaxed_greater(double(387), int64_t(386))); - EXPECT_TRUE(util::relaxed_greater(bool(true), int64_t(0))); + EXPECT_FALSE(util::relaxed_greater(bool(true), int64_t(0))); - EXPECT_TRUE(util::relaxed_greater(std::string("387"), double(386.7))); + EXPECT_FALSE(util::relaxed_greater(std::string("387"), double(386.7))); EXPECT_TRUE(util::relaxed_greater(uint64_t(387), double(386.7))); EXPECT_TRUE(util::relaxed_greater(int64_t(387), double(386.7))); EXPECT_TRUE(util::relaxed_greater(double(387), double(386.7))); - EXPECT_TRUE(util::relaxed_greater(bool(true), double(0))); + EXPECT_FALSE(util::relaxed_greater(bool(true), double(0))); - EXPECT_TRUE(util::relaxed_greater(std::string("387"), bool(true))); - EXPECT_TRUE(util::relaxed_greater(std::string("387"), bool(false))); - EXPECT_TRUE(util::relaxed_greater(uint64_t(387), bool(false))); - EXPECT_TRUE(util::relaxed_greater(int64_t(387), bool(false))); - EXPECT_TRUE(util::relaxed_greater(double(387), bool(false))); - EXPECT_TRUE(util::relaxed_greater(double(387), bool(false))); - EXPECT_TRUE(util::relaxed_greater(uint64_t(387), bool(true))); - EXPECT_TRUE(util::relaxed_greater(int64_t(387), bool(true))); - EXPECT_TRUE(util::relaxed_greater(double(387), bool(true))); - EXPECT_TRUE(util::relaxed_greater(double(387), bool(true))); + EXPECT_FALSE(util::relaxed_greater(std::string("387"), bool(true))); + EXPECT_FALSE(util::relaxed_greater(std::string("387"), bool(false))); + EXPECT_FALSE(util::relaxed_greater(uint64_t(387), bool(false))); + EXPECT_FALSE(util::relaxed_greater(int64_t(387), bool(false))); + EXPECT_FALSE(util::relaxed_greater(double(387), bool(false))); + EXPECT_FALSE(util::relaxed_greater(double(387), bool(false))); + EXPECT_FALSE(util::relaxed_greater(uint64_t(387), bool(true))); + EXPECT_FALSE(util::relaxed_greater(int64_t(387), bool(true))); + EXPECT_FALSE(util::relaxed_greater(double(387), bool(true))); + EXPECT_FALSE(util::relaxed_greater(double(387), bool(true))); - EXPECT_TRUE(util::relaxed_greater(bool(true), double(0))); - EXPECT_TRUE(util::relaxed_greater(bool(true), double(0.5))); - EXPECT_TRUE(util::relaxed_greater(bool(true), bool(false))); - EXPECT_TRUE(util::relaxed_greater(bool(true), int64_t(0))); - EXPECT_TRUE(util::relaxed_greater(bool(true), uint64_t(0))); + EXPECT_FALSE(util::relaxed_greater(bool(true), double(0))); + EXPECT_FALSE(util::relaxed_greater(bool(true), double(0.5))); EXPECT_TRUE(util::relaxed_greater(bool(true), bool(false))); + EXPECT_FALSE(util::relaxed_greater(bool(true), bool(true))); + EXPECT_FALSE(util::relaxed_greater(bool(true), int64_t(0))); + EXPECT_FALSE(util::relaxed_greater(bool(true), uint64_t(0))); @@ -315,52 +224,52 @@ TEST(Variant, RelaxedGreater) { TEST(Variant, RelaxedGreaterEqual) { EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), std::string("386"))); EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), std::string("387"))); - EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), std::string("386"))); - EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), std::string("387"))); - EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), std::string("386"))); - EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), std::string("387"))); - EXPECT_TRUE(util::relaxed_greater_equal(double(387), std::string("386"))); - EXPECT_TRUE(util::relaxed_greater_equal(double(387), std::string("387"))); - EXPECT_TRUE(util::relaxed_greater_equal(bool(true), std::string("0"))); + EXPECT_FALSE(util::relaxed_greater_equal(uint64_t(387), std::string("386"))); + EXPECT_FALSE(util::relaxed_greater_equal(uint64_t(387), std::string("387"))); + EXPECT_FALSE(util::relaxed_greater_equal(int64_t(387), std::string("386"))); + EXPECT_FALSE(util::relaxed_greater_equal(int64_t(387), std::string("387"))); + EXPECT_FALSE(util::relaxed_greater_equal(double(387), std::string("386"))); + EXPECT_FALSE(util::relaxed_greater_equal(double(387), std::string("387"))); + EXPECT_FALSE(util::relaxed_greater_equal(bool(true), std::string("0"))); - EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), uint64_t(386))); - EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), uint64_t(387))); + EXPECT_FALSE(util::relaxed_greater_equal(std::string("387"), uint64_t(386))); + EXPECT_FALSE(util::relaxed_greater_equal(std::string("387"), uint64_t(387))); EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), uint64_t(386))); EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), uint64_t(387))); EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), uint64_t(386))); EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), uint64_t(387))); EXPECT_TRUE(util::relaxed_greater_equal(double(387), uint64_t(386))); EXPECT_TRUE(util::relaxed_greater_equal(double(387), uint64_t(387))); - EXPECT_TRUE(util::relaxed_greater_equal(bool(true), uint64_t(0))); + EXPECT_FALSE(util::relaxed_greater_equal(bool(true), uint64_t(0))); - EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), int64_t(386))); - EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), int64_t(387))); + EXPECT_FALSE(util::relaxed_greater_equal(std::string("387"), int64_t(386))); + EXPECT_FALSE(util::relaxed_greater_equal(std::string("387"), int64_t(387))); EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), int64_t(386))); EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), int64_t(387))); EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), int64_t(386))); EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), int64_t(387))); EXPECT_TRUE(util::relaxed_greater_equal(double(387), int64_t(386))); EXPECT_TRUE(util::relaxed_greater_equal(double(387), int64_t(387))); - EXPECT_TRUE(util::relaxed_greater_equal(bool(true), int64_t(0))); + EXPECT_FALSE(util::relaxed_greater_equal(bool(true), int64_t(0))); - EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), double(386.7))); - EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), double(387))); + EXPECT_FALSE(util::relaxed_greater_equal(std::string("387"), double(386.7))); + EXPECT_FALSE(util::relaxed_greater_equal(std::string("387"), double(387))); EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), double(386.7))); EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), double(387))); EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), double(386.7))); EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), double(387))); EXPECT_TRUE(util::relaxed_greater_equal(double(387), double(386.7))); EXPECT_TRUE(util::relaxed_greater_equal(double(387), double(387))); - EXPECT_TRUE(util::relaxed_greater_equal(bool(true), double(0))); + EXPECT_FALSE(util::relaxed_greater_equal(bool(true), double(0))); - EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), bool(false))); - EXPECT_TRUE(util::relaxed_greater_equal(std::string("387"), bool(true))); - EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), bool(false))); - EXPECT_TRUE(util::relaxed_greater_equal(uint64_t(387), bool(true))); - EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), bool(false))); - EXPECT_TRUE(util::relaxed_greater_equal(int64_t(387), bool(true))); - EXPECT_TRUE(util::relaxed_greater_equal(double(387), bool(false))); - EXPECT_TRUE(util::relaxed_greater_equal(double(387), bool(true))); + EXPECT_FALSE(util::relaxed_greater_equal(std::string("387"), bool(false))); + EXPECT_FALSE(util::relaxed_greater_equal(std::string("387"), bool(true))); + EXPECT_FALSE(util::relaxed_greater_equal(uint64_t(387), bool(false))); + EXPECT_FALSE(util::relaxed_greater_equal(uint64_t(387), bool(true))); + EXPECT_FALSE(util::relaxed_greater_equal(int64_t(387), bool(false))); + EXPECT_FALSE(util::relaxed_greater_equal(int64_t(387), bool(true))); + EXPECT_FALSE(util::relaxed_greater_equal(double(387), bool(false))); + EXPECT_FALSE(util::relaxed_greater_equal(double(387), bool(true))); EXPECT_TRUE(util::relaxed_greater_equal(bool(true), bool(false))); EXPECT_TRUE(util::relaxed_greater_equal(bool(true), bool(true))); @@ -391,43 +300,43 @@ TEST(Variant, RelaxedGreaterEqual) { TEST(Variant, RelaxedLess) { EXPECT_TRUE(util::relaxed_less(std::string("387"), std::string("388"))); - EXPECT_TRUE(util::relaxed_less(uint64_t(387), std::string("388"))); - EXPECT_TRUE(util::relaxed_less(int64_t(387), std::string("388"))); - EXPECT_TRUE(util::relaxed_less(double(387), std::string("388"))); - EXPECT_TRUE(util::relaxed_less(bool(false), std::string("388"))); - EXPECT_TRUE(util::relaxed_less(bool(false), std::string("1"))); + EXPECT_FALSE(util::relaxed_less(uint64_t(387), std::string("388"))); + EXPECT_FALSE(util::relaxed_less(int64_t(387), std::string("388"))); + EXPECT_FALSE(util::relaxed_less(double(387), std::string("388"))); + EXPECT_FALSE(util::relaxed_less(bool(false), std::string("388"))); + EXPECT_FALSE(util::relaxed_less(bool(false), std::string("1"))); - EXPECT_TRUE(util::relaxed_less(std::string("387"), uint64_t(388))); + EXPECT_FALSE(util::relaxed_less(std::string("387"), uint64_t(388))); EXPECT_TRUE(util::relaxed_less(uint64_t(387), uint64_t(388))); EXPECT_TRUE(util::relaxed_less(int64_t(387), uint64_t(388))); EXPECT_TRUE(util::relaxed_less(double(387), uint64_t(388))); - EXPECT_TRUE(util::relaxed_less(bool(false), uint64_t(388))); - EXPECT_TRUE(util::relaxed_less(bool(false), uint64_t(1))); + EXPECT_FALSE(util::relaxed_less(bool(false), uint64_t(388))); + EXPECT_FALSE(util::relaxed_less(bool(false), uint64_t(1))); - EXPECT_TRUE(util::relaxed_less(std::string("387"), int64_t(388))); + EXPECT_FALSE(util::relaxed_less(std::string("387"), int64_t(388))); EXPECT_TRUE(util::relaxed_less(uint64_t(387), int64_t(388))); EXPECT_TRUE(util::relaxed_less(int64_t(387), int64_t(388))); EXPECT_TRUE(util::relaxed_less(double(387), int64_t(388))); - EXPECT_TRUE(util::relaxed_less(bool(false), int64_t(388))); - EXPECT_TRUE(util::relaxed_less(bool(false), int64_t(1))); + EXPECT_FALSE(util::relaxed_less(bool(false), int64_t(388))); + EXPECT_FALSE(util::relaxed_less(bool(false), int64_t(1))); - EXPECT_TRUE(util::relaxed_less(std::string("387"), double(387.7))); + EXPECT_FALSE(util::relaxed_less(std::string("387"), double(387.7))); EXPECT_TRUE(util::relaxed_less(uint64_t(387), double(387.7))); EXPECT_TRUE(util::relaxed_less(int64_t(387), double(387.7))); EXPECT_TRUE(util::relaxed_less(double(387), double(387.7))); - EXPECT_TRUE(util::relaxed_less(bool(false), double(387))); - EXPECT_TRUE(util::relaxed_less(bool(false), double(1))); + EXPECT_FALSE(util::relaxed_less(bool(false), double(387))); + EXPECT_FALSE(util::relaxed_less(bool(false), double(1))); - EXPECT_TRUE(util::relaxed_less(std::string("0"), bool(true))); - EXPECT_TRUE(util::relaxed_less(uint64_t(0), bool(true))); - EXPECT_TRUE(util::relaxed_less(int64_t(0), bool(true))); - EXPECT_TRUE(util::relaxed_less(double(0), bool(true))); + EXPECT_FALSE(util::relaxed_less(std::string("0"), bool(true))); + EXPECT_FALSE(util::relaxed_less(uint64_t(0), bool(true))); + EXPECT_FALSE(util::relaxed_less(int64_t(0), bool(true))); + EXPECT_FALSE(util::relaxed_less(double(0), bool(true))); EXPECT_TRUE(util::relaxed_less(bool(false), bool(true))); - EXPECT_TRUE(util::relaxed_less(bool(true), std::string("386"))); - EXPECT_TRUE(util::relaxed_less(bool(true), uint64_t(386))); - EXPECT_TRUE(util::relaxed_less(bool(true), int64_t(386))); - EXPECT_TRUE(util::relaxed_less(bool(true), double(386))); + EXPECT_FALSE(util::relaxed_less(bool(true), std::string("386"))); + EXPECT_FALSE(util::relaxed_less(bool(true), uint64_t(386))); + EXPECT_FALSE(util::relaxed_less(bool(true), int64_t(386))); + EXPECT_FALSE(util::relaxed_less(bool(true), double(386))); @@ -464,60 +373,60 @@ TEST(Variant, RelaxedLess) { TEST(Variant, RelaxedLessEqual) { EXPECT_TRUE(util::relaxed_less_equal(std::string("387"), std::string("388"))); EXPECT_TRUE(util::relaxed_less_equal(std::string("387"), std::string("387"))); - EXPECT_TRUE(util::relaxed_less_equal(uint64_t(387), std::string("388"))); - EXPECT_TRUE(util::relaxed_less_equal(uint64_t(387), std::string("387"))); - EXPECT_TRUE(util::relaxed_less_equal(int64_t(387), std::string("388"))); - EXPECT_TRUE(util::relaxed_less_equal(int64_t(387), std::string("387"))); - EXPECT_TRUE(util::relaxed_less_equal(double(387), std::string("388"))); - EXPECT_TRUE(util::relaxed_less_equal(double(387), std::string("387"))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), std::string("388"))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), std::string("1"))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), std::string("0"))); + EXPECT_FALSE(util::relaxed_less_equal(uint64_t(387), std::string("388"))); + EXPECT_FALSE(util::relaxed_less_equal(uint64_t(387), std::string("387"))); + EXPECT_FALSE(util::relaxed_less_equal(int64_t(387), std::string("388"))); + EXPECT_FALSE(util::relaxed_less_equal(int64_t(387), std::string("387"))); + EXPECT_FALSE(util::relaxed_less_equal(double(387), std::string("388"))); + EXPECT_FALSE(util::relaxed_less_equal(double(387), std::string("387"))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), std::string("388"))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), std::string("1"))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), std::string("0"))); - EXPECT_TRUE(util::relaxed_less_equal(std::string("387"), uint64_t(388))); - EXPECT_TRUE(util::relaxed_less_equal(std::string("387"), uint64_t(387))); + EXPECT_FALSE(util::relaxed_less_equal(std::string("387"), uint64_t(388))); + EXPECT_FALSE(util::relaxed_less_equal(std::string("387"), uint64_t(387))); EXPECT_TRUE(util::relaxed_less_equal(uint64_t(387), uint64_t(388))); EXPECT_TRUE(util::relaxed_less_equal(uint64_t(387), uint64_t(387))); EXPECT_TRUE(util::relaxed_less_equal(int64_t(387), uint64_t(388))); EXPECT_TRUE(util::relaxed_less_equal(int64_t(387), uint64_t(387))); EXPECT_TRUE(util::relaxed_less_equal(double(387), uint64_t(388))); EXPECT_TRUE(util::relaxed_less_equal(double(387), uint64_t(387))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), uint64_t(388))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), uint64_t(1))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), uint64_t(0))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), uint64_t(388))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), uint64_t(1))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), uint64_t(0))); - EXPECT_TRUE(util::relaxed_less_equal(std::string("387"), int64_t(388))); - EXPECT_TRUE(util::relaxed_less_equal(std::string("387"), int64_t(387))); + EXPECT_FALSE(util::relaxed_less_equal(std::string("387"), int64_t(388))); + EXPECT_FALSE(util::relaxed_less_equal(std::string("387"), int64_t(387))); EXPECT_TRUE(util::relaxed_less_equal(uint64_t(387), int64_t(388))); EXPECT_TRUE(util::relaxed_less_equal(uint64_t(387), int64_t(387))); EXPECT_TRUE(util::relaxed_less_equal(int64_t(387), int64_t(388))); EXPECT_TRUE(util::relaxed_less_equal(int64_t(387), int64_t(387))); EXPECT_TRUE(util::relaxed_less_equal(double(387), int64_t(388))); EXPECT_TRUE(util::relaxed_less_equal(double(387), int64_t(387))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), int64_t(388))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), int64_t(1))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), int64_t(0))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), int64_t(388))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), int64_t(1))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), int64_t(0))); - EXPECT_TRUE(util::relaxed_less_equal(std::string("387"), double(387.7))); - EXPECT_TRUE(util::relaxed_less_equal(std::string("387"), double(387))); + EXPECT_FALSE(util::relaxed_less_equal(std::string("387"), double(387.7))); + EXPECT_FALSE(util::relaxed_less_equal(std::string("387"), double(387))); EXPECT_TRUE(util::relaxed_less_equal(uint64_t(387), double(387.7))); EXPECT_TRUE(util::relaxed_less_equal(uint64_t(387), double(387))); EXPECT_TRUE(util::relaxed_less_equal(int64_t(387), double(387.7))); EXPECT_TRUE(util::relaxed_less_equal(int64_t(387), double(387))); EXPECT_TRUE(util::relaxed_less_equal(double(387), double(387.7))); EXPECT_TRUE(util::relaxed_less_equal(double(387), double(387))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), double(387))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), double(1))); - EXPECT_TRUE(util::relaxed_less_equal(bool(false), double(0))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), double(387))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), double(1))); + EXPECT_FALSE(util::relaxed_less_equal(bool(false), double(0))); - EXPECT_TRUE(util::relaxed_less_equal(std::string("0"), bool(true))); - EXPECT_TRUE(util::relaxed_less_equal(std::string("0"), bool(false))); - EXPECT_TRUE(util::relaxed_less_equal(uint64_t(0), bool(true))); - EXPECT_TRUE(util::relaxed_less_equal(uint64_t(0), bool(false))); - EXPECT_TRUE(util::relaxed_less_equal(int64_t(0), bool(true))); - EXPECT_TRUE(util::relaxed_less_equal(int64_t(0), bool(false))); - EXPECT_TRUE(util::relaxed_less_equal(double(0), bool(true))); - EXPECT_TRUE(util::relaxed_less_equal(double(0), bool(false))); + EXPECT_FALSE(util::relaxed_less_equal(std::string("0"), bool(true))); + EXPECT_FALSE(util::relaxed_less_equal(std::string("0"), bool(false))); + EXPECT_FALSE(util::relaxed_less_equal(uint64_t(0), bool(true))); + EXPECT_FALSE(util::relaxed_less_equal(uint64_t(0), bool(false))); + EXPECT_FALSE(util::relaxed_less_equal(int64_t(0), bool(true))); + EXPECT_FALSE(util::relaxed_less_equal(int64_t(0), bool(false))); + EXPECT_FALSE(util::relaxed_less_equal(double(0), bool(true))); + EXPECT_FALSE(util::relaxed_less_equal(double(0), bool(false))); EXPECT_TRUE(util::relaxed_less_equal(bool(false), bool(true))); EXPECT_TRUE(util::relaxed_less_equal(bool(false), bool(false))); From 05c5c3a8bc38ddc7c6819f986132d0883a136ea7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 31 Oct 2014 17:21:30 -0400 Subject: [PATCH 17/22] Use v6 styles --- linux/main.cpp | 2 +- macosx/main.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/main.cpp b/linux/main.cpp index b28ad84d1..c49957349 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) { // Load style if (style.empty()) - style = std::string("file://") + uv::cwd() + std::string("/../../styles/styles/bright-v5.json"); + style = std::string("file://") + uv::cwd() + std::string("/../../styles/styles/bright-v6.json"); map.setStyleURL(style); diff --git a/macosx/main.mm b/macosx/main.mm index 5c6f3592a..9a6e52757 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -100,7 +100,7 @@ int main() { if (accessToken) map.setAccessToken([accessToken cStringUsingEncoding:[NSString defaultCStringEncoding]]); // Load style - const std::string path([[[NSBundle mainBundle] pathForResource:@"bright-v5" ofType:@"json" inDirectory:@"styles/"] UTF8String]); + const std::string path([[[NSBundle mainBundle] pathForResource:@"bright-v6" ofType:@"json" inDirectory:@"styles/"] UTF8String]); map.setStyleURL(std::string("file://") + path); From d964949a12b90f2bd2bcc1b490ee545377a88df9 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 1 Nov 2014 14:15:25 -0400 Subject: [PATCH 18/22] Update styles --- test/fixtures/style_parser/colors.style.json | 28 +- test/fixtures/style_parser/default.info.json | 6 - test/fixtures/style_parser/default.style.json | 2244 ----------------- .../style_parser/function-numeric.style.json | 10 +- .../style_parser/function-type.style.json | 10 +- .../style_parser/line-opacity.style.json | 10 +- .../style_parser/line-width.style.json | 10 +- .../style_parser/stop-zoom-value.style.json | 22 +- .../style_parser/stops-array.style.json | 10 +- .../style_parser/text-size.style.json | 10 +- 10 files changed, 55 insertions(+), 2305 deletions(-) delete mode 100644 test/fixtures/style_parser/default.info.json delete mode 100755 test/fixtures/style_parser/default.style.json diff --git a/test/fixtures/style_parser/colors.style.json b/test/fixtures/style_parser/colors.style.json index c3e94d637..24aa2e5d1 100644 --- a/test/fixtures/style_parser/colors.style.json +++ b/test/fixtures/style_parser/colors.style.json @@ -1,39 +1,39 @@ { - "version": 3, + "version": 6, + "constants": { + "@land": "r44,239,225)", + "@snow": "f4f8foNGbjf#", + "@crop": "#eerLznieed4" + }, "sources": { "mapbox": { "type": "vector", "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 + "maxzoom": 14 } }, - "constants": { - "@land":"r44,239,225)", - "@snow":"f4f8foNGbjf#", - "@crop":"#eerLznieed4" - }, "layers": [{ "id": "background", "type": "background", - "style": { + "paint": { "background-color": "@land" } }, { "id": "landcover_snow", + "type": "fill", "source": "mapbox", "source-layer": "landcover", - "filter": { "class": "snow" }, - "type": "fill", - "style": { + "filter": ["==", "class", "snow"], + "paint": { "fill-color": "@snow" } }, { "id": "landcover_crop", + "type": "fill", "source": "mapbox", "source-layer": "landcover", - "filter": { "class": "crop" }, - "type": "fill", - "style": { + "filter": ["==", "class", "crop"], + "paint": { "fill-color": "@crop" } }] diff --git a/test/fixtures/style_parser/default.info.json b/test/fixtures/style_parser/default.info.json deleted file mode 100644 index 9c25a2f48..000000000 --- a/test/fixtures/style_parser/default.info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "default": { - "log": [ - ] - } -} diff --git a/test/fixtures/style_parser/default.style.json b/test/fixtures/style_parser/default.style.json deleted file mode 100755 index aea2a1a3a..000000000 --- a/test/fixtures/style_parser/default.style.json +++ /dev/null @@ -1,2244 +0,0 @@ -{ - "version": 3, - "sprite": "https://www.mapbox.com/mapbox-gl-styles/sprites/outdoors", - "glyphs": "https://mapbox.s3.amazonaws.com/gl-glyphs-256/{fontstack}/{range}.pbf", - "sources": { - "mapbox": { - "type": "vector", - "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 - } - }, - "constants": { - "@land": "rgb(244,239,225)", - "@water": "#cdd", - "@water_dark": "#185869", - "@crop": "#eeeed4", - "@grass": "#e6e6cc", - "@scrub": "#dfe5c8", - "@wood": "#cee2bd", - "@snow": "#f4f8ff", - "@rock": "#ddd", - "@sand": "#ffd", - "@cemetery": "#edf4ed", - "@pitch": "#fff", - "@park": "#d4e4bc", - "@piste": "blue", - "@school": "#e8dfe0", - "@hospital": "#f8eee0", - "@builtup": "#f6faff", - "@case": "#fff", - "@motorway": "#cda0a0", - "@main": "#ddc0b9", - "@street": "#fff", - "@text": "#666", - "@text_stroke": "rgba(255,255,255,0.8)", - "@country_text": "#222", - "@marine_text": "#a0bdc0", - "@water_text": "#185869", - "@land_night": "#017293", - "@water_night": "#103", - "@water_dark_night": "#003366", - "@crop_night": "#178d96", - "@grass_night": "#23948a", - "@scrub_night": "#31a186", - "@wood_night": "#45b581", - "@park_night": "#51bd8b", - "@snow_night": "#5ad9fe", - "@rock_night": "#999", - "@sand_night": "#437162", - "@cemetery_night": "#218c96", - "@pitch_night": "rgba(255,255,255,0.2)", - "@school_night": "#01536a", - "@hospital_night": "#015e7a", - "@builtup_night": "#014b60", - "@admin_night": "#ffb680", - "@text_night": "#fff", - "@text_water_night": "#2a5b8a", - "@text_stroke_night": "#103", - "@text2_stroke_night": "rgba(1,69,89,0.8)", - "@case_night": "#015e7a", - "@street_case_night": "#015b76", - "@motorway_night": "#bbdde7", - "@main_night": "#64b2c9", - "@street_night": "#0186ac", - "@contour_night": "#ffff80", - "@river_canal_width": { - "stops": [[10, 0.5], [11, 1], [13, 2], [15, 3]] - }, - "@stream_width": { - "stops": [[12, 0.25], [13, 0.5], [15, 1.5], [17, 2]] - }, - "@motorway_width": { - "stops": [[4, 0], [5, 0.5], [7, 0.8], [9, 1], [10, 1.2], [11, 2], [12, 3], [13, 4], [14, 6], [15, 9], [16, 12], [17, 14]] - }, - "@motorway_casing_width": { - "stops": [[6.5, 0.6], [7, 0.8], [9, 2.8], [10, 3], [11, 4], [12, 5], [13, 6.5], [14, 9], [15, 12], [16, 15], [17, 17]] - }, - "@motorway_link_width": { - "stops": [[11, 1.2], [13, 2], [15, 3], [17, 4]] - }, - "@motorway_link_casing_width": { - "stops": [[11, 2.8], [13, 3.5], [15, 5], [17, 6]] - }, - "@main_width": { - "stops": [[4, 1], [11, 1], [12, 1.5], [13, 2], [14, 3], [15, 6], [16, 10], [17, 12]] - }, - "@main_casing_width": { - "stops": [[8, 2.9], [11, 2.9], [12, 3.5], [13, 4], [14, 5.5], [15, 9], [16, 12], [17, 14]] - }, - "@street_width": { - "stops": [[13.5, 0], [14, 1.5], [15, 3], [16, 8]] - }, - "@street_casing_width": { - "stops": [[12, 0.4], [13, 1], [14, 2.5], [15, 4], [16, 10]] - }, - "@street_casing_opacity": { - "stops": [[13, 0], [13.5, 1]] - }, - "@service_casing_width": { - "stops": [[13, 0.5], [14, 3], [15, 3.5], [16, 4], [17, 5], [18, 6]] - }, - "@runway_width": { - "stops": [[9, 1], [10, 2], [11, 3], [12, 5], [13, 7], [14, 11], [15, 15], [16, 19], [17, 23]] - }, - "@taxiway_width": { - "stops": [[9, 0.2], [11, 0.2], [12, 1], [13, 1.5], [14, 2], [15, 3], [16, 4], [17, 5]] - }, - "@aerialway_width": { - "stops": [[12.5, 0.8], [13, 1.4], [14, 1.6], [15, 2], [16, 2.4], [17, 3]] - }, - "@aerialway_casing_width": { - "stops": [[12.5, 2], [13, 2.5], [14, 3], [15, 3.5], [16, 4], [21, 5]] - }, - "@path_width": { - "stops": [[13, 1.2], [14, 1.5], [15, 1.8]] - }, - "@admin_l2_width": { - "stops": [[1, 0.5], [2, 0.7], [3, 0.7], [4, 0.8], [5, 1], [7, 2], [9, 3]] - }, - "@admin_l3_width": { - "stops": [[5, 0.6], [7, 1], [11, 2]] - }, - "@road_label_1_size": { - "stops": [[12, 11], [13, 12], [14, 13], [15, 14], [16, 16], [17, 18]] - }, - "@road_label_2_size": { - "stops": [[12, 11], [13, 12], [15, 14], [17, 16]] - }, - "@road_label_3_size": { - "stops": [[14, 10], [15, 12], [17, 14]] - }, - "@fence_width": { - "stops": [[16, 0.6], [18, 1]] - }, - "@hedge_width": { - "stops": [[15, 0.6], [16, 1.2], [18, 1.6]] - }, - "@barrier_line_land_width": { - "stops": [[13, 0.4], [14, 0.75], [15, 1.5], [16, 3], [17, 6], [18, 12], [19, 24], [20, 48]] - }, - "@country_label_size": { - "stops": [[0, 14], [11, 24]] - }, - "@poi_label_1-2_size": { - "stops": [[14, 10], [15, 11], [16, 12]] - }, - "@poi_label_3_size": { - "stops": [[15, 10], [16, 11]] - }, - "@hillshade_rasterize": { - "enabled": { - "stops": [[10, false], [11, true]] - }, - "size": { - "stops": [[10, 1024], [11, 512], [12, 256]] - }, - "blur": 1 - } - }, - "layers": [{ - "id": "background", - "type": "background", - "style": { - "background-color": "@land" - }, - "style.night": { - "background-color": "@land_night" - } - }, { - "id": "landcover_snow", - "source": "mapbox", - "source-layer": "landcover", - "filter": { "class": "snow" }, - "type": "fill", - "style": { - "fill-color": "@snow" - }, - "style.night": { - "fill-color": "@snow_night" - } - }, { - "id": "landcover_crop", - "source": "mapbox", - "source-layer": "landcover", - "filter": { "class": "crop" }, - "type": "fill", - "style": { - "fill-color": "@crop" - }, - "style.night": { - "fill-color": "@crop_night" - } - }, { - "id": "landcover_grass", - "source": "mapbox", - "source-layer": "landcover", - "filter": { "class": "grass" }, - "type": "fill", - "style": { - "fill-color": "@grass", - "fill-opacity": { - "stops": [[12, 1], [13, 0.8], [16, 0.2]] - } - }, - "style.night": { - "fill-color": "@grass_night", - "fill-opacity": { - "stops": [[12, 1], [13, 0.8], [16, 0.2]] - } - } - }, { - "id": "landcover_scrub", - "source": "mapbox", - "source-layer": "landcover", - "filter": { "class": "scrub" }, - "type": "fill", - "style": { - "fill-color": "@scrub", - "fill-opacity": { - "stops": [[12, 1], [13, 0.8], [16, 0.2]] - } - }, - "style.night": { - "fill-color": "@scrub_night", - "fill-opacity": { - "stops": [[12, 1], [13, 0.8], [16, 0.2]] - } - } - }, { - "id": "landcover_wood", - "source": "mapbox", - "source-layer": "landcover", - "filter": { "class": "wood" }, - "type": "fill", - "style": { - "fill-color": "@wood", - "fill-opacity": { - "stops": [[12, 1], [13, 0.8], [16, 0.2]] - } - }, - "style.night": { - "fill-color": "@wood_night", - "fill-opacity": { - "stops": [[12, 1], [13, 0.8], [16, 0.2]] - } - } - }, { - "id": "landuse_wood", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "wood" }, - "type": "fill", - "style": { - "fill-color": "@wood" - }, - "style.night": { - "fill-color": "@wood_night", - "fill-opacity": 0.8 - } - }, { - "id": "landuse_school", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "school" }, - "type": "fill", - "style": { - "fill-color": "@school" - }, - "style.night": { - "fill-color": "@school_night" - } - }, { - "id": "landuse_sand", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "sand" }, - "type": "fill", - "style": { - "fill-color": "@sand" - }, - "style.night": { - "fill-color": "@sand_night", - "fill-opacity": 0.8 - } - }, { - "id": "landuse_pitch", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "pitch" }, - "type": "fill", - "style": { - "fill-color": "rgba(255,255,255,0.5)", - "fill-outline-color": "@pitch" - }, - "style.night": { - "fill-color": "@pitch_night", - "fill-outline-color": "@pitch" - } - }, { - "id": "landuse_park", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "park" }, - "type": "fill", - "style": { - "fill-color": "@park" - }, - "style.night": { - "fill-color": "@park_night" - } - }, { - "id": "landuse_industrial", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "industrial" }, - "type": "fill", - "style": { - "fill-color": "rgba(246,250,255,0.5)" - }, - "style.night": { - "fill-color": "@builtup_night" - } - }, { - "id": "landuse_scrub", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "scrub" }, - "type": "fill", - "style": { - "fill-color": "@scrub" - }, - "style.night": { - "fill-color": "@scrub_night", - "fill-opacity": 0.8 - } - }, { - "id": "landuse_grass", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "grass" }, - "type": "fill", - "style": { - "fill-color": "@grass" - }, - "style.night": { - "fill-color": "@grass_night", - "fill-opacity": 0.8 - } - }, { - "id": "landuse_crop", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "crop" }, - "type": "fill", - "style": { - "fill-color": "@crop" - }, - "style.night": { - "fill-color": "@crop_night", - "fill-opacity": 0.8 - } - }, { - "id": "landuse_rock", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "rock" }, - "type": "fill", - "style": { - "fill-color": "@rock" - }, - "style.night": { - "fill-color": "@rock_night", - "fill-opacity": 0.8 - } - }, { - "id": "landuse_snow", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "snow" }, - "type": "fill", - "style": { - "fill-color": "@snow" - }, - "style.night": { - "fill-color": "@snow_night", - "fill-opacity": 0.8 - } - }, { - "id": "landuse_hospital", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "hospital" }, - "type": "fill", - "style": { - "fill-color": "@hospital" - }, - "style.night": { - "fill-color": "@hospital_night" - } - }, { - "id": "landuse_cemetery", - "source": "mapbox", - "source-layer": "landuse", - "filter": { "class": "cemetery" }, - "type": "fill", - "style": { - "fill-color": "@cemetery" - }, - "style.night": { - "fill-color": "@cemetery_night" - } - }, { - "id": "overlay_wetland", - "source": "mapbox", - "source-layer": "landuse_overlay", - "filter": { "class": ["wetland", "wetland_noveg"] }, - "type": "fill", - "style": { - "fill-color": "rgba(210,225,225,0.2)", - "fill-image": "wetland_noveg_64" - }, - "style.night": { - "fill-color": "rgba(210,225,225,0.2)", - "fill-image": "wetland_noveg_64" - } - }, { - "id": "overlay_breakwater_pier", - "source": "mapbox", - "source-layer": "landuse_overlay", - "filter": { "class": ["breakwater", "pier"] }, - "type": "fill", - "style": { - "fill-color": "@land" - }, - "style.night": { - "fill-color": "@land_night" - } - }, { - "id": "waterway_river_canal", - "source": "mapbox", - "source-layer": "waterway", - "filter": { "type": ["river", "canal"] }, - "type": "line", - "render": { - "line-cap": "round" - }, - "style": { - "line-color": "#87abaf", - "line-width": "@river_canal_width" - }, - "style.night": { - "line-color": "rgb(10,20,71)", - "line-width": "@river_canal_width" - } - }, { - "id": "waterway_stream", - "source": "mapbox", - "source-layer": "waterway", - "filter": { "type": "stream" }, - "type": "line", - "render": { - "line-cap": "round" - }, - "style": { - "line-color": "#87abaf", - "line-width": "@stream_width" - }, - "style.night": { - "line-color": "rgb(10,20,71)", - "line-width": "@stream_width" - } - }, { - "id": "building_shadow", - "source": "mapbox", - "source-layer": "building", - "type": "fill", - "style": { - "fill-color": "#d5d1c6", - "fill-translate": [1, 1], - "fill-opacity": { - "stops": [[15.5, 0], [16, 1]] - }, - "fill-outline-color": "#d5d1c6" - }, - "style.night": { - "fill-color": "#026688", - "fill-translate": [1, 1], - "fill-opacity": { - "stops": [[15.5, 0], [16, 1]] - }, - "fill-outline-color": "#026688" - } - }, { - "id": "building", - "ref": "building_shadow", - "style": { - "fill-color": "#ebe7db" - }, - "style.night": { - "fill-color": "#027797" - } - }, { - "id": "building_wall", - "ref": "building_shadow", - "style": { - "fill-color": "#ebe7db", - "fill-opacity": { - "stops": [[15.5, 0], [16, 0.7]] - }, - "fill-outline-color": "#d5d1c6" - }, - "style.night": { - "fill-color": "#027797", - "fill-opacity": { - "stops": [[15.5, 0], [16, 0.7]] - }, - "fill-outline-color": "#026688" - } - }, { - "id": "hillshade_full_highlight", - "source": "mapbox", - "source-layer": "hillshade", - "filter": { "class": "full_highlight" }, - "type": "fill", - "rasterize": "@hillshade_rasterize", - "style": { - "fill-color": "#fffff3", - "fill-antialias": false, - "fill-opacity": { - "stops": [[14, 0.3], [15, 0.3], [16, 0.2], [17, 0.2], [18, 0.1]] - } - }, - "style.night": { - "fill-color": "#fdfdad", - "fill-antialias": false, - "fill-opacity": { - "stops": [[13, 0.4], [14, 0.3], [16, 0.2], [17, 0.1], [18, 0.05]] - } - } - }, { - "id": "hillshade_medium_highlight", - "source": "mapbox", - "source-layer": "hillshade", - "filter": { "class": "medium_highlight" }, - "type": "fill", - "rasterize": "@hillshade_rasterize", - "style": { - "fill-color": "#ffd", - "fill-antialias": false, - "fill-opacity": { - "stops": [[14, 0.3], [15, 0.3], [16, 0.2], [17, 0.2], [18, 0.1]] - } - }, - "style.night": { - "fill-color": "#ffe1b7", - "fill-antialias": false, - "fill-opacity": { - "stops": [[14, 0.3], [16, 0.2], [17, 0.15], [18, 0.05]] - } - } - }, { - "id": "hillshade_medium_shadow", - "source": "mapbox", - "source-layer": "hillshade", - "filter": { "class": "medium_shadow" }, - "type": "fill", - "rasterize": "@hillshade_rasterize", - "style": { - "fill-color": "#206", - "fill-antialias": false, - "fill-opacity": { - "stops": [[14, 0.08], [15, 0.075], [16, 0.05], [17, 0.05], [18, 0.025]] - } - }, - "style.night": { - "fill-color": "#206", - "fill-antialias": false, - "fill-opacity": { - "stops": [[15, 0.3], [16, 0.2], [17, 0.1], [18, 0.05]] - } - } - }, { - "id": "hillshade_full_shadow", - "source": "mapbox", - "source-layer": "hillshade", - "filter": { "class": "full_shadow" }, - "type": "fill", - "rasterize": "@hillshade_rasterize", - "style": { - "fill-color": "#103", - "fill-antialias": false, - "fill-opacity": { - "stops": [[14, 0.08], [15, 0.075], [16, 0.05], [17, 0.05], [18, 0.025]] - } - }, - "style.night": { - "fill-color": "#103", - "fill-antialias": false, - "fill-opacity": { - "stops": [[15, 0.3], [16, 0.2], [17, 0.1], [18, 0.05]] - } - } - }, { - "id": "contour_line_loud", - "source": "mapbox", - "source-layer": "contour", - "filter": { "index": 5 }, - "type": "line", - "render": { - "line-join": "round" - }, - "style": { - "line-color": "#008", - "line-width": 0.9, - "line-opacity": { - "stops": [[11, 0.05], [12, 0.11]] - } - }, - "style.night": { - "line-color": "@contour_night", - "line-width": 0.9, - "line-opacity": { - "stops": [[11, 0.1], [12, 0.2]] - } - } - }, { - "id": "contour_line_regular", - "source": "mapbox", - "source-layer": "contour", - "type": "line", - "render": { - "line-join": "round" - }, - "style": { - "line-color": "#008", - "line-width": 0.5, - "line-opacity": { - "stops": [[11, 0.05], [12, 0.11]] - } - }, - "style.night": { - "line-color": "@contour_night", - "line-width": 0.5, - "line-opacity": { - "stops": [[11, 0.1], [12, 0.4]] - } - } - }, { - "id": "barrier_line_gate", - "source": "mapbox", - "source-layer": "barrier_line", - "filter": { "class": "gate" }, - "type": "line", - "style": { - "line-width": 2.5, - "line-color": "#aab" - }, - "style.night": { - "line-width": 2.5, - "line-color": "#59596f" - } - }, { - "id": "barrier_line_fence", - "source": "mapbox", - "source-layer": "barrier_line", - "filter": { "class": "fence" }, - "type": "line", - "style": { - "line-color": "#aeada3", - "line-width": "@fence_width" - }, - "style.night": { - "line-color": "#014b61", - "line-width": "@fence_width" - } - }, { - "id": "barrier_line_hedge", - "source": "mapbox", - "source-layer": "barrier_line", - "filter": { "class": "hedge" }, - "type": "line", - "style": { - "line-color": "#8de99b", - "line-width": "@hedge_width" - }, - "style.night": { - "line-color": "#2e7a57", - "line-width": "@hedge_width" - } - }, { - "id": "barrier_line_land", - "source": "mapbox", - "source-layer": "barrier_line", - "filter": { "class": "land" }, - "type": "line", - "style": { - "line-color": "@land", - "line-width": "@barrier_line_land_width" - }, - "style.night": { - "line-color": "@land_night", - "line-width": "@barrier_line_land_width" - } - }, { - "id": "barrier_line_land_fill", - "source": "mapbox", - "source-layer": "barrier_line", - "filter": { "class": "land" }, - "type": "fill", - "style": { - "fill-color": "@land" - }, - "style.night": { - "fill-color": "@land_night" - } - }, { - "id": "barrier_line_cliff", - "source": "mapbox", - "source-layer": "barrier_line", - "filter": { "class": "cliff" }, - "type": "line", - "style": { - "line-color": "#987", - "line-width": 4 - }, - "style.night": { - "line-color": "#63574b", - "line-width": 4 - } - }, { - "id": "water", - "source": "mapbox", - "source-layer": "water", - "type": "fill", - "style": { - "fill-color": "@water", - "fill-outline-color": "#a2bdc0" - }, - "style.night": { - "fill-color": "@water_night", - "fill-outline-color": "@water_dark_night" - } - }, { - "id": "aeroway_fill", - "source": "mapbox", - "source-layer": "aeroway", - "type": "fill", - "style": { - "fill-color": "#ddd" - }, - "style.night": { - "fill-color": "#367" - } - }, { - "id": "aeroway_runway", - "source": "mapbox", - "source-layer": "aeroway", - "filter": { "type": "runway" }, - "type": "line", - "style": { - "line-color": "#ddd", - "line-width": "@runway_width" - }, - "style.night": { - "line-color": "#367", - "line-width": "@runway_width" - } - }, { - "id": "aeroway_taxiway", - "source": "mapbox", - "source-layer": "aeroway", - "filter": { "type": "taxiway" }, - "type": "line", - "style": { - "line-color": "#ddd", - "line-width": "@taxiway_width" - }, - "style.night": { - "line-color": "#367", - "line-width": "@taxiway_width" - } - }, { - "id": "tunnel_motorway_link_casing", - "source": "mapbox", - "source-layer": "tunnel", - "filter": { "class": "motorway_link" }, - "type": "line", - "style": { - "line-color": "@case", - "line-dasharray": [6, 6], - "line-width": "@motorway_link_casing_width" - }, - "style.night": { - "line-color": "@case_night", - "line-dasharray": [6, 6], - "line-width": "@motorway_link_casing_width" - } - }, { - "id": "tunnel_service_casing", - "source": "mapbox", - "source-layer": "tunnel", - "filter": { "class": "service" }, - "type": "line", - "style": { - "line-color": "#000", - "line-opacity": 0.04, - "line-dasharray": [6, 6], - "line-width": "@service_casing_width" - }, - "style.night": { - "line-color": "#000", - "line-opacity": 0.04, - "line-dasharray": [6, 6], - "line-width": "@service_casing_width" - } - }, { - "id": "tunnel_main_casing", - "source": "mapbox", - "source-layer": "tunnel", - "filter": { "class": "main" }, - "type": "line", - "style": { - "line-color": "@case", - "line-dasharray": [6, 6], - "line-width": "@main_casing_width", - "line-opacity": { - "stops": [[8, 0], [9, 1]] - } - }, - "style.night": { - "line-color": "@case_night", - "line-dasharray": [6, 6], - "line-width": "@main_casing_width", - "line-opacity": { - "stops": [[8, 0], [9, 1]] - } - } - }, { - "id": "tunnel_street_casing", - "source": "mapbox", - "source-layer": "tunnel", - "filter": { "class": ["street", "street_limited"] }, - "type": "line", - "style": { - "line-color": "#d9d5c6", - "line-width": "@street_casing_width", - "line-opacity": "@street_casing_opacity" - }, - "style.night": { - "line-color": "@street_case_night", - "line-width": "@street_casing_width", - "line-opacity": "@street_casing_opacity" - } - }, { - "id": "tunnel_motorway_link", - "ref": "tunnel_motorway_link_casing", - "style": { - "line-color": "#e6cec7", - "line-width": "@motorway_link_width" - }, - "style.night": { - "line-color": "#78b0c1", - "line-width": "@motorway_link_width" - } - }, { - "id": "tunnel_service", - "ref": "tunnel_service_casing", - "style": { - "line-color": "#e6cec7", - "line-width": 2 - }, - "style.night": { - "line-color": "#017ca0", - "line-width": 2 - } - }, { - "id": "tunnel_street", - "ref": "tunnel_street_casing", - "style": { - "line-color": "#d9d5c6", - "line-width": "@street_width" - }, - "style.night": { - "line-color": "@street_night", - "line-width": "@street_width" - } - }, { - "id": "tunnel_main", - "ref": "tunnel_main_casing", - "style": { - "line-color": "#e6cec7", - "line-width": "@main_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - }, - "style.night": { - "line-color": "#78b0c1", - "line-width": "@main_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - } - }, { - "id": "tunnel_motorway_casing", - "source": "mapbox", - "source-layer": "tunnel", - "filter": { "class": "motorway" }, - "type": "line", - "style": { - "line-color": "@case", - "line-dasharray": [6, 6], - "line-width": "@motorway_casing_width", - "line-opacity": { - "stops": [[8.5, 0], [9, 1]] - } - }, - "style.night": { - "line-color": "@case_night", - "line-dasharray": [6, 6], - "line-width": "@motorway_casing_width", - "line-opacity": { - "stops": [[8.5, 0], [9, 1]] - } - } - }, { - "id": "tunnel_motorway", - "ref": "tunnel_motorway_casing", - "style": { - "line-color": "#e6cec7", - "line-width": "@motorway_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - }, - "style.night": { - "line-color": "#78b0c1", - "line-width": "@motorway_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - } - }, { - "id": "road_path_case", - "source": "mapbox", - "source-layer": "road", - "filter": { "class": "path" }, - "type": "line", - "style": { - "line-color": "#ffd", - "line-opacity": 0.4, - "line-width": { - "stops": [[14, 3], [15, 4]] - } - }, - "style.night": { - "line-color": "@land_night", - "line-opacity": 0.2 - } - }, { - "id": "road_path_footway", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "type": "footway" }, - "type": "line", - "style": { - "line-color": "#bba", - "line-dasharray": [10, 4], - "line-width": "@path_width" - }, - "style.night": { - "line-color": "#fff", - "line-dasharray": [10, 4], - "line-width": "@path_width" - } - }, { - "id": "road_path_path", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "type": "path" }, - "type": "line", - "style": { - "line-color": "#987", - "line-dasharray": [10, 4], - "line-opacity": 0.8, - "line-width": { - "stops": [[13, 0.8], [14, 0.9], [15, 1.2]] - } - }, - "style.night": { - "line-color": "#fff", - "line-dasharray": [10, 4], - "line-opacity": 0.8, - "line-width": { - "stops": [[13, 0.8], [14, 0.9], [15, 1.2]] - } - } - }, { - "id": "road_path_cycleway", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "type": "cycleway" }, - "type": "line", - "style": { - "line-color": "#488", - "line-dasharray": [10, 4], - "line-width": "@path_width" - }, - "style.night": { - "line-color": "#94e6ff", - "line-dasharray": [10, 4], - "line-width": "@path_width" - } - }, { - "id": "road_path_mtb", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "type": "mtb" }, - "type": "line", - "style": { - "line-color": "#488", - "line-dasharray": [12, 4], - "line-width": "@path_width" - }, - "style.night": { - "line-color": "#94e6ff", - "line-dasharray": [12, 4], - "line-width": "@path_width" - } - }, { - "id": "road_path_piste", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "type": "piste" }, - "type": "line", - "style": { - "line-color": "#87b", - "line-dasharray": [8, 4], - "line-width": "@path_width" - }, - "style.night": { - "line-color": "#715dae", - "line-dasharray": [8, 4], - "line-width": "@path_width" - } - }, { - "id": "road_path_steps", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "type": "steps" }, - "type": "line", - "style": { - "line-color": "#bba", - "line-dasharray": [10, 4], - "line-width": 4 - }, - "style.night": { - "line-color": "#016684", - "line-dasharray": [10, 4], - "line-opacity": 0.3, - "line-width": 6 - } - }, { - "id": "road_major_rail", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "class": "major_rail" }, - "type": "line", - "style": { - "line-color": "#c8c4c0", - "line-width": 0.8 - }, - "style.night": { - "line-color": "#c8c4c0", - "line-width": 0.8 - } - }, { - "id": "road_motorway_link_casing", - "source": "mapbox", - "source-layer": "road", - "filter": { "class": "motorway_link" }, - "type": "line", - "render": { - "line-join": "round", - "line-cap": "round" - }, - "style": { - "line-color": "@case", - "line-width": "@motorway_link_casing_width" - }, - "style.night": { - "line-color": "@case_night", - "line-width": "@motorway_link_casing_width" - } - }, { - "id": "road_service_casing", - "source": "mapbox", - "source-layer": "road", - "filter": { "class": "service" }, - "type": "line", - "render": { - "line-join": "round", - "line-cap": "round" - }, - "style": { - "line-color": "#000", - "line-opacity": 0.04, - "line-width": "@service_casing_width" - }, - "style.night": { - "line-color": "#000", - "line-opacity": 0.04, - "line-width": "@service_casing_width" - } - }, { - "id": "road_main_casing", - "source": "mapbox", - "source-layer": "road", - "filter": { "class": "main" }, - "type": "line", - "render": { - "line-join": "round", - "line-cap": "round" - }, - "style": { - "line-color": "@case", - "line-width": "@main_casing_width", - "line-opacity": { - "stops": [[8, 0], [9, 1]] - } - }, - "style.night": { - "line-color": "@case_night", - "line-width": "@main_casing_width", - "line-opacity": { - "stops": [[8, 0], [9, 1]] - } - } - }, { - "id": "road_street_casing", - "source": "mapbox", - "source-layer": "road", - "filter": { "class": ["street", "street_limited"] }, - "type": "line", - "render": { - "line-join": "round", - "line-cap": "round" - }, - "style": { - "line-color": "#d9d5c6", - "line-width": "@street_casing_width", - "line-opacity": "@street_casing_opacity" - }, - "style.night": { - "line-color": "@street_case_night", - "line-width": "@street_casing_width", - "line-opacity": "@street_casing_opacity" - } - }, { - "id": "road_motorway_link", - "ref": "road_motorway_link_casing", - "style": { - "line-color": "@motorway", - "line-width": "@motorway_link_width" - }, - "style.night": { - "line-color": "@motorway_night", - "line-width": "@motorway_link_width" - } - }, { - "id": "road_service", - "ref": "road_service_casing", - "style": { - "line-color": "@street", - "line-width": 2 - }, - "style.night": { - "line-color": "@street_night", - "line-width": 2 - } - }, { - "id": "road_street", - "ref": "road_street_casing", - "style": { - "line-color": "@street", - "line-width": "@street_width" - }, - "style.night": { - "line-color": "@street_night", - "line-width": "@street_width" - } - }, { - "id": "road_main", - "ref": "road_main_casing", - "style": { - "line-color": "@main", - "line-width": "@main_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - }, - "style.night": { - "line-color": "@main_night", - "line-width": "@main_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - } - }, { - "id": "road_motorway_casing", - "source": "mapbox", - "source-layer": "road", - "filter": { "class": "motorway" }, - "type": "line", - "render": { - "line-join": "round", - "line-cap": "round" - }, - "style": { - "line-color": "@case", - "line-width": "@motorway_casing_width", - "line-opacity": { - "stops": [[8.5, 0], [9, 1]] - } - }, - "style.night": { - "line-color": "@case_night", - "line-width": "@motorway_casing_width", - "line-opacity": { - "stops": [[8.5, 0], [9, 1]] - } - } - }, { - "id": "road_motorway", - "ref": "road_motorway_casing", - "style": { - "line-color": "@motorway", - "line-width": "@motorway_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - }, - "style.night": { - "line-color": "@motorway_night", - "line-width": "@motorway_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - } - }, { - "id": "road_major_rail_hatching", - "ref": "road_major_rail", - "style": { - "line-color": "#c8c4c0", - "line-dasharray": [2, 31], - "line-width": 5 - }, - "style.night": { - "line-color": "#c8c4c0", - "line-dasharray": [2, 31], - "line-width": 5 - } - }, { - "id": "bridge_motorway_link_casing", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "class": "motorway_link" }, - "type": "line", - "style": { - "line-color": "@case", - "line-width": "@motorway_link_casing_width" - }, - "style.night": { - "line-color": "@case_night", - "line-width": "@motorway_link_casing_width" - } - }, { - "id": "bridge_service_casing", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "class": "service" }, - "type": "line", - "style": { - "line-color": "#000", - "line-opacity": 0.04, - "line-width": "@service_casing_width" - }, - "style.night": { - "line-color": "#000", - "line-opacity": 0.04, - "line-width": "@service_casing_width" - } - }, { - "id": "bridge_main_casing", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "class": "main" }, - "type": "line", - "style": { - "line-color": "@case", - "line-width": "@main_casing_width", - "line-opacity": { - "stops": [[8, 0], [9, 1]] - } - }, - "style.night": { - "line-color": "@case_night", - "line-width": "@main_casing_width", - "line-opacity": { - "stops": [[8, 0], [9, 1]] - } - } - }, { - "id": "bridge_street_casing", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "class": ["street", "street_limited"] }, - "type": "line", - "style": { - "line-color": "#d9d5c6", - "line-width": "@street_casing_width", - "line-opacity": "@street_casing_opacity" - }, - "style.night": { - "line-color": "@street_case_night", - "line-width": "@street_casing_width", - "line-opacity": "@street_casing_opacity" - } - }, { - "id": "bridge_motorway_link", - "ref": "bridge_motorway_link_casing", - "style": { - "line-color": "@motorway", - "line-width": "@motorway_link_width" - }, - "style.night": { - "line-color": "@motorway_night", - "line-width": "@motorway_link_width" - } - }, { - "id": "bridge_service", - "ref": "bridge_service_casing", - "style": { - "line-color": "@street", - "line-width": 2 - }, - "style.night": { - "line-color": "@street_night", - "line-width": 2 - } - }, { - "id": "bridge_street", - "ref": "bridge_street_casing", - "style": { - "line-color": "@street", - "line-width": "@street_width" - }, - "style.night": { - "line-color": "@street_night", - "line-width": "@street_width" - } - }, { - "id": "bridge_main", - "ref": "bridge_main_casing", - "style": { - "line-color": "@main", - "line-width": "@main_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - }, - "style.night": { - "line-color": "@main_night", - "line-width": "@main_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - } - }, { - "id": "bridge_motorway_casing", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "class": "motorway" }, - "type": "line", - "style": { - "line-color": "@case", - "line-width": "@motorway_casing_width", - "line-opacity": { - "stops": [[8.5, 0], [9, 1]] - } - }, - "style.night": { - "line-color": "@case_night", - "line-width": "@motorway_casing_width", - "line-opacity": { - "stops": [[8.5, 0], [9, 1]] - } - } - }, { - "id": "bridge_motorway", - "ref": "bridge_motorway_casing", - "style": { - "line-color": "@motorway", - "line-width": "@motorway_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - }, - "style.night": { - "line-color": "@motorway_night", - "line-width": "@motorway_width", - "line-opacity": { - "stops": [[5.5, 0], [6, 1]] - } - } - }, { - "id": "bridge_aerialway_casing", - "source": "mapbox", - "source-layer": "bridge", - "filter": { "class": "aerialway" }, - "type": "line", - "style": { - "line-color": "white", - "line-opacity": 0.5, - "line-width": "@aerialway_casing_width" - }, - "style.night": { - "line-color": "white", - "line-opacity": 0.5, - "line-width": "@aerialway_casing_width" - } - }, { - "id": "bridge_aerialway", - "ref": "bridge_aerialway_casing", - "style": { - "line-color": "#876", - "line-opacity": 0.5, - "line-width": "@aerialway_width" - }, - "style.night": { - "line-color": "#876", - "line-opacity": 0.5, - "line-width": "@aerialway_width" - } - }, { - "id": "admin_l3", - "source": "mapbox", - "source-layer": "admin", - "filter": { "admin_level": [3, 4, 5] }, - "type": "line", - "render": { - "line-join": "round" - }, - "style": { - "line-color": "#88a", - "line-dasharray": [60, 20], - "line-opacity": { - "stops": [[3, 0], [5, 1]] - }, - "line-width": "@admin_l3_width" - }, - "style.night": { - "line-color": "@admin_night", - "line-dasharray": [60, 20], - "line-opacity": { - "stops": [[3, 0], [5, 1]] - }, - "line-width": "@admin_l3_width" - } - }, { - "id": "admin_l2", - "source": "mapbox", - "source-layer": "admin", - "filter": { "admin_level": 2 }, - "type": "line", - "render": { - "line-join": "round", - "line-cap": "round" - }, - "style": { - "line-color": "#88a", - "line-width": "@admin_l2_width" - }, - "style.night": { - "line-color": "@admin_night", - "line-width": "@admin_l2_width" - } - }, { - "id": "admin_maritime_cover", - "source": "mapbox", - "source-layer": "admin", - "filter": { "maritime": 1 }, - "type": "line", - "render": { - "line-join": "round", - "line-cap": "round" - }, - "style": { - "line-color": "@water", - "line-width": 5 - }, - "style.night": { - "line-color": "@water_night", - "line-width": 5 - } - }, { - "id": "admin_maritime", - "ref": "admin_maritime_cover", - "style": { - "line-color": "#c0d6d6", - "line-width": { - "stops": [[5, 1], [7, 2], [11, 3]] - } - }, - "style.night": { - "line-color": "#0a1347", - "line-width": { - "stops": [[5, 1], [7, 2], [11, 3]] - } - } - }, { - "id": "country_label_line", - "source": "mapbox", - "source-layer": "country_label_line", - "type": "line", - "render": { - "text-max-width": 5 - }, - "style": { - "line-color": "@country_text", - "line-width": 0.5, - "line-opacity": 0.5 - }, - "style.night": { - "line-color": "@text_night", - "line-width": 0.5, - "line-opacity": 0.5 - } - }, { - "id": "country_label", - "source": "mapbox", - "source-layer": "country_label", - "filter": { "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold, Arial Unicode MS Bold", - "text-max-size": 24, - "text-max-width": 5 - }, - "style": { - "text-color": "@country_text", - "text-halo-color": "rgba(255,255,255,0.5)", - "text-halo-width": 0.5, - "text-size": "@country_label_size" - }, - "style.night": { - "text-color": "@text_night", - "text-halo-color": "@text2_stroke_night", - "text-halo-width": 0.4, - "text-size": "@country_label_size" - } - }, { - "id": "marine_label_line_1", - "source": "mapbox", - "source-layer": "marine_label", - "filter": { "$type": "LineString", "labelrank": 1 }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "curve", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 30, - "text-max-angle": 0.5, - "text-letter-spacing": 0.4 - }, - "style": { - "text-color": "@marine_text", - "text-size": { - "stops": [[2, 20], [3, 25], [4, 30], [21, 30]] - }, - "text-halo-color": "@water" - }, - "style.night": { - "text-color": "@water_dark_night", - "text-size": { - "stops": [[2, 20], [3, 25], [4, 30], [21, 30]] - }, - "text-halo-color": "@water_night" - } - }, { - "id": "marine_label_line_2", - "source": "mapbox", - "source-layer": "marine_label", - "filter": { "$type": "LineString", "labelrank": 2 }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "curve", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 24, - "text-max-angle": 0.5 - }, - "style": { - "text-color": "@marine_text", - "text-size": { - "stops": [[2, 13], [3, 14], [4, 20], [5, 24], [21, 24]] - }, - "text-halo-color": "@water" - }, - "style.night": { - "text-color": "@water_dark_night", - "text-size": { - "stops": [[2, 13], [3, 14], [4, 20], [5, 24], [21, 24]] - }, - "text-halo-color": "@water_night" - } - }, { - "id": "marine_label_line_3", - "source": "mapbox", - "source-layer": "marine_label", - "filter": { "$type": "LineString", "labelrank": 3 }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "curve", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 18, - "text-max-angle": 0.5 - }, - "style": { - "text-color": "@marine_text", - "text-size": { - "stops": [[2, 12], [3, 13], [4, 15], [5, 18], [21, 18]] - }, - "text-halo-color": "@water" - }, - "style.night": { - "text-color": "@water_dark_night", - "text-size": { - "stops": [[2, 12], [3, 13], [4, 15], [5, 18], [21, 18]] - }, - "text-halo-color": "@water_night" - } - }, { - "id": "marine_label_line_other", - "source": "mapbox", - "source-layer": "marine_label", - "filter": { "$type": "LineString", "labelrank": [4, 5, 6] }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "curve", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 16, - "text-max-angle": 0.5 - }, - "style": { - "text-color": "@marine_text", - "text-size": { - "stops": [[3, 12], [4, 14], [5, 16], [21, 16]] - }, - "text-halo-color": "@water" - }, - "style.night": { - "text-color": "@water_dark_night", - "text-size": { - "stops": [[3, 12], [4, 14], [5, 16], [21, 16]] - }, - "text-halo-color": "@water_night" - } - }, { - "id": "marine_label_point_1", - "source": "mapbox", - "source-layer": "marine_label", - "filter": { "$type": "Point", "labelrank": 1 }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 30, - "text-max-width": 8, - "text-letter-spacing": 0.4, - "text-line-height": 2 - }, - "style": { - "text-color": "@marine_text", - "text-size": { - "stops": [[2, 20], [3, 25], [4, 30], [21, 30]] - }, - "text-halo-color": "@water" - }, - "style.night": { - "text-color": "@water_dark_night", - "text-size": { - "stops": [[2, 20], [3, 25], [4, 30], [21, 30]] - }, - "text-halo-color": "@water_night" - } - }, { - "id": "marine_label_point_2", - "source": "mapbox", - "source-layer": "marine_label", - "filter": { "$type": "Point", "labelrank": 2 }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 24, - "text-max-width": 8, - "text-letter-spacing": 0.2, - "text-line-height": 1.5 - }, - "style": { - "text-color": "@marine_text", - "text-size": { - "stops": [[2, 13], [3, 14], [4, 20], [5, 24], [21, 24]] - }, - "text-halo-color": "@water" - }, - "style.night": { - "text-color": "@water_dark_night", - "text-size": { - "stops": [[2, 13], [3, 14], [4, 20], [5, 24], [21, 24]] - }, - "text-halo-color": "@water_night" - } - }, { - "id": "marine_label_point_3", - "source": "mapbox", - "source-layer": "marine_label", - "filter": { "$type": "Point", "labelrank": 3 }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 18, - "text-max-width": 8, - "text-letter-spacing": 0.1, - "text-line-height": 1.3 - }, - "style": { - "text-color": "@marine_text", - "text-size": { - "stops": [[2, 12], [3, 13], [4, 15], [5, 18], [21, 18]] - }, - "text-halo-color": "@water" - }, - "style.night": { - "text-color": "@water_dark_night", - "text-size": { - "stops": [[2, 12], [3, 13], [4, 15], [5, 18], [21, 18]] - }, - "text-halo-color": "@water_night" - } - }, { - "id": "marine_label_point_other", - "source": "mapbox", - "source-layer": "marine_label", - "filter": { "$type": "Point", "labelrank": [4, 5, 6] }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 16, - "text-max-width": 8, - "text-letter-spacing": 0.1, - "text-line-height": 1.2 - }, - "style": { - "text-color": "@marine_text", - "text-size": { - "stops": [[3, 12], [4, 14], [5, 16], [21, 16]] - }, - "text-halo-color": "@water" - }, - "style.night": { - "text-color": "@water_dark_night", - "text-size": { - "stops": [[3, 12], [4, 14], [5, 16], [21, 16]] - }, - "text-halo-color": "@water_night" - } - }, { - "id": "state_label", - "source": "mapbox", - "source-layer": "state_label", - "filter": { "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Regular, Arial Unicode MS Regular", - "text-max-size": 16, - "text-max-width": 8 - }, - "style": { - "text-color": "#333", - "text-halo-width": 0.4, - "text-halo-color": "rgba(244,239,225,0.8)", - "text-size": { - "stops": [[2.99, 0], [3, 10], [8.99, 16], [9, 0]] - } - }, - "style.night": { - "text-color": "#fff", - "text-halo-width": 0.4, - "text-halo-color": "@land_night", - "text-size": { - "stops": [[2.99, 0], [3, 10], [8.99, 16], [9, 0]] - } - } - }, { - "id": "place_label_city", - "source": "mapbox", - "source-layer": "place_label", - "filter": { "type": "city", "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold, Arial Unicode MS Bold", - "text-max-size": 20, - "text-max-width": 8 - }, - "style": { - "text-color": "#444", - "text-halo-width": 0.4, - "text-halo-color": "@text_stroke", - "text-size": { - "stops": [[2.99, 0], [3, 10], [6, 14], [13.99, 20], [14, 0]] - } - }, - "style.night": { - "text-color": "#fff", - "text-halo-width": 0.4, - "text-halo-color": "@text2_stroke_night", - "text-size": { - "stops": [[2.99, 0], [3, 10], [6, 14], [13.99, 20], [14, 0]] - } - } - }, { - "id": "place_label_town", - "source": "mapbox", - "source-layer": "place_label", - "filter": { "type": "town", "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold, Arial Unicode MS Bold", - "text-max-size": 24, - "text-max-width": 8 - }, - "style": { - "text-color": "#716656", - "text-halo-width": 0.3, - "text-halo-color": "@text_stroke", - "text-size": { - "stops": [[8, 10], [11, 13], [13, 17], [15, 22]] - } - }, - "style.night": { - "text-color": "@text_night", - "text-halo-width": 0.3, - "text-halo-color": "@text2_stroke_night", - "text-size": { - "stops": [[8, 10], [11, 13], [13, 17], [15, 22]] - } - } - }, { - "id": "place_label_village", - "source": "mapbox", - "source-layer": "place_label", - "filter": { "type": "village", "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold, Arial Unicode MS Bold", - "text-max-size": 22, - "text-max-width": 8 - }, - "style": { - "text-color": "#635644", - "text-halo-width": 0.3, - "text-halo-color": "@text_stroke", - "text-size": { - "stops": [[8, 8], [11, 10], [13, 14], [15, 16], [16, 20]] - } - }, - "style.night": { - "text-color": "@text_night", - "text-halo-width": 0.3, - "text-halo-color": "@text2_stroke_night", - "text-size": { - "stops": [[8, 8], [11, 10], [13, 14], [15, 16], [16, 20]] - } - } - }, { - "id": "place_label_other", - "source": "mapbox", - "source-layer": "place_label", - "filter": { "type": ["hamlet", "suburb", "neighbourhood"], "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold, Arial Unicode MS Bold", - "text-max-size": 18, - "text-max-width": 6 - }, - "style": { - "text-color": "#7d6c55", - "text-halo-color": "@text_stroke", - "text-size": { - "stops": [[12, 11], [13, 12], [15, 14], [17, 18]] - } - }, - "style.night": { - "text-color": "@text_night", - "text-halo-color": "@text2_stroke_night", - "text-halo-width": 0.3, - "text-size": { - "stops": [[12, 11], [13, 12], [15, 14], [17, 18]] - } - } - }, { - "id": "road_label_1", - "source": "mapbox", - "source-layer": "road_label", - "filter": { "class": ["motorway", "main"], "$type": "LineString" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "curve", - "text-padding": 2, - "text-font": "Open Sans Regular, Arial Unicode MS Regular", - "text-max-size": 18, - "text-max-angle": 0.5 - }, - "style": { - "text-color": "#585042", - "text-halo-color": "@land", - "text-halo-width": 0.6, - "text-size": "@road_label_1_size" - }, - "style.night": { - "text-color": "@text_night", - "text-halo-color": "@text2_stroke_night", - "text-halo-width": 0.5, - "text-size": "@road_label_1_size" - } - }, { - "id": "road_label_2", - "source": "mapbox", - "source-layer": "road_label", - "filter": { "class": ["street", "street_limited"], "$type": "LineString" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "curve", - "text-padding": 2, - "text-font": "Open Sans Regular, Arial Unicode MS Regular", - "text-max-size": 16, - "text-max-angle": 0.5 - }, - "style": { - "text-color": "#585042", - "text-halo-color": "@land", - "text-halo-width": 0.6, - "text-size": "@road_label_2_size" - }, - "style.night": { - "text-color": "@text_night", - "text-halo-color": "@text2_stroke_night", - "text-halo-width": 0.5, - "text-size": "@road_label_2_size" - } - }, { - "id": "road_label_3", - "source": "mapbox", - "source-layer": "road_label", - "filter": { "class": ["service", "driveway", "path"], "$type": "LineString" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "curve", - "text-padding": 2, - "text-font": "Open Sans Regular, Arial Unicode MS Regular", - "text-max-size": 14, - "text-max-angle": 0.5 - }, - "style": { - "text-color": "#585042", - "text-halo-color": "@land", - "text-halo-width": 0.6, - "text-size": "@road_label_3_size" - }, - "style.night": { - "text-color": "@text_night", - "text-halo-color": "@text2_stroke_night", - "text-halo-width": 0.5, - "text-size": "@road_label_3_size" - } - }, { - "id": "contour_label", - "source": "mapbox", - "source-layer": "contour", - "filter": { "index": [5, 10], "$type": "LineString" }, - "type": "text", - "render": { - "text-path": "curve", - "text-field": "{ele} m", - "text-font": "Open Sans Regular, Arial Unicode MS Regular", - "text-max-size": 10, - "text-max-angle": 0.5 - }, - "style": { - "text-color": "@text", - "text-halo-color": "@land", - "text-halo-width": 0.3, - "text-size": 10 - }, - "style.night": { - "text-color": "@contour_night", - "text-halo-color": "@land_night", - "text-halo-width": 0.3, - "text-size": 10 - } - }, { - "id": "water_label", - "source": "mapbox", - "source-layer": "water_label", - "filter": { "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 12, - "text-max-width": 8 - }, - "style": { - "text-color": "@water_dark", - "text-halo-color": "rgba(255,255,255,0.75)" - }, - "style.night": { - "text-color": "@text_water_night", - "text-halo-color": "@water_night" - } - }, { - "id": "waterway_label", - "source": "mapbox", - "source-layer": "waterway_label", - "filter": { "$type": "LineString" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "curve", - "text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold", - "text-max-size": 12, - "text-max-angle": 0.5 - }, - "style": { - "text-color": "@water_dark", - "text-halo-width": 0.4, - "text-halo-color": "@text_stroke" - }, - "style.night": { - "text-color": "@text_water_night", - "text-halo-color": "@water_night" - } - }, { - "id": "poi", - "source": "mapbox", - "source-layer": "poi_label", - "filter": { "scalerank": [1, 2] }, - "type": "icon", - "render": { - "icon-image": "{maki}-12", - "icon-size": 12 - }, - "style.night": {} - }, { - "id": "poi_label_1-2", - "source": "mapbox", - "source-layer": "poi_label", - "filter": { "scalerank": [1, 2], "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-padding": 2, - "text-font": "Open Sans Semibold, Arial Unicode MS Bold", - "text-max-size": 12, - "text-max-width": 10, - "text-alignment": "center" - }, - "style": { - "text-color": "#444", - "text-size": "@poi_label_1-2_size", - "text-halo-color": "@land", - "text-halo-width": 0.3 - }, - "style.night": { - "text-color": "#fff", - "text-size": "@poi_label_1-2_size", - "text-halo-color": "@text2_stroke_night", - "text-halo-width": 0.3 - } - }, { - "id": "poi_3", - "source": "mapbox", - "source-layer": "poi_label", - "filter": { "scalerank": 3 }, - "type": "icon", - "render": { - "icon-image": "{maki}-12", - "icon-size": 12 - }, - "style": { - "icon-opacity": { - "stops": [[15.5, 0], [15.75, 1]] - } - }, - "style.night": { - "icon-opacity": { - "stops": [[15.5, 0], [15.75, 1]] - } - } - }, { - "id": "poi_label_3", - "source": "mapbox", - "source-layer": "poi_label", - "filter": { "scalerank": 3, "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-padding": 2, - "text-font": "Open Sans Semibold, Arial Unicode MS Bold", - "text-max-size": 11, - "text-max-width": 10, - "text-alignment": "center" - }, - "style": { - "text-color": "#444", - "text-size": "@poi_label_3_size", - "text-halo-color": "@land", - "text-halo-width": 0.3, - "text-opacity": { - "stops": [[15.5, 0], [15.75, 1]] - } - }, - "style.night": { - "text-color": "#fff", - "text-size": "@poi_label_3_size", - "text-halo-color": "@text2_stroke_night", - "text-halo-width": 0.3, - "text-opacity": { - "stops": [[15.5, 0], [15.75, 1]] - } - } - }, { - "id": "poi_4", - "source": "mapbox", - "source-layer": "poi_label", - "filter": { "scalerank": 4 }, - "type": "icon", - "render": { - "icon-image": "{maki}-12", - "icon-size": 12 - }, - "style": { - "icon-opacity": { - "stops": [[17.5, 0], [17.75, 1]] - } - }, - "style.night": { - "icon-opacity": { - "stops": [[17.5, 0], [17.75, 1]] - } - } - }, { - "id": "poi_label_4", - "source": "mapbox", - "source-layer": "poi_label", - "filter": { "scalerank": 4, "$type": "Point" }, - "type": "text", - "render": { - "text-field": "{name_en}", - "text-path": "horizontal", - "text-padding": 2, - "text-font": "Open Sans Semibold, Arial Unicode MS Bold", - "text-max-size": 10, - "text-max-width": 10, - "text-alignment": "center" - }, - "style": { - "text-color": "#444", - "text-size": 10, - "text-opacity": { - "stops": [[17.5, 0], [17.75, 1]] - }, - "text-halo-color": "@land", - "text-halo-width": 0.3 - }, - "style.night": { - "text-color": "#fff", - "text-size": 10, - "text-opacity": { - "stops": [[17.5, 0], [17.75, 1]] - }, - "text-halo-color": "@text2_stroke_night", - "text-halo-width": 0.3 - } - }, { - "id": "poi_aerodrome", - "source": "mapbox", - "source-layer": "poi_label", - "filter": { "maki": "airport" }, - "type": "icon", - "render": { - "icon-image": "{maki}-12", - "icon-size": 12 - }, - "style": { - "icon-opacity": { - "stops": [[12, 0], [12.25, 1]] - } - }, - "style.night": { - "icon-opacity": { - "stops": [[12, 0], [12.25, 1]] - } - } - }] -} diff --git a/test/fixtures/style_parser/function-numeric.style.json b/test/fixtures/style_parser/function-numeric.style.json index 1df070263..2db5624ac 100644 --- a/test/fixtures/style_parser/function-numeric.style.json +++ b/test/fixtures/style_parser/function-numeric.style.json @@ -1,19 +1,19 @@ { - "version": 3, + "version": 6, "sources": { "mapbox": { "type": "vector", "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 + "maxzoom": 14 } }, "layers": [{ "id": "waterway_river_canal", + "type": "line", "source": "mapbox", "source-layer": "waterway", - "filter": { "type": ["river", "canal"] }, - "type": "line", - "style": { + "filter": ["in", "type", "river", "canal"], + "paint": { "line-width": { "stops": [0] } diff --git a/test/fixtures/style_parser/function-type.style.json b/test/fixtures/style_parser/function-type.style.json index 4439cf038..c992e71f0 100644 --- a/test/fixtures/style_parser/function-type.style.json +++ b/test/fixtures/style_parser/function-type.style.json @@ -1,19 +1,19 @@ { - "version": 3, + "version": 6, "sources": { "mapbox": { "type": "vector", "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 + "maxzoom": 14 } }, "layers": [{ "id": "waterway_river_canal", + "type": "line", "source": "mapbox", "source-layer": "waterway", - "filter": { "type": ["river", "canal"] }, - "type": "line", - "style": { + "filter": ["in", "type", "river", "canal"], + "paint": { "line-width": {} } }] diff --git a/test/fixtures/style_parser/line-opacity.style.json b/test/fixtures/style_parser/line-opacity.style.json index 31b0c1dea..8f5221b8a 100644 --- a/test/fixtures/style_parser/line-opacity.style.json +++ b/test/fixtures/style_parser/line-opacity.style.json @@ -1,19 +1,19 @@ { - "version": 3, + "version": 6, "sources": { "mapbox": { "type": "vector", "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 + "maxzoom": 14 } }, "layers": [{ "id": "contour_line_loud", + "type": "line", "source": "mapbox", "source-layer": "contour", - "filter": { "index": 5 }, - "type": "line", - "style": { + "filter": ["==", "index", 5], + "paint": { "line-color": "#008", "line-width": 0.9, "line-opacity": null diff --git a/test/fixtures/style_parser/line-width.style.json b/test/fixtures/style_parser/line-width.style.json index 83c66065d..18653074d 100644 --- a/test/fixtures/style_parser/line-width.style.json +++ b/test/fixtures/style_parser/line-width.style.json @@ -1,19 +1,19 @@ { - "version": 3, + "version": 6, "sources": { "mapbox": { "type": "vector", "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 + "maxzoom": 14 } }, "layers": [{ "id": "waterway_river_canal", + "type": "line", "source": "mapbox", "source-layer": "waterway", - "filter": { "type": ["river", "canal"] }, - "type": "line", - "style": { + "filter": ["in", "type", "river", "canal"], + "paint": { "line-width": null } }] diff --git a/test/fixtures/style_parser/stop-zoom-value.style.json b/test/fixtures/style_parser/stop-zoom-value.style.json index 87e674d52..5f907cd8e 100644 --- a/test/fixtures/style_parser/stop-zoom-value.style.json +++ b/test/fixtures/style_parser/stop-zoom-value.style.json @@ -1,41 +1,41 @@ { - "version": 3, + "version": 6, "sources": { "mapbox": { "type": "vector", "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 + "maxzoom": 14 } }, "layers": [{ "id": "landcover_grass", + "type": "fill", "source": "mapbox", "source-layer": "landcover", - "filter": { "class": "grass" }, - "type": "fill", - "style": { + "filter": ["==", "class", "grass"], + "paint": { "fill-opacity": { "stops": [] } } }, { "id": "landcover_scrub", + "type": "fill", "source": "mapbox", "source-layer": "landcover", - "filter": { "class": "scrub" }, - "type": "fill", - "style": { + "filter": ["==", "class", "scrub"], + "paint": { "fill-opacity": { "stops": [[12]] } } }, { "id": "landcover_wood", + "type": "fill", "source": "mapbox", "source-layer": "landcover", - "filter": { "class": "wood" }, - "type": "fill", - "style": { + "filter": ["==", "class", "wood"], + "paint": { "fill-color": "@wood", "fill-opacity": { "stops": [[12, 1], [13, 0.8], [16, 0.2]] diff --git a/test/fixtures/style_parser/stops-array.style.json b/test/fixtures/style_parser/stops-array.style.json index 67a2f83b0..107c1c064 100644 --- a/test/fixtures/style_parser/stops-array.style.json +++ b/test/fixtures/style_parser/stops-array.style.json @@ -1,19 +1,19 @@ { - "version": 3, + "version": 6, "sources": { "mapbox": { "type": "vector", "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 + "maxzoom": 14 } }, "layers": [{ "id": "waterway_river_canal", + "type": "line", "source": "mapbox", "source-layer": "waterway", - "filter": { "type": ["river", "canal"] }, - "type": "line", - "style": { + "filter": ["in", "type", "river", "canal"], + "paint": { "line-width": { "stops": null } diff --git a/test/fixtures/style_parser/text-size.style.json b/test/fixtures/style_parser/text-size.style.json index bb221efb6..175ce456a 100644 --- a/test/fixtures/style_parser/text-size.style.json +++ b/test/fixtures/style_parser/text-size.style.json @@ -1,19 +1,19 @@ { - "version": 3, + "version": 6, "sources": { "mapbox": { "type": "vector", "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", - "maxZoom": 14 + "maxzoom": 14 } }, "layers": [{ "id": "country_label", + "type": "text", "source": "mapbox", "source-layer": "country_label", - "filter": { "$type": "Point" }, - "type": "text", - "style": { + "filter": ["==", "$type", "Point"], + "paint": { "text-size": null } }] From 9a3b740fcc76d9f245ec330093b2e1231656697f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 1 Nov 2014 14:48:32 -0400 Subject: [PATCH 19/22] =?UTF-8?q?Render=20=E2=87=A2=20layout,=20style=20?= =?UTF-8?q?=E2=87=A2=20paint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/mapbox/mapbox-gl-style-spec/issues/166 --- include/mbgl/style/style_parser.hpp | 6 +++--- src/style/style_parser.cpp | 30 ++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/mbgl/style/style_parser.hpp b/include/mbgl/style/style_parser.hpp index a1c57cf2d..c37e85603 100644 --- a/include/mbgl/style/style_parser.hpp +++ b/include/mbgl/style/style_parser.hpp @@ -49,11 +49,11 @@ private: util::ptr createLayer(JSVal value); void parseLayers(); void parseLayer(std::pair> &pair); - void parseStyles(JSVal value, std::map &styles); - void parseStyle(JSVal, ClassProperties &properties); + void parsePaints(JSVal value, std::map &paints); + void parsePaint(JSVal, ClassProperties &properties); void parseReference(JSVal value, util::ptr &layer); void parseBucket(JSVal value, util::ptr &layer); - void parseRender(JSVal value, util::ptr &layer); + void parseLayout(JSVal value, util::ptr &layer); void parseSprite(JSVal value); void parseGlyphURL(JSVal value); diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 9f2307441..b32c36f17 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -485,12 +485,12 @@ util::ptr StyleParser::createLayer(JSVal value) { return nullptr; } - // Parse styles already, as they can't be inherited anyway. - std::map styles; - parseStyles(value, styles); + // Parse paints already, as they can't be inherited anyway. + std::map paints; + parsePaints(value, paints); util::ptr layer = std::make_shared( - layer_id, std::move(styles)); + layer_id, std::move(paints)); if (value.HasMember("layers")) { layer->layers = createLayers(value["layers"]); @@ -548,21 +548,21 @@ void StyleParser::parseLayer(std::pair> &pair) { #pragma mark - Parse Styles -void StyleParser::parseStyles(JSVal value, std::map &styles) { +void StyleParser::parsePaints(JSVal value, std::map &paints) { rapidjson::Value::ConstMemberIterator itr = value.MemberBegin(); for (; itr != value.MemberEnd(); ++itr) { const std::string name { itr->name.GetString(), itr->name.GetStringLength() }; - if (name == "style") { - parseStyle(replaceConstant(itr->value), styles[ClassID::Default]); - } else if (name.compare(0, 6, "style.") == 0 && name.length() > 6) { + if (name == "paint") { + parsePaint(replaceConstant(itr->value), paints[ClassID::Default]); + } else if (name.compare(0, 6, "paint.") == 0 && name.length() > 6) { const ClassID class_id = ClassDictionary::Get().lookup(name.substr(6)); - parseStyle(replaceConstant(itr->value), styles[class_id]); + parsePaint(replaceConstant(itr->value), paints[class_id]); } } } -void StyleParser::parseStyle(JSVal value, ClassProperties &klass) { +void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { using Key = PropertyKey; parseOptionalProperty>("fill-antialias", Key::FillAntialias, klass, value); @@ -714,9 +714,9 @@ void StyleParser::parseBucket(JSVal value, util::ptr &layer) { layer->bucket->filter = parseFilterExpression(value_filter); } - if (value.HasMember("render")) { - JSVal value_render = replaceConstant(value["render"]); - parseRender(value_render, layer); + if (value.HasMember("layout")) { + JSVal value_render = replaceConstant(value["layout"]); + parseLayout(value_render, layer); } if (value.HasMember("minzoom")) { @@ -738,9 +738,9 @@ void StyleParser::parseBucket(JSVal value, util::ptr &layer) { } } -void StyleParser::parseRender(JSVal value, util::ptr &layer) { +void StyleParser::parseLayout(JSVal value, util::ptr &layer) { if (!value.IsObject()) { - Log::Warning(Event::ParseStyle, "render property of layer '%s' must be an object", layer->id.c_str()); + Log::Warning(Event::ParseStyle, "layout property of layer '%s' must be an object", layer->id.c_str()); return; } From 0790b574b43322a0ea85e6ec6488b16dc74e11ce Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 3 Nov 2014 15:07:33 -0800 Subject: [PATCH 20/22] Single text positioning property https://github.com/mapbox/mapbox-gl-style-spec/issues/197 --- include/mbgl/style/style_bucket.hpp | 3 +-- include/mbgl/style/types.hpp | 28 +++++++++------------------- src/renderer/symbol_bucket.cpp | 26 +++++++++++++++++--------- src/style/style_parser.cpp | 3 +-- styles | 2 +- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/include/mbgl/style/style_bucket.hpp b/include/mbgl/style/style_bucket.hpp index c4a8f6037..d84d35d5b 100644 --- a/include/mbgl/style/style_bucket.hpp +++ b/include/mbgl/style/style_bucket.hpp @@ -64,8 +64,7 @@ public: float line_height = 1.2f * 24 /* em */; float letter_spacing = 0.0f * 24 /* em */; TextJustifyType justify = TextJustifyType::Center; - TextHorizontalAlignType horizontal_align = TextHorizontalAlignType::Center; - TextVerticalAlignType vertical_align = TextVerticalAlignType::Center; + TextAnchorType anchor = TextAnchorType::Center; float max_angle = 45.0f /* degrees */; float rotate = 0.0f; float slant = 0.0f; diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index fa21f819a..36cb39181 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -152,30 +152,20 @@ MBGL_DEFINE_ENUM_CLASS(TextJustifyTypeClass, TextJustifyType, { // ------------------------------------------------------------------------------------------------- -enum class TextHorizontalAlignType : uint8_t { +enum class TextAnchorType : uint8_t { + Center, Left, - Center, Right, -}; - -MBGL_DEFINE_ENUM_CLASS(TextHorizontalAlignTypeClass, TextHorizontalAlignType, { - { TextHorizontalAlignType::Left, "left" }, - { TextHorizontalAlignType::Center, "center" }, - { TextHorizontalAlignType::Right, "right" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class TextVerticalAlignType : uint8_t { Top, - Center, - Bottom, + Bottom }; -MBGL_DEFINE_ENUM_CLASS(TextVerticalAlignTypeClass, TextVerticalAlignType, { - { TextVerticalAlignType::Top, "top" }, - { TextVerticalAlignType::Center, "center" }, - { TextVerticalAlignType::Bottom, "bottom" }, +MBGL_DEFINE_ENUM_CLASS(TextAnchorTypeClass, TextAnchorType, { + { TextAnchorType::Center, "center" }, + { TextAnchorType::Left, "left" }, + { TextAnchorType::Right, "right" }, + { TextAnchorType::Top, "top" }, + { TextAnchorType::Bottom, "bottom" }, }); // ------------------------------------------------------------------------------------------------- diff --git a/src/renderer/symbol_bucket.cpp b/src/renderer/symbol_bucket.cpp index 37ff4a0a6..e80f1505b 100644 --- a/src/renderer/symbol_bucket.cpp +++ b/src/renderer/symbol_bucket.cpp @@ -103,16 +103,24 @@ void SymbolBucket::addFeatures(const VectorTileLayer &layer, const FilterExpress const std::vector features = processFeatures(layer, filter, glyphStore, sprite); float horizontalAlign = 0.5; - if (properties.text.horizontal_align == TextHorizontalAlignType::Right) - horizontalAlign = 1; - else if (properties.text.horizontal_align == TextHorizontalAlignType::Left) - horizontalAlign = 0; - float verticalAlign = 0.5; - if (properties.text.vertical_align == TextVerticalAlignType::Bottom) - verticalAlign = 1; - else if (properties.text.vertical_align == TextVerticalAlignType::Top) - verticalAlign = 0; + + switch (properties.text.anchor) { + case TextAnchorType::Center: + break; + case TextAnchorType::Right: + horizontalAlign = 1; + break; + case TextAnchorType::Left: + horizontalAlign = 0; + break; + case TextAnchorType::Bottom: + verticalAlign = 1; + break; + case TextAnchorType::Top: + verticalAlign = 0; + break; + } float justify = 0.5; if (properties.text.justify == TextJustifyType::Right) justify = 1; diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index b32c36f17..fa51e48ce 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -801,8 +801,7 @@ void StyleParser::parseLayout(JSVal value, util::ptr &layer) { render.text.letter_spacing *= 24; // em } parseRenderProperty(value, render.text.justify, "text-justify"); - parseRenderProperty(value, render.text.horizontal_align, "text-horizontal-align"); - parseRenderProperty(value, render.text.vertical_align, "text-vertical-align"); + parseRenderProperty(value, render.text.anchor, "text-anchor"); parseRenderProperty(value, render.text.max_angle, "text-max-angle"); parseRenderProperty(value, render.text.rotate, "text-rotate"); parseRenderProperty(value, render.text.slant, "text-slant"); diff --git a/styles b/styles index 65dc5c9b7..225f78f42 160000 --- a/styles +++ b/styles @@ -1 +1 @@ -Subproject commit 65dc5c9b7e926a7f43c2834979bd4c7395e8dcaf +Subproject commit 225f78f4281dbb315c030b1ba288e51193282cf7 From 051e1c32ae4f553085adfc7b66e005ef70f62349 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 4 Nov 2014 10:53:35 -0800 Subject: [PATCH 21/22] Support compound text-anchor values --- include/mbgl/style/types.hpp | 10 +++++++++- src/renderer/symbol_bucket.cpp | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 36cb39181..2f7ca7683 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -157,7 +157,11 @@ enum class TextAnchorType : uint8_t { Left, Right, Top, - Bottom + Bottom, + TopLeft, + TopRight, + BottomLeft, + BottomRight }; MBGL_DEFINE_ENUM_CLASS(TextAnchorTypeClass, TextAnchorType, { @@ -166,6 +170,10 @@ MBGL_DEFINE_ENUM_CLASS(TextAnchorTypeClass, TextAnchorType, { { TextAnchorType::Right, "right" }, { TextAnchorType::Top, "top" }, { TextAnchorType::Bottom, "bottom" }, + { TextAnchorType::TopLeft, "top-left" }, + { TextAnchorType::TopRight, "top-right" }, + { TextAnchorType::BottomLeft, "bottom-left" }, + { TextAnchorType::BottomRight, "bottom-right" } }); // ------------------------------------------------------------------------------------------------- diff --git a/src/renderer/symbol_bucket.cpp b/src/renderer/symbol_bucket.cpp index e80f1505b..a00544962 100644 --- a/src/renderer/symbol_bucket.cpp +++ b/src/renderer/symbol_bucket.cpp @@ -106,18 +106,35 @@ void SymbolBucket::addFeatures(const VectorTileLayer &layer, const FilterExpress float verticalAlign = 0.5; switch (properties.text.anchor) { + case TextAnchorType::Top: + case TextAnchorType::Bottom: case TextAnchorType::Center: break; case TextAnchorType::Right: + case TextAnchorType::TopRight: + case TextAnchorType::BottomRight: horizontalAlign = 1; break; case TextAnchorType::Left: + case TextAnchorType::TopLeft: + case TextAnchorType::BottomLeft: horizontalAlign = 0; break; + } + + switch (properties.text.anchor) { + case TextAnchorType::Left: + case TextAnchorType::Right: + case TextAnchorType::Center: + break; case TextAnchorType::Bottom: + case TextAnchorType::BottomLeft: + case TextAnchorType::BottomRight: verticalAlign = 1; break; case TextAnchorType::Top: + case TextAnchorType::TopLeft: + case TextAnchorType::TopRight: verticalAlign = 0; break; } From 51c32247fb18d5824f405dcaac65436128dc83e8 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 4 Nov 2014 12:27:14 -0800 Subject: [PATCH 22/22] Update test/suite --- test/headless.cpp | 5 +++++ test/suite | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/headless.cpp b/test/headless.cpp index 657bab4c3..38c3decd6 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -76,6 +76,11 @@ TEST_P(HeadlessTest, render) { std::string style = util::read_file(base_directory + "tests/" + base + "/style.json"); std::string info = util::read_file(base_directory + "tests/" + base + "/info.json"); + std::size_t pos = 0; + while ((pos = style.find("local://", pos)) != std::string::npos) { + style.replace(pos, 8, "http://localhost:2900/"); + } + // Parse style. rapidjson::Document styleDoc; styleDoc.Parse<0>((const char *const)style.c_str()); diff --git a/test/suite b/test/suite index 0f5f8f302..b94ae79bb 160000 --- a/test/suite +++ b/test/suite @@ -1 +1 @@ -Subproject commit 0f5f8f302202261c19810ea856fdcfb624989731 +Subproject commit b94ae79bb1e802b3c2d41792401192631d2be545