Skip to content

Commit 3a75075

Browse files
thedmdAnClark
authored andcommittedAug 30, 2021
ImDrawList: Fix AddCircle{Filled} with 12 segment case (ocornut#4419, ocornut#4421)
1 parent cef3540 commit 3a75075

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed
 

‎docs/CHANGELOG.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ Other Changes:
9292
- Fonts: Prefer using U+FFFD character for fallback instead of '?', if available. (#4269)
9393
- Fonts: Use U+FF0E dot character to construct an ellipsis if U+002E '.' is not available. (#4269)
9494
- Fonts: Add U+FFFD ("replacement character") to default asian glyphs ranges. (#4269)
95-
- Fonts: Fix calling ClearTexData() (clearing CPU side font data) triggering an assert in NewFrame(). (#3487)
95+
- Fonts: Fixed calling ClearTexData() (clearing CPU side font data) triggering an assert in NewFrame(). (#3487)
96+
- DrawList: Fixed AddCircle/AddCircleFilled() with auto-tesselation not using accelerated paths for small circles.
97+
Fixed AddCircle/AddCircleFilled() with 12 segments which had a broken edge. (#4419, #4421) [@thedmd]
9698
- Demo: Fixed requirement in 1.83 to link with imgui_demo.cpp if IMGUI_DISABLE_METRICS_WINDOW is not set. (#4171)
9799
Normally the right way to disable compiling the demo is to set IMGUI_DISABLE_DEMO_WINDOWS, but we want to avoid
98100
implying that the file is required.

‎imgui_draw.cpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -1479,24 +1479,22 @@ void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int nu
14791479
if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f)
14801480
return;
14811481

1482-
// Obtain segment count
14831482
if (num_segments <= 0)
14841483
{
1485-
// Automatic segment count
1486-
num_segments = _CalcCircleAutoSegmentCount(radius);
1484+
// Use arc with automatic segment count
1485+
_PathArcToFastEx(center, radius - 0.5f, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
1486+
_Path.Size--;
14871487
}
14881488
else
14891489
{
14901490
// Explicit segment count (still clamp to avoid drawing insanely tessellated shapes)
14911491
num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX);
1492-
}
14931492

1494-
// Because we are filling a closed shape we remove 1 from the count of segments/points
1495-
const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
1496-
if (num_segments == 12)
1497-
PathArcToFast(center, radius - 0.5f, 0, 12 - 1);
1498-
else
1493+
// Because we are filling a closed shape we remove 1 from the count of segments/points
1494+
const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
14991495
PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1);
1496+
}
1497+
15001498
PathStroke(col, ImDrawFlags_Closed, thickness);
15011499
}
15021500

@@ -1505,24 +1503,22 @@ void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col,
15051503
if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f)
15061504
return;
15071505

1508-
// Obtain segment count
15091506
if (num_segments <= 0)
15101507
{
1511-
// Automatic segment count
1512-
num_segments = _CalcCircleAutoSegmentCount(radius);
1508+
// Use arc with automatic segment count
1509+
_PathArcToFastEx(center, radius, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
1510+
_Path.Size--;
15131511
}
15141512
else
15151513
{
15161514
// Explicit segment count (still clamp to avoid drawing insanely tessellated shapes)
15171515
num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX);
1518-
}
15191516

1520-
// Because we are filling a closed shape we remove 1 from the count of segments/points
1521-
const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
1522-
if (num_segments == 12)
1523-
PathArcToFast(center, radius, 0, 12 - 1);
1524-
else
1517+
// Because we are filling a closed shape we remove 1 from the count of segments/points
1518+
const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
15251519
PathArcTo(center, radius, 0.0f, a_max, num_segments - 1);
1520+
}
1521+
15261522
PathFillConvex(col);
15271523
}
15281524

0 commit comments

Comments
 (0)
Please sign in to comment.