Skip to content

Feat: PlotPolygon#673

Merged
brenocq merged 5 commits intomasterfrom
feat/polygon
Mar 7, 2026
Merged

Feat: PlotPolygon#673
brenocq merged 5 commits intomasterfrom
feat/polygon

Conversation

@brenocq
Copy link
Copy Markdown
Collaborator

@brenocq brenocq commented Feb 14, 2026

Closes #631

This PR introduces PlotPolygon as requested by #631.

// Flags for PlotPolygon. Used by setting ImPlotSpec::Flags.
enum ImPlotPolygonFlags_ {
  ImPlotPolygonFlags_None     = 0,       // default (closed, convex polygon)
  ImPlotPolygonFlags_Concave  = 1 << 10, // use concave polygon filling (slower but supports concave shapes)
};

// Plots a polygon. Points are specified as separate x and y arrays. Supports both convex and concave polygons.
IMPLOT_TMP void PlotPolygon(const char* label_id, const T* xs, const T* ys, int count, const ImPlotSpec& spec=ImPlotSpec());

Usage

...
if (ImPlot::BeginPlot("Polygon Plot", ImVec2(-1,0), ImPlotFlags_Equal)) {
    ImPlot::PlotPolygon("Triangle", tri_xs, tri_ys, 3, {
        ImPlotProp_FillAlpha, 0.5f,
    });
    ImPlot::PlotPolygon("Pentagon", pent_xs, pent_ys, 5, {
        ImPlotProp_FillAlpha, 0.5f,
        ImPlotProp_FillColor, ImVec4(0,1,0,1),
    });
    ImPlot::PlotPolygon("Star (Concave)", star_xs, star_ys, 10, {
        ImPlotProp_FillAlpha, 0.5f,
        ImPlotProp_FillColor, ImVec4(1,1,0,1),
        ImPlotProp_Flags, ImPlotPolygonFlags_Concave,
    });

    ImPlot::EndPlot();
}
image

@brenocq brenocq self-assigned this Feb 14, 2026
@brenocq brenocq added type:feat New feature or request prio:medium Medium priority status:review The task is under review labels Feb 14, 2026
@brenocq brenocq linked an issue Feb 14, 2026 that may be closed by this pull request
@brenocq brenocq mentioned this pull request Feb 14, 2026
@brenocq brenocq added this to the v0.18 - ImPlotSpec milestone Feb 14, 2026
@brenocq
Copy link
Copy Markdown
Collaborator Author

brenocq commented Mar 7, 2026

Since the user specifies the points in plot space, but the ImGui draw list methods expect the points in screen space, I needed dynamically allocate an array of ImVec2 to convert each point from plot space to screen space before sending the array to ImGui, I think this is fine for now for an initial implementation, in the future we can create a polyline renderer so we avoid this dynamic allocation by filling in the draw list directly.

@brenocq brenocq merged commit 625ed87 into master Mar 7, 2026
36 checks passed
@brenocq brenocq added status:done Task completed successfully and removed status:review The task is under review labels Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prio:medium Medium priority status:done Task completed successfully type:feat New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Plot polygon

1 participant