From 5bc11ccfcdfd1421b968446d85ac4de4ea785acb Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 30 Mar 2015 13:09:26 +0100 Subject: Bug 695556: Use doubles when inverting matrices. When inverting matrices, use doubles for inversion calculations. This prevents floats over/underflowing and causing stroked content to go missing. --- source/fitz/geometry.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/source/fitz/geometry.c b/source/fitz/geometry.c index b6b6533e..073536ff 100644 --- a/source/fitz/geometry.c +++ b/source/fitz/geometry.c @@ -217,18 +217,26 @@ int fz_try_invert_matrix(fz_matrix *dst, const fz_matrix *src) { /* Be careful to cope with dst == src */ - float a = src->a; - float det = a * src->d - src->b * src->c; - if (det >= -FLT_EPSILON && det <= FLT_EPSILON) + double sa = (double)src->a; + double sb = (double)src->b; + double sc = (double)src->c; + double sd = (double)src->d; + double da, db, dc, dd; + double det = sa * sd - sb * sc; + if (det >= -DBL_EPSILON && det <= DBL_EPSILON) return 1; det = 1 / det; - dst->a = src->d * det; - dst->b = -src->b * det; - dst->c = -src->c * det; - dst->d = a * det; - a = -src->e * dst->a - src->f * dst->c; - dst->f = -src->e * dst->b - src->f * dst->d; - dst->e = a; + da = sd * det; + dst->a = (float)da; + db = -sb * det; + dst->b = (float)db; + dc = -sc * det; + dst->c = (float)dc; + dd = sa * det; + dst->d = (float)dd; + da = -src->e * da - src->f * dc; + dst->f = (float)(-src->e * db - src->f * dd); + dst->e = (float)da; return 0; } -- cgit v1.2.3