Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dashed lines with square line caps #9561

Merged
merged 2 commits into from
May 6, 2021
Merged

fix dashed lines with square line caps #9561

merged 2 commits into from
May 6, 2021

Conversation

ansis
Copy link
Contributor

@ansis ansis commented Apr 14, 2020

fix #9531

"line-dasharray": ...,
"line-cap": "square"

This adds square caps to each dash (matching what svg does). It does this by making every pixel within the sdf 0.5 line widths closer to the edge of the dashed line. It also makes the square cap of the line it's own quad to avoid stretching the distance-along-the line which would make coincident dashed lines not line up properly.

Before:

After:
square

Launch Checklist

  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • write tests for all new functionality
  • [n/a] document any changes to public APIs
  • [n/a] post benchmark scores
  • manually test the debug page
  • tagged @mapbox/map-design-team @mapbox/static-apis if this PR includes style spec API or visual changes
  • tagged @mapbox/gl-native if this PR includes shader changes or needs a native port
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Fix dashed lines with square line caps.</changelog>

@mapbox/map-design-team this PR includes visual changes for dashed lines with square line caps. Do you think any styles need to be adjusted or would this combination be uncommon enough to not affect much? @mapbox/static-apis I'm not sure whether these visual changes would affect you in any way.

@tmpsantos this needs a -native port

@ansis
Copy link
Contributor Author

ansis commented Apr 15, 2020

There are two more things I need to look into:

  • how the extra vertices for square line caps affect line-pattern
  • how this looks when the antialiasing of the dash edge aligns exactly on the end of the line. I think it might make the entire square cap translucent

The square cap of each line is rendered as it’s own pair of triangles after these changes. Each pixel within the square cap has the same “distance along the line” value. When the line’s end vertex is within a dash it renders solid. When it’s in a gap it’s transparent. That’s all the way it should be. But when the “distance along the line” for the end vertex is right on the edge of a dash it’ll think it needs to antialias that pixel and will render the entire cap semi-transparent

Copy link
Contributor

@tmpsantos tmpsantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ansis ansis marked this pull request as draft May 20, 2020 17:18
@arindam1993 arindam1993 changed the base branch from master to main June 18, 2020 18:13
@mourner
Copy link
Member

mourner commented Dec 10, 2020

@ansis should we revisit landing this?

@mourner
Copy link
Member

mourner commented May 4, 2021

Rebased against data-driven dashes #10591 in fix-9531-rebase branch.

@mourner mourner marked this pull request as ready for review May 6, 2021 10:00
@mourner mourner merged commit 7ca8f72 into main May 6, 2021
@mourner mourner deleted the fix-9531 branch May 6, 2021 10:08
@karimnaaji karimnaaji added this to the v2.3 milestone May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

line-dasharray with square line cap not rendering correctly
4 participants