summaryrefslogtreecommitdiff
path: root/src/plot/generic.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2010-01-31 22:29:01 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2010-01-31 22:29:01 +0000
commitd4977e28bad2b03eac90adba88a1334932ecf72a (patch)
treee70b5c6a47988d981b18aacc31d032be7a9e3302 /src/plot/generic.c
parentbf36ea80c319f307831f38c069d4e67442e4e81b (diff)
downloadlibnsfb-d4977e28bad2b03eac90adba88a1334932ecf72a.tar.gz
libnsfb-d4977e28bad2b03eac90adba88a1334932ecf72a.tar.bz2
Improve rounding of fill span endpoints for polygon plotter.
svn path=/trunk/libnsfb/; revision=9946
Diffstat (limited to 'src/plot/generic.c')
-rw-r--r--src/plot/generic.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/plot/generic.c b/src/plot/generic.c
index e6856dc..3bd06a5 100644
--- a/src/plot/generic.c
+++ b/src/plot/generic.c
@@ -173,9 +173,22 @@ static bool find_span(const int *p, int n, int x, int y, int *x0, int *x1)
} else {
/* find crossing (intersection of this line and
* current y level) */
- x_new = p_x0 + ((long long)
- (y - p_y0) * (p_x1 - p_x0)) /
- (p_y1 - p_y0);
+ int numerator = (y - p_y0) * (p_x1 - p_x0);
+ int denominator = (p_y1 - p_y0);
+
+ /* To round to nearest (rather than down)
+ * half the denominator is either added to
+ * or subtracted from the numerator,
+ * depending on whether the numerator and
+ * denominator have the same sign */
+ if ((numerator < 0) == (denominator < 0))
+ x_new = p_x0 + (numerator +
+ (denominator / 2)) /
+ denominator;
+ else
+ x_new = p_x0 + (numerator -
+ (denominator / 2)) /
+ denominator;
}
/* ignore crossings before current x */