From 727939b3e6380e623540b4dfae497ead2c3c6e04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bert=20M=C3=BCnnich?= <ber.t@posteo.de>
Date: Mon, 22 Jan 2018 10:37:06 +0100
Subject: [PATCH] Make zoomdiff compare impact on image dimensions

Before that zoomdiff was a merely heuristic.

Related to issue #303
---
 image.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/image.c b/image.c
index e7a5ca6..41d9b32 100644
--- a/image.c
+++ b/image.c
@@ -39,9 +39,9 @@ enum { DEF_GIF_DELAY = 75 };
 float zoom_min;
 float zoom_max;
 
-static int zoomdiff(float z1, float z2)
+static int zoomdiff(img_t *img, float z)
 {
-	return (int) (z1 * 1000.0 - z2 * 1000.0);
+	return (int) ((img->w * z - img->w * img->zoom) + (img->h * z - img->h * img->zoom));
 }
 
 void img_init(img_t *img, win_t *win)
@@ -417,7 +417,7 @@ bool img_fit(img_t *img)
 	z = MAX(z, zoom_min);
 	z = MIN(z, zmax);
 
-	if (zoomdiff(z, img->zoom) != 0) {
+	if (zoomdiff(img, z) != 0) {
 		img->zoom = z;
 		img->dirty = true;
 		return true;
@@ -539,7 +539,7 @@ bool img_zoom(img_t *img, float z)
 
 	img->scalemode = SCALE_ZOOM;
 
-	if (zoomdiff(z, img->zoom) != 0) {
+	if (zoomdiff(img, z) != 0) {
 		int x, y;
 
 		win_cursor_pos(img->win, &x, &y);
@@ -565,7 +565,7 @@ bool img_zoom_in(img_t *img)
 
 	for (i = 1; i < ARRLEN(zoom_levels); i++) {
 		z = zoom_levels[i] / 100.0;
-		if (zoomdiff(z, img->zoom) > 0)
+		if (zoomdiff(img, z) > 0)
 			return img_zoom(img, z);
 	}
 	return false;
@@ -578,7 +578,7 @@ bool img_zoom_out(img_t *img)
 
 	for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) {
 		z = zoom_levels[i] / 100.0;
-		if (zoomdiff(z, img->zoom) < 0)
+		if (zoomdiff(img, z) < 0)
 			return img_zoom(img, z);
 	}
 	return false;