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

Improved algorithm for mitre joints on thick lines #2518

Closed
wants to merge 1 commit into from

Conversation

rmitton
Copy link
Contributor

@rmitton rmitton commented Apr 27, 2019

The current implementation for rendering thick lines suffers from issues when the lines meet at extreme angles. A 90-degree bend will cause the thickness of the line to contract by around 30%. In the case of a rectangle, this causes the entire rectangle to be the wrong thickness:

lines_before

I've modified the algorithm to counteract this effect by placing the mitre vertices at a distance that preserves the correct thickness. The new algorithm works for vertices up to 90-degrees; past that, it would be impossible to fix without actually inserting new vertices. Seeing as rectangles are by far the most common UI element, this seems an acceptable compromise.

lines_after

@ocornut
Copy link
Owner

ocornut commented Apr 28, 2019

Thank you Richard, will look into it soon.
Linking to #2183 and the old unmerged #288 for non-AA path.

ocornut added a commit that referenced this pull request Apr 29, 2019
@ocornut
Copy link
Owner

ocornut commented Apr 29, 2019

Merged this now, thank you!

I've modified the algorithm to counteract this effect by placing the mitre vertices at a distance that preserves the correct thickness. The new algorithm works for vertices up to 90-degrees; past that, it would be impossible to fix without actually inserting new vertices.

It would be interesting to see what it would take to make this modification.
In particular, triangles are very much affected (see #2183) and perhaps it would make sense to have some sort of specialization for them if a general solution is too costly.

Logs from rough perf measurement system (not very precise!)

Before, Debug, x12
,perf,perf_draw_prim_rect_stroke,3.454,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_stroke_thick,3.707,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_filled,0.806,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_stroke,9.762,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_stroke_thick,10.144,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_filled,8.837,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_stroke,9.732,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_stroke_thick,10.113,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_filled,9.309,,12,Debug,X86,Windows,MSVC,2019-04-29

After, Debug, x12
,perf,perf_draw_prim_rect_stroke,2.924,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_stroke_thick,3.143,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_filled,0.911,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_stroke,8.757,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_stroke_thick,9.455,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_filled,7.999,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_stroke,9.873,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_stroke_thick,10.422,,12,Debug,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_filled,9.682,,12,Debug,X86,Windows,MSVC,2019-04-29

Before, Release x12
,perf,perf_draw_prim_rect_stroke,0.495,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_stroke_thick,0.642,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_filled,1.170,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_stroke,2.040,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_stroke_thick,2.561,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_filled,1.673,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_stroke,2.684,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_stroke_thick,3.028,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_filled,2.431,,12,Release,X86,Windows,MSVC,2019-04-29

After, Release x12
,perf,perf_draw_prim_rect_stroke,0.474,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_stroke_thick,0.609,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_filled,1.176,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_stroke,1.919,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_stroke_thick,2.470,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_rect_rounded_filled,1.562,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_stroke,2.715,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_stroke_thick,3.104,,12,Release,X86,Windows,MSVC,2019-04-29
,perf,perf_draw_prim_circle_filled,2.432,,12,Release,X86,Windows,MSVC,2019-04-29

@ocornut
Copy link
Owner

ocornut commented Apr 19, 2021

An update on this can be found here:
#4053 (comment)

(TL;DR; this PR did partially fix an earlier regression from Jan 2019 but we somehow still carried part of that regression even after April 2019)

ocornut added a commit that referenced this pull request Apr 19, 2021
…ioritize preserving property of limiting extents. (#4053, #3366, #2964, #2868, #2518, #2183)

Amend fdda8b8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants