ImDrawList: Fix AddCircle{Filled} with 12 segment case (#4419, #4421)

This commit is contained in:
thedmd 2021-08-11 13:21:27 +02:00 committed by ocornut
parent e3988a84db
commit cb00972b87
2 changed files with 17 additions and 19 deletions

View File

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

View File

@ -1479,24 +1479,22 @@ void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int nu
if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f) if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f)
return; return;
// Obtain segment count
if (num_segments <= 0) if (num_segments <= 0)
{ {
// Automatic segment count // Use arc with automatic segment count
num_segments = _CalcCircleAutoSegmentCount(radius); _PathArcToFastEx(center, radius - 0.5f, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
_Path.Size--;
} }
else else
{ {
// Explicit segment count (still clamp to avoid drawing insanely tessellated shapes) // Explicit segment count (still clamp to avoid drawing insanely tessellated shapes)
num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX); num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX);
}
// Because we are filling a closed shape we remove 1 from the count of segments/points // Because we are filling a closed shape we remove 1 from the count of segments/points
const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
if (num_segments == 12)
PathArcToFast(center, radius - 0.5f, 0, 12 - 1);
else
PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1); PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1);
}
PathStroke(col, ImDrawFlags_Closed, thickness); PathStroke(col, ImDrawFlags_Closed, thickness);
} }
@ -1505,24 +1503,22 @@ void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col,
if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f) if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f)
return; return;
// Obtain segment count
if (num_segments <= 0) if (num_segments <= 0)
{ {
// Automatic segment count // Use arc with automatic segment count
num_segments = _CalcCircleAutoSegmentCount(radius); _PathArcToFastEx(center, radius, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
_Path.Size--;
} }
else else
{ {
// Explicit segment count (still clamp to avoid drawing insanely tessellated shapes) // Explicit segment count (still clamp to avoid drawing insanely tessellated shapes)
num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX); num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX);
}
// Because we are filling a closed shape we remove 1 from the count of segments/points // Because we are filling a closed shape we remove 1 from the count of segments/points
const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
if (num_segments == 12)
PathArcToFast(center, radius, 0, 12 - 1);
else
PathArcTo(center, radius, 0.0f, a_max, num_segments - 1); PathArcTo(center, radius, 0.0f, a_max, num_segments - 1);
}
PathFillConvex(col); PathFillConvex(col);
} }