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

Inconsistent width of PathArcTo strokes #4993

Closed
pixtur opened this issue Feb 7, 2022 · 3 comments
Closed

Inconsistent width of PathArcTo strokes #4993

pixtur opened this issue Feb 7, 2022 · 3 comments

Comments

@pixtur
Copy link

pixtur commented Feb 7, 2022

Version/Branch of Dear ImGui:

Version: 1.83
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends imgui .net
Operating System: windows 10

My Issue/Question:
After upgrading from 1.77 to 1.86 there seem to appear rendering glitches for paths that include PathArcTo() with a small radius.

It's not unlikely that I'm not using the API correctly. But the effect only appeared recently and might be a regression of some optimization.

Screenshots/Video
As screenshot highlighting some issues.
Frame 23

Here is a capture of the code below...
https://user-images.githubusercontent.com/1732545/152852430-57253e47-46aa-4239-bcd4-939993eb1bef.mp4

Standalone, minimal, complete and verifiable example: (see #2261)

Sorry. c# only... 🙈

        private void DrawTest()
        {
            if (ImGui.Begin("test"))
            {
                ImGui.DragFloat("radius", ref _testRadius, 0.1f);
                ImGui.DragFloat("thickness", ref _thickness, 1f);
                
                const float Pi = 3.141592f;
                var drawList = ImGui.GetWindowDrawList();

                var center = new Vector2(300, 400);
                var max = 100;
                
                for (float i = _testRadius; i < max; i += 20)
                {
                    var radius = 10 + i;
                    drawList.PathClear();
                    drawList.PathArcTo(center + new Vector2(0, -100), max- radius,  1.5f * Pi,Pi );
                    drawList.PathArcTo(center + new Vector2(-max,10), radius, 0, Pi * 0.5f);
                    drawList.PathLineTo( center + new Vector2(-max - 100,10 + radius) );
                    
                    drawList.AddPolyline(ref drawList._Path[0], drawList._Path.Size, Color.White, ImDrawFlags.None, _thickness + 2);
                    drawList.PathStroke(Color.DarkGray, ImDrawFlags.None, _thickness);
                }

                ImGui.End();
            }
        }
@thedmd
Copy link
Contributor

thedmd commented Feb 8, 2022

I got it fixed in 775b9e4.

image

Translated example:

        if (ImGui::Begin("test"))
        {
            static float _testRadius = 1.0f;
            static float _thickness = 1.0f;

            ImGui::DragFloat("radius", &_testRadius, 0.1f);
            ImGui::DragFloat("thickness", &_thickness, 1.0f);

            const float Pi = 3.141592f;
            auto drawList = ImGui::GetWindowDrawList();

            auto center = ImVec2(300, 400) + ImGui::GetCursorScreenPos();
            auto max = 100;

            //_testRadius = max - 20;

            for (float i = _testRadius; i < max; i += 20)
            {
                auto radius = 10 + i;
                drawList->PathClear();
                drawList->PathArcTo(center + ImVec2(0, -100), max - radius, 1.5f * Pi, Pi);
                drawList->PathArcTo(center + ImVec2(-max, 10), radius, 0, Pi * 0.5f);
                drawList->PathLineTo(center + ImVec2(-max - 100, 10 + radius));

                drawList->AddPolyline(drawList->_Path.Data, drawList->_Path.Size, IM_COL32_WHITE, ImDrawFlags_None, _thickness + 2.0);
                drawList->PathStroke(IM_COL32(169, 169, 169, 255), ImDrawFlags_None, _thickness);
            }

            ImGui::End();
        }

@pixtur
Copy link
Author

pixtur commented Feb 8, 2022

Wow! That's incredible.

One more thing... I noticed that ImGui.net v1.84 can cause division/0 exceptions for PathArcTo() and DrawCicle() when called with small radii (e.g. 1e-7). I'm not sure if this is related do your fix. But these exceptions seem to be introduced the same time, as the drawing glitches.

@ocornut
Copy link
Owner

ocornut commented Feb 8, 2022

Merged @thedmd fix as 4691fa0

Thank you very much !

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

No branches or pull requests

3 participants