From bca913c35ad0ca655976c72dfb8d7530340ed938 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/gfx/gfx.c b/lib/gfx/gfx.c index 55f1debf..dd92ecdc 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 dx = (x_ - x) * (x_ - x); + int dy = (y_ - y) * (y_ - y); 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