[cairo-commit] 2 commits - src/cairo-fixed-private.h src/cairo-stroke-dash.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Apr 19 08:16:34 PDT 2012


 src/cairo-fixed-private.h |    2 ++
 src/cairo-stroke-dash.c   |    4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

New commits:
commit 0046967224640c0a390b4a7b376bbd631ed32a5c
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Apr 19 16:12:55 2012 +0100

    dash: Increment dash_remain by the next segment to reduce accumulation errors
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-stroke-dash.c b/src/cairo-stroke-dash.c
index b38d3bc..9494010 100644
--- a/src/cairo-stroke-dash.c
+++ b/src/cairo-stroke-dash.c
@@ -76,7 +76,7 @@ _cairo_stroker_dash_step (cairo_stroker_dash_t *dash, double step)
 	    dash->dash_index = 0;
 
 	dash->dash_on = ! dash->dash_on;
-	dash->dash_remain = dash->dashes[dash->dash_index];
+	dash->dash_remain += dash->dashes[dash->dash_index];
     }
 }
 
commit 5e39a8098b88b2e8d25eb46c6bbe8656c9e0260c
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Apr 19 15:48:01 2012 +0100

    dash: Use a epsilon compare for stepping the dash
    
    Due to rounding errors that may creep in comparing against 0.0 is
    dangerous and may result in an infinite loop whilst generating dashes
    that consumes all memory.
    
    Reported-and-tested-by: Uli Schlachter <psychon at znc.in>
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-fixed-private.h b/src/cairo-fixed-private.h
index 9a16a03..b6cc6be 100644
--- a/src/cairo-fixed-private.h
+++ b/src/cairo-fixed-private.h
@@ -52,6 +52,8 @@
 #define CAIRO_FIXED_ONE_DOUBLE ((double)(1 << CAIRO_FIXED_FRAC_BITS))
 #define CAIRO_FIXED_EPSILON    ((cairo_fixed_t)(1))
 
+#define CAIRO_FIXED_ERROR_DOUBLE (1. / (2 * CAIRO_FIXED_ONE_DOUBLE))
+
 #define CAIRO_FIXED_FRAC_MASK  ((cairo_fixed_t)(((cairo_fixed_unsigned_t)(-1)) >> (CAIRO_FIXED_BITS - CAIRO_FIXED_FRAC_BITS)))
 #define CAIRO_FIXED_WHOLE_MASK (~CAIRO_FIXED_FRAC_MASK)
 
diff --git a/src/cairo-stroke-dash.c b/src/cairo-stroke-dash.c
index d581bdc..b38d3bc 100644
--- a/src/cairo-stroke-dash.c
+++ b/src/cairo-stroke-dash.c
@@ -71,7 +71,7 @@ void
 _cairo_stroker_dash_step (cairo_stroker_dash_t *dash, double step)
 {
     dash->dash_remain -= step;
-    if (dash->dash_remain <= 0.) {
+    if (dash->dash_remain < CAIRO_FIXED_ERROR_DOUBLE) {
 	if (++dash->dash_index == dash->num_dashes)
 	    dash->dash_index = 0;
 


More information about the cairo-commit mailing list