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

AddCircleFilled draws an irregular polygon instead of a regular one #2287

Closed
baktery opened this issue Jan 16, 2019 · 1 comment
Closed

AddCircleFilled draws an irregular polygon instead of a regular one #2287

baktery opened this issue Jan 16, 2019 · 1 comment

Comments

@baktery
Copy link

baktery commented Jan 16, 2019

Version/Branch of Dear ImGui:

Version: 1.6WIP
Branch: https://github.com/google/filament/tree/master/third_party/imgui

My Issue/Question:

Drawing a circle with ImDrawList::AddCircleFilled() I noticed that the size of all the segments were not the same.

For example, you can try to draw an hexagon (6 segments) and you will see an irregular polygon instead of a regular hexagon.

Standalone, minimal, complete and verifiable example:

This is the original function:

void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
{
    if ((col & IM_COL32_A_MASK) == 0)
        return;

	const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
	PathArcTo(centre, radius, 0.0f, a_max, num_segments);
    PathFillConvex(col);
}

PathActTo() is not called with the proper number of segments. This a fixed version:

void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
{
    if ((col & IM_COL32_A_MASK) == 0)
        return;

	const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
	PathArcTo(centre, radius, 0.0f, a_max, num_segments-1);
    PathFillConvex(col);
}

It seems like AddCicle() function also has the same issue.

@ocornut
Copy link
Owner

ocornut commented Jan 16, 2019

Thank you @baktery, I verified this and pushed a fix.
Even though PathArcTo() is correct as it is, it can be misleading when used for a full closed shape. so I added a few comments around those functions and the circle function.

Also added an hexagon in the demo:
image

ocornut added a commit that referenced this issue Jan 16, 2019
…, which was visible when drawing a "circle" with a small number of segments (e.g. an hexagon). (#2287) [@baktery]

+ Demo tweaks
@ocornut ocornut closed this as completed Jan 16, 2019
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

2 participants