Skip to content

Commit

Permalink
fix "line-dasharray" with "line-cap": "square"
Browse files Browse the repository at this point in the history
fix #9531
  • Loading branch information
ansis committed Apr 13, 2020
1 parent d9696a0 commit a48df69
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/render/line_atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class LineAtlas {
* @returns {Object} position of dash texture in { y, height, width }
* @private
*/
getDash(dasharray: Array<number>, round: boolean) {
const key = dasharray.join(",") + String(round);
getDash(dasharray: Array<number>, lineCap: string) {
const key = dasharray.join(",") + lineCap;

if (!this.dashEntry[key]) {
this.dashEntry[key] = this.addDash(dasharray, round);
this.dashEntry[key] = this.addDash(dasharray, lineCap);
}
return this.dashEntry[key];
}
Expand Down Expand Up @@ -108,7 +108,7 @@ class LineAtlas {
}
}

addRegularDash(ranges: Object) {
addRegularDash(ranges: Object, capLength: number) {

// Collapse any zero-length range
// Collapse neighbouring same-type parts into a single part
Expand Down Expand Up @@ -144,13 +144,14 @@ class LineAtlas {
const distRight = Math.abs(x - range.right);

const minDist = Math.min(distLeft, distRight);
const signedDistance = range.isDash ? minDist : -minDist;
const signedDistance = (range.isDash ? minDist : -minDist) + capLength;

this.data[index + x] = Math.max(0, Math.min(255, signedDistance + 128));
}
}

addDash(dasharray: Array<number>, round: boolean) {
addDash(dasharray: Array<number>, lineCap: string) {
const round = lineCap === 'round';
const n = round ? 7 : 0;
const height = 2 * n + 1;

Expand All @@ -169,7 +170,8 @@ class LineAtlas {
if (round) {
this.addRoundDash(ranges, stretch, n);
} else {
this.addRegularDash(ranges);
const capLength = lineCap === 'square' ? 0.5 * stretch : 0;
this.addRegularDash(ranges, capLength);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/render/program/line_program.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ const lineSDFUniformValues = (
const lineAtlas = painter.lineAtlas;
const tileRatio = calculateTileRatio(tile, transform);

const round = layer.layout.get('line-cap') === 'round';
const lineCap = layer.layout.get('line-cap');

const posA = lineAtlas.getDash(dasharray.from, round);
const posB = lineAtlas.getDash(dasharray.to, round);
const posA = lineAtlas.getDash(dasharray.from, lineCap);
const posB = lineAtlas.getDash(dasharray.to, lineCap);

const widthA = posA.width * crossfade.fromScale;
const widthB = posB.width * crossfade.toScale;
Expand Down
1 change: 0 additions & 1 deletion test/ignores.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"query-tests/regressions/mapbox-gl-js#4494": "https://github.com/mapbox/mapbox-gl-js/issues/2716",
"render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary",
"render-tests/line-dasharray/case/square": "https://github.com/mapbox/mapbox-gl-js/issues/9531",
"render-tests/map-mode/static": "https://github.com/mapbox/mapbox-gl-js/issues/5649",
"render-tests/map-mode/tile": "skip - mapbox-gl-js does not support tile-mode",
"render-tests/map-mode/tile-avoid-edges": "skip - mapbox-gl-js does not support tile-mode",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a48df69

Please sign in to comment.