diff options
author | zmiao <zmiao.jamie@gmail.com> | 2019-08-26 16:30:35 +0300 |
---|---|---|
committer | zmiao <zmiao.jamie@gmail.com> | 2019-08-26 16:30:35 +0300 |
commit | 61faf2b15bacd22e154eadb115501c6c4579ff65 (patch) | |
tree | 987ed4f4f11c4a73d336a2580f0d79a8949e9787 | |
parent | e1047757c7130c1899f48dd36534daa0ffac3c72 (diff) | |
download | qtlocation-mapboxgl-61faf2b15bacd22e154eadb115501c6c4579ff65.tar.gz |
provide bitwise operator for SymbolContent enum
-rw-r--r-- | src/mbgl/layout/symbol_instance.cpp | 14 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_instance.hpp | 20 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_layout.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_layout.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/buckets/symbol_bucket.cpp | 7 |
5 files changed, 27 insertions, 18 deletions
diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp index 98f546325a..ad36e6c38c 100644 --- a/src/mbgl/layout/symbol_instance.cpp +++ b/src/mbgl/layout/symbol_instance.cpp @@ -89,10 +89,10 @@ SymbolInstance::SymbolInstance(Anchor& anchor_, const float textRotation, float radialTextOffset_, bool allowVerticalPlacement, - const SymbolContent& iconType) : + const SymbolContent iconType) : sharedData(std::move(sharedData_)), anchor(anchor_), - symbolContent(static_cast<uint8_t>(iconType)), + symbolContent(iconType), // Create the collision features that will be used to check whether this symbol instance can be placed // As a collision approximation, we can use either the vertical or any of the horizontal versions of the feature textCollisionFeature(sharedData->line, anchor, getAnyShaping(shapedTextOrientations), textBoxScale_, textPadding, textPlacement, indexedFeature, overscaling, textRotation), @@ -106,8 +106,8 @@ SymbolInstance::SymbolInstance(Anchor& anchor_, textBoxScale(textBoxScale_), radialTextOffset(radialTextOffset_), singleLine(shapedTextOrientations.singleLine) { - // 'hasText' depends on finding at least one glyph in the shaping that's also in the GlyphPositionMap - if(!sharedData->empty()) symbolContent |= static_cast<uint8_t>(SymbolContent::Text); + // 'hasText' depends on finding at least one glyph in the shaping that's also in the GlyphPositionMap + if(!sharedData->empty()) symbolContent |= SymbolContent::Text; if (allowVerticalPlacement && shapedTextOrientations.vertical) { const float verticalPointLabelAngle = 90.0f; verticalTextCollisionFeature = CollisionFeature(line(), anchor, shapedTextOrientations.vertical, textBoxScale_, textPadding, textPlacement, indexedFeature, overscaling, textRotation + verticalPointLabelAngle); @@ -166,15 +166,15 @@ const optional<SymbolQuad>& SymbolInstance::iconQuad() const { } bool SymbolInstance::hasText() const { - return symbolContent & static_cast<uint8_t>(SymbolContent::Text); + return static_cast<bool>(symbolContent & SymbolContent::Text); } bool SymbolInstance::hasIcon() const { - return (symbolContent & static_cast<uint8_t>(SymbolContent::IconRGBA)) || hasSdfIcon(); + return static_cast<bool>(symbolContent & SymbolContent::IconRGBA) || hasSdfIcon(); } bool SymbolInstance::hasSdfIcon() const { - return symbolContent & static_cast<uint8_t>(SymbolContent::IconSDF); + return static_cast<bool>(symbolContent & SymbolContent::IconSDF); } const optional<SymbolQuad>& SymbolInstance::verticalIconQuad() const { diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp index 01e40c1970..2471ddc40d 100644 --- a/src/mbgl/layout/symbol_instance.hpp +++ b/src/mbgl/layout/symbol_instance.hpp @@ -4,7 +4,7 @@ #include <mbgl/text/glyph_atlas.hpp> #include <mbgl/text/collision_feature.hpp> #include <mbgl/style/layers/symbol_layer_properties.hpp> - +#include <mbgl/util/traits.hpp> namespace mbgl { @@ -45,10 +45,22 @@ struct SymbolInstanceSharedData { enum class SymbolContent : uint8_t { None = 0, Text = 1 << 0, - IconRGBA= 1 << 1, + IconRGBA = 1 << 1, IconSDF = 1 << 2 }; +constexpr SymbolContent operator|(SymbolContent a, SymbolContent b) { + return SymbolContent(mbgl::underlying_type(a) | mbgl::underlying_type(b)); +} + +constexpr SymbolContent& operator|=(SymbolContent& a, SymbolContent b) { + return (a = a | b); +} + +constexpr SymbolContent operator&(SymbolContent a, SymbolContent b) { + return SymbolContent(mbgl::underlying_type(a) & mbgl::underlying_type(b)); +} + class SymbolInstance { public: SymbolInstance(Anchor& anchor_, @@ -72,7 +84,7 @@ public: const float textRotation, float radialTextOffset, bool allowVerticalPlacement, - const SymbolContent& iconType = SymbolContent::None); + const SymbolContent iconType = SymbolContent::None); optional<size_t> getDefaultHorizontalPlacedTextIndex() const; const GeometryCoordinates& line() const; @@ -92,7 +104,7 @@ private: public: Anchor anchor; - uint8_t symbolContent; + SymbolContent symbolContent; std::size_t rightJustifiedGlyphQuadsSize; std::size_t centerJustifiedGlyphQuadsSize; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index f77703e1f4..fe169785ce 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -436,7 +436,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex, optional<PositionedIcon> shapedIcon, const GlyphPositions& glyphPositions, Point<float> offset, - const SymbolContent& iconType) { + const SymbolContent iconType) { const float minScale = 0.5f; const float glyphSize = 24.0f; diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index d7daafc4c6..8d4c51148a 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -54,7 +54,7 @@ private: optional<PositionedIcon> shapedIcon, const GlyphPositions&, Point<float> textOffset, - const SymbolContent& iconType); + const SymbolContent iconType); bool anchorIsTooClose(const std::u16string& text, const float repeatDistance, const Anchor&); std::map<std::u16string, std::vector<Anchor>> compareText; diff --git a/src/mbgl/renderer/buckets/symbol_bucket.cpp b/src/mbgl/renderer/buckets/symbol_bucket.cpp index b2f469927c..a46c25a13b 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.cpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.cpp @@ -237,14 +237,11 @@ void SymbolBucket::sortFeatures(const float angle) { auto& iconBuffer = symbolInstance.hasSdfIcon() ? sdfIcon : icon; if (symbolInstance.placedIconIndex) { - addPlacedSymbol(iconBuffer.triangles, - iconBuffer.placedSymbols[*symbolInstance.placedIconIndex]); + addPlacedSymbol(iconBuffer.triangles, iconBuffer.placedSymbols[*symbolInstance.placedIconIndex]); } if (symbolInstance.placedVerticalIconIndex) { - addPlacedSymbol(iconBuffer.triangles, - iconBuffer.placedSymbols[*symbolInstance.placedVerticalIconIndex]); - + addPlacedSymbol(iconBuffer.triangles, iconBuffer.placedSymbols[*symbolInstance.placedVerticalIconIndex]); } } } |