From 4f827c21c62e9059cdfc108d2275ec99f639566c Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 14 Jan 2015 22:56:44 -0500 Subject: [PATCH] implement round dash caps --- src/mbgl/geometry/line_atlas.cpp | 10 +++++----- src/mbgl/renderer/painter_line.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index ae5617bf3..45fcde99d 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -27,7 +27,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector &dasharray, b std::string key = sskey.str(); if (positions.find(key) == positions.end()) { - fprintf(stderr, "add %s\n", key.c_str()); + //fprintf(stderr, "add %s\n", key.c_str()); positions[key] = addDash(dasharray, round); } @@ -73,12 +73,12 @@ LinePatternPos LineAtlas::addDash(const std::vector &dasharray, bool roun int signedDistance; if (round) { - float distMiddle = n ? y / n * halfWidth : 0; - float distEdge = halfWidth - fabs(distMiddle); + float distMiddle = n ? (float)y / n * (halfWidth + 1) : 0; if (inside) { + float distEdge = halfWidth - fabs(distMiddle); signedDistance = sqrt(dist * dist + distEdge * distEdge); } else { - signedDistance = halfWidth = sqrt(dist * dist + distMiddle * distMiddle); + signedDistance = halfWidth - sqrt(dist * dist + distMiddle * distMiddle); } } else { @@ -91,7 +91,7 @@ LinePatternPos LineAtlas::addDash(const std::vector &dasharray, bool roun LinePatternPos position; position.y = (0.5 + nextRow + n) / height; - position.height = 2 * n / height; + position.height = (2.0 * n) / height; position.width = length; nextRow += dashheight; diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 0aadd9219..2d57bb26e 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -81,7 +81,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c linesdfShader->u_blur = blur; linesdfShader->u_color = color; - LinePatternPos pos = lineAtlas.getDashPosition(properties.dash_array, false); + LinePatternPos pos = lineAtlas.getDashPosition(properties.dash_array, bucket.properties.cap == CapType::Round); lineAtlas.bind(); float patternratio = std::pow(2.0, std::floor(std::log2(state.getScale())) - id.z) / 8.0;