From 4316ba1d4ac54f379e04c07b07c9a55bfe9227b2 Mon Sep 17 00:00:00 2001 From: Marek Ventur <marekventur@gmail.com> Date: Thu, 22 Aug 2019 11:50:37 +0200 Subject: [PATCH] Optimize circle drawing I have no idea whether this is something the compiler wouldn't automatically do, but it can't hurt to be explicit. --- lib/gfx/gfx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gfx/gfx.c b/lib/gfx/gfx.c index 55f1debf5..03e99516c 100644 --- a/lib/gfx/gfx.c +++ b/lib/gfx/gfx.c @@ -135,12 +135,12 @@ void gfx_clear(struct gfx_region *reg) void gfx_circle(struct gfx_region *reg, int x, int y, int r, int t, Color c) { + int outer = (r + t) * (r + t); + int inner = r * r; for (int y_ = y - r - t; y_ <= y + r + t; y_++) { for (int x_ = x - r - t; x_ <= x + r + t; x_++) { int dx = (x_ - x) * (x_ - x); int dy = (y_ - y) * (y_ - y); - int outer = (r + t) * (r + t); - int inner = r * r; int edge = ((dx + dy) >= inner) && ((dx + dy) <= outer); if (edge) gfx_setpixel(reg, x_, y_, c); @@ -150,11 +150,11 @@ void gfx_circle(struct gfx_region *reg, int x, int y, int r, int t, Color c) void gfx_circle_fill(struct gfx_region *reg, int x, int y, int r, Color c) { + int edge = r * r; for (int y_ = y - r; y_ <= y + r; y_++) { for (int x_ = x - r; x_ <= x + r; x_++) { int dx = (x_ - x) * (x_ - x); int dy = (y_ - y) * (y_ - y); - int edge = r * r; int fill = (dx + dy) <= edge; if (fill) gfx_setpixel(reg, x_, y_, c); -- GitLab