Skip to content

Commit

Permalink
fix zero-width line rendering (mapbox#6772)
Browse files Browse the repository at this point in the history
* fix zero-width line rendering

* fix other line types too:
  • Loading branch information
mollymerp authored and pirxpilot committed Jun 18, 2019
1 parent d6d7a6d commit f3268a9
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/render/draw_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = function drawLine(painter, sourceCache, layer, coords) {
if (painter.renderPass !== 'translucent') return;

const opacity = layer.paint.get('line-opacity');
if (opacity.constantOr(1) === 0) return;
const width = layer.paint.get('line-width');
if (opacity.constantOr(1) === 0 || width.constantOr(1) === 0) return;

const context = painter.context;

Expand Down
2 changes: 1 addition & 1 deletion src/shaders/line.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void main() {
offset = -1.0 * offset;

float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING);

// Scale the extrusion vector down to a normal and then up by the line width
// of this vertex.
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/line_gradient.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void main() {
offset = -1.0 * offset;

float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING);

// Scale the extrusion vector down to a normal and then up by the line width
// of this vertex.
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/line_pattern.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void main() {
offset = -1.0 * offset;

float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING);

// Scale the extrusion vector down to a normal and then up by the line width
// of this vertex.
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/line_sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void main() {
offset = -1.0 * offset;

float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING;
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING);

// Scale the extrusion vector down to a normal and then up by the line width
// of this vertex.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"version": 8,
"metadata": {
"test": {
"width": 100,
"height": 100,
"diff": 0.00075
}
},
"zoom": 2,
"sources": {
"linesource": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {
"width": 0
},
"geometry": {
"type": "LineString",
"coordinates": [
[
-1,
8
],
[
8,
1
],
[
1,
-8
],
[
-8,
-1
],
[
1,
4
],
[
4,
-1
],
[
-1,
-4
],
[
-2,
0
]
]
}
},
"lineMetrics": true
}
},
"layers": [
{
"id": "line",
"type": "line",
"source": "linesource",
"layout": {
"line-cap": "round",
"line-join": "round"
},
"paint": {
"line-width": ["get", "width"],
"line-color": "red"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions test/integration/render-tests/line-width/zero-width/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"version": 8,
"metadata": {
"test": {
"width": 100,
"height": 100,
"diff": 0.00075
}
},
"zoom": 2,
"sources": {
"linesource": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
-1,
8
],
[
8,
1
],
[
1,
-8
],
[
-8,
-1
],
[
1,
4
],
[
4,
-1
],
[
-1,
-4
],
[
-2,
0
]
]
}
},
"lineMetrics": true
}
},
"layers": [
{
"id": "line",
"type": "line",
"source": "linesource",
"layout": {
"line-cap": "round",
"line-join": "round"
},
"paint": {
"line-width": 0,
"line-color": "red"
}
}
]
}

0 comments on commit f3268a9

Please sign in to comment.