summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-12-16 13:29:04 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-12-16 13:29:04 (GMT)
commit1f6969f1905fd4559011cd33d116687bc533c088 (patch)
tree9fae16b44603172408d44f9f348cd2642252523e /meme/gui.c
parent5ad3a3a6e4782bc33a4858ae118d4659acdd9f32 (diff)
downloadmisc-1f6969f1905fd4559011cd33d116687bc533c088.zip
misc-1f6969f1905fd4559011cd33d116687bc533c088.tar.gz
misc-1f6969f1905fd4559011cd33d116687bc533c088.tar.bz2
meme/gui.c: clip profiles more aggressively
Note the we can still get artefacts. To eliminate them completely, we could further constrain out-of-area coordinates but at the price of losing many partial lines at high zoom levels. What we'd really want to do is adjust coordinates such that we clip right at the area boundary. Maybe another time ;)
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/meme/gui.c b/meme/gui.c
index f626fe0..c40e94e 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -108,7 +108,7 @@ static inline int xz_z_model2screen(int z)
}
-static int coord_xz(int x, int y, Sint16 *res_x, Sint16 *res_y)
+static int coord_xz(int x, int y, Sint16 *res_x, Sint16 *res_y, Sint16 ymin)
{
x = x_model2screen(x);
y = xz_z_model2screen(y);
@@ -121,7 +121,7 @@ static int coord_xz(int x, int y, Sint16 *res_x, Sint16 *res_y)
*res_x = x;
*res_y = y;
- return x >= 0 && x < xres && y >= 0 && y < yres;
+ return x >= 0 && x < xres && y >= ymin && y < yres;
}
@@ -132,7 +132,7 @@ static inline int yz_z_model2screen(int z)
}
-static int coord_yz(int x, int y, Sint16 *res_x, Sint16 *res_y)
+static int coord_yz(int x, int y, Sint16 *res_x, Sint16 *res_y, Sint16 xmin)
{
x = yz_z_model2screen(x);
y = y_model2screen(y);
@@ -145,7 +145,7 @@ static int coord_yz(int x, int y, Sint16 *res_x, Sint16 *res_y)
*res_x = x;
*res_y = y;
- return x >= 0 && x < xres && y >= 0 && y < yres;
+ return x >= xmin && x < xres && y >= 0 && y < yres;
}
@@ -564,6 +564,7 @@ static void show_xz_profile(SDL_Surface *s)
{
struct point *xz;
unsigned n, i;
+ Sint16 ymin;
Sint16 xa = 0, ya = 0, xb = 0, yb = 0;
/* initialize because gcc seems to "see" that they can be left
uninitialized by coord_xz but then fails to notice that
@@ -572,11 +573,12 @@ static void show_xz_profile(SDL_Surface *s)
xz = plane_xz(cursor->y, &n);
- a = coord_xz(xz[0].x, xz[0].y, &xa, &ya);
- change(s, 0, yres - (yres >> 2)-1, xres, yres >> 2);
+ ymin = yres - (yres >> 2)-1;
+ a = coord_xz(xz[0].x, xz[0].y, &xa, &ya, ymin);
+ change(s, 0, ymin, xres, yres >> 2);
SDL_LockSurface(s);
for (i = 1; i < n; i++) {
- b = coord_xz(xz[i].x, xz[i].y, &xb, &yb);
+ b = coord_xz(xz[i].x, xz[i].y, &xb, &yb, ymin);
if (a >= 0 && b >= 0 && (a || b))
aalineColor(s, xa, ya, xb, yb, PROFILE_RGBA);
xa = xb;
@@ -595,19 +597,21 @@ static void show_yz_profile(SDL_Surface *s)
{
struct point *yz;
unsigned n, i;
+ Sint16 xmin;
Sint16 xa = 0, ya = 0, xb = 0, yb = 0;
/* initialize because gcc seems to "see" that they can be left
- uninitialized by coord_xz but then fails to notice that
+ uninitialized by coord_yz but then fails to notice that
we track this via the return value. */
int a, b;
yz = plane_yz(cursor->x, &n);
- a = coord_yz(yz[0].x, yz[0].y, &xa, &ya);
- change(s, xres - (xres >> 2)-1, 0, xres >> 2, yres);
+ xmin = xres - (xres >> 2)-1;
+ a = coord_yz(yz[0].x, yz[0].y, &xa, &ya, xmin);
+ change(s, xmin, 0, xres >> 2, yres);
SDL_LockSurface(s);
for (i = 1; i < n; i++) {
- b = coord_yz(yz[i].x, yz[i].y, &xb, &yb);
+ b = coord_yz(yz[i].x, yz[i].y, &xb, &yb, xmin);
if (a >= 0 && b >= 0 && (a || b))
aalineColor(s, xa, ya, xb, yb, PROFILE_RGBA);
xa = xb;