From aa64c27048e9d308400058b40ee2677cfd7c5081 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 18 Jul 2012 16:04:06 +0100 Subject: Fix missing diagram in 1522*.pdf Since the commit to replace abs/min/max/clamp with inline versions, "1522 - diagramm missing above 88 pc zoom.pdf" has been missing a diagram. This is because the diagram contains sections like: -2147483648 -2147483648 m -2147483648 2147483647 l 2147483647 2147483647 l 2147483647 -2147483648 l These extreme values, when transformed would give floating point values that when naively cast down to int, flip sign (e.g. extreme positive when cast to int becomes extreme negative). I had been relying on the cast down giving sane results to enable me to use fz_clampi. Revert to using fz_clamp and all is fine. --- draw/draw_edge.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'draw') diff --git a/draw/draw_edge.c b/draw/draw_edge.c index 48496acd..ff5dcdfc 100644 --- a/draw/draw_edge.c +++ b/draw/draw_edge.c @@ -356,10 +356,14 @@ fz_insert_gel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1) fy0 = floorf(fy0 * fz_aa_vscale); fy1 = floorf(fy1 * fz_aa_vscale); - x0 = fz_clampi(fx0, BBOX_MIN * fz_aa_hscale, BBOX_MAX * fz_aa_hscale); - y0 = fz_clampi(fy0, BBOX_MIN * fz_aa_vscale, BBOX_MAX * fz_aa_vscale); - x1 = fz_clampi(fx1, BBOX_MIN * fz_aa_hscale, BBOX_MAX * fz_aa_hscale); - y1 = fz_clampi(fy1, BBOX_MIN * fz_aa_vscale, BBOX_MAX * fz_aa_vscale); + /* Call fz_clamp so that clamping is done in the float domain, THEN + * cast down to an int. Calling fz_clampi causes problems due to the + * implicit cast down from float to int of the first argument + * over/underflowing and flipping sign at extreme values. */ + x0 = (int)fz_clamp(fx0, BBOX_MIN * fz_aa_hscale, BBOX_MAX * fz_aa_hscale); + y0 = (int)fz_clamp(fy0, BBOX_MIN * fz_aa_vscale, BBOX_MAX * fz_aa_vscale); + x1 = (int)fz_clamp(fx1, BBOX_MIN * fz_aa_hscale, BBOX_MAX * fz_aa_hscale); + y1 = (int)fz_clamp(fy1, BBOX_MIN * fz_aa_vscale, BBOX_MAX * fz_aa_vscale); d = clip_lerp_y(gel->clip.y0, 0, x0, y0, x1, y1, &v); if (d == OUTSIDE) return; -- cgit v1.2.3