[dia] Fix endless loop with cairo renderer (maybe bug 660574)



commit 0b73f85982d0a5117c469cd643821bbc06a74eb2
Author: Hans Breuer <hans breuer org>
Date:   Sun Sep 2 19:58:24 2012 +0200

    Fix endless loop with cairo renderer (maybe bug 660574)
    
    Dia's geometry function fillet() was not initializing
    it's return values under certain conditions. Now it signals
    these conditions by returning false, to allow the API user
    (draw_rounded_polyline) to not use these values.
    
    Still cairo should not go into an endless loop with completely
    bogus values, but hopefully Dia does not trigger that bug
    anymore ...

 lib/diarenderer.c |    8 ++++----
 lib/geometry.c    |   15 ++++++++-------
 lib/geometry.h    |    4 ++--
 3 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/lib/diarenderer.c b/lib/diarenderer.c
index 42b5d37..7e52540 100644
--- a/lib/diarenderer.c
+++ b/lib/diarenderer.c
@@ -796,10 +796,10 @@ draw_rounded_polyline (DiaRenderer *renderer,
     
     /* adjust the radius if it would cause odd rendering */
     min_radius = MIN(radius, calculate_min_radius(&p1,&p2,&p4));
-    fillet(&p1,&p2,&p3,&p4, min_radius, &c, &start_angle, &stop_angle);
-    klass->draw_arc(renderer, &c, min_radius*2, min_radius*2,
-		    start_angle,
-		    stop_angle, color);
+    if (fillet(&p1,&p2,&p3,&p4, min_radius, &c, &start_angle, &stop_angle))
+      klass->draw_arc(renderer, &c, min_radius*2, min_radius*2,
+		      start_angle,
+		      stop_angle, color);
     klass->draw_line(renderer, &p1, &p2, color);
     p1.x = p3.x; p1.y = p3.y;
     p2.x = p4.x; p2.y = p4.y;
diff --git a/lib/geometry.c b/lib/geometry.c
index 9fe1d52..bfaea16 100644
--- a/lib/geometry.c
+++ b/lib/geometry.c
@@ -510,8 +510,10 @@ void point_perp(Point *p, real a, real b, real c, Point *perp) {
    The start angle is pa
    The end angle is aa,
    The points p1-p4 will be modified as necessary */
-void fillet(Point *p1, Point *p2, Point *p3, Point *p4,
-                   real r, Point *c, real *pa, real *aa) {
+gboolean
+fillet(Point *p1, Point *p2, Point *p3, Point *p4,
+       real r, Point *c, real *pa, real *aa)
+{
   real a1, b1, c1;  /* Coefficients for L1 */
   real a2, b2, c2;  /* Coefficients for L2 */
   real d, d1, d2;
@@ -525,21 +527,19 @@ void fillet(Point *p1, Point *p2, Point *p3, Point *p4,
   line_coef(&a2,&b2,&c2,p3,p4);
 
   if ( (a1*b2) == (a2*b1) ) /* Parallel or coincident lines */
-  {
-    return;
-  }
+    return FALSE;
 
   mp.x = (p3->x + p4->x) / 2.0;          /* Find midpoint of p3 p4 */
   mp.y = (p3->y + p4->y) / 2.0;
   d1 = line_to_point(a1, b1, c1, &mp);    /* Find distance p1 p2 to
                                              midpoint p3 p4 */
-  if ( d1 == 0.0 ) return;                /* p1p2 to p3 */
+  if ( d1 == 0.0 ) return FALSE;          /* p1p2 to p3 */
 
   mp.x = (p1->x + p2->x) / 2.0;          /* Find midpoint of p1 p2 */
   mp.y = (p1->y + p2->y) / 2.0;
   d2 = line_to_point(a2, b2, c2, &mp);    /* Find distance p3 p4 to
                                              midpoint p1 p2 */
-  if ( d2 == 0.0 ) return;
+  if ( d2 == 0.0 ) return FALSE;
 
   rr = r;
   if ( d1 <= 0.0 ) rr = -rr;
@@ -582,6 +582,7 @@ void fillet(Point *p1, Point *p2, Point *p3, Point *p4,
   }
   *pa = start_angle;
   *aa = stop_angle;
+  return TRUE;
 }
 
 int 
diff --git a/lib/geometry.h b/lib/geometry.h
index 889e1af..68300fe 100644
--- a/lib/geometry.h
+++ b/lib/geometry.h
@@ -370,8 +370,8 @@ real dot2(Point *p1, Point *p2);
 void line_coef(real *a, real *b, real *c, Point *p1, Point *p2);
 real line_to_point(real a, real b , real c, Point *p);
 void point_perp(Point *p, real a, real b, real c, Point *perp);
-void fillet(Point *p1, Point *p2, Point *p3, Point *p4,
-	    real r, Point *c, real *pa, real *aa);
+gboolean fillet(Point *p1, Point *p2, Point *p3, Point *p4,
+		real r, Point *c, real *pa, real *aa);
 int  three_point_circle(const Point *p1, const Point *p2, const Point *p3,
                         Point* center, real* radius);
 real point_cross(Point *p1, Point *p2);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]