diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-09-06 14:38:49 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-09-07 17:56:38 +0200 |
commit | 3d960c8136541f1f6d71409e23b8f56eee9dd1d0 (patch) | |
tree | c51dfbc628232ba37db5d37a954dfca9e22449d6 /src/mbgl/geometry | |
parent | 85e222c8258654c5b75860d086d169fe998c8f63 (diff) | |
download | qtlocation-mapboxgl-3d960c8136541f1f6d71409e23b8f56eee9dd1d0.tar.gz |
[core] change bool round to LinePatternCap
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r-- | src/mbgl/geometry/line_atlas.cpp | 14 | ||||
-rw-r--r-- | src/mbgl/geometry/line_atlas.hpp | 9 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index f08ea1e5fc..bc81c38f53 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -21,8 +21,10 @@ LineAtlas::LineAtlas(GLsizei w, GLsizei h) LineAtlas::~LineAtlas() = default; -LinePatternPos LineAtlas::getDashPosition(const std::vector<float>& dasharray, bool round) { - size_t key = round ? std::numeric_limits<size_t>::min() : std::numeric_limits<size_t>::max(); +LinePatternPos LineAtlas::getDashPosition(const std::vector<float>& dasharray, + LinePatternCap patternCap) { + size_t key = patternCap == LinePatternCap::Round ? std::numeric_limits<size_t>::min() + : std::numeric_limits<size_t>::max(); for (const float part : dasharray) { boost::hash_combine<float>(key, part); } @@ -30,7 +32,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector<float>& dasharray, b // Note: We're not handling hash collisions here. const auto it = positions.find(key); if (it == positions.end()) { - auto inserted = positions.emplace(key, addDash(dasharray, round)); + auto inserted = positions.emplace(key, addDash(dasharray, patternCap)); assert(inserted.second); return inserted.first->second; } else { @@ -38,8 +40,8 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector<float>& dasharray, b } } -LinePatternPos LineAtlas::addDash(const std::vector<float>& dasharray, bool round) { - int n = round ? 7 : 0; +LinePatternPos LineAtlas::addDash(const std::vector<float>& dasharray, LinePatternCap patternCap) { + int n = patternCap == LinePatternCap::Round ? 7 : 0; int dashheight = 2 * n + 1; const uint8_t offset = 128; @@ -90,7 +92,7 @@ LinePatternPos LineAtlas::addDash(const std::vector<float>& dasharray, bool roun bool inside = (partIndex % 2) == 1; int signedDistance; - if (round) { + if (patternCap == LinePatternCap::Round) { float distMiddle = n ? (float)y / n * (halfWidth + 1) : 0; if (inside) { float distEdge = halfWidth - fabs(distMiddle); diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index 1e6c0ac84e..a2bda71863 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -19,6 +19,11 @@ typedef struct { float y; } LinePatternPos; +enum class LinePatternCap : bool { + Square = false, + Round = true, +}; + class LineAtlas { public: LineAtlas(GLsizei width, GLsizei height); @@ -31,8 +36,8 @@ public: // the texture is only bound when the data is out of date (=dirty). void upload(gl::ObjectStore&, gl::Config&, uint32_t unit); - LinePatternPos getDashPosition(const std::vector<float>&, bool); - LinePatternPos addDash(const std::vector<float>& dasharray, bool round); + LinePatternPos getDashPosition(const std::vector<float>&, LinePatternCap); + LinePatternPos addDash(const std::vector<float>& dasharray, LinePatternCap); const GLsizei width; const GLsizei height; |