summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-18 22:28:24 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-18 22:28:24 +0100
commit2050f59e3aaf0020a51235ac4e583643c79b898d (patch)
tree50f26d3a058d756da6c39e27f52afe331e429759 /scene/main
parentf2dbd011b6884a5f8a61f44f57e157f0c96bd3d3 (diff)
parent43fc483e6cf609301004c37039aa45a2ca79e070 (diff)
Merge pull request #71623 from kleonc/draw_arc_clamp_to_single_circle
`CanvasItem::draw_arc` Clamp angle difference so arc won't overlap itself
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_item.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 9be1a6431b..a4af7988c6 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -531,10 +531,13 @@ void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vect
void CanvasItem::draw_arc(const Vector2 &p_center, real_t p_radius, real_t p_start_angle, real_t p_end_angle, int p_point_count, const Color &p_color, real_t p_width, bool p_antialiased) {
Vector<Point2> points;
points.resize(p_point_count);
- const real_t delta_angle = p_end_angle - p_start_angle;
+ Point2 *points_ptr = points.ptrw();
+
+ // Clamp angle difference to full circle so arc won't overlap itself.
+ const real_t delta_angle = CLAMP(p_end_angle - p_start_angle, -Math_TAU, Math_TAU);
for (int i = 0; i < p_point_count; i++) {
real_t theta = (i / (p_point_count - 1.0f)) * delta_angle + p_start_angle;
- points.set(i, p_center + Vector2(Math::cos(theta), Math::sin(theta)) * p_radius);
+ points_ptr[i] = p_center + Vector2(Math::cos(theta), Math::sin(theta)) * p_radius;
}
draw_polyline(points, p_color, p_width, p_antialiased);