[glabels] Allow for small error in comparison of dimensions.



commit 94475149f8f8568f62723cb2428ce11d76243f1b
Author: Jim Evins <evins snaught com>
Date:   Sun May 16 11:56:03 2010 -0400

    Allow for small error in comparison of dimensions.
    
    In lgl_template_are_templates_identical(), allow for a small error when
    comparing dimensions.  Set EPSILON to 0.5pt, which is aproximately
    0.007in or 0.2mm.

 libglabels/template.c |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/libglabels/template.c b/libglabels/template.c
index 50ba454..bacb6c6 100644
--- a/libglabels/template.c
+++ b/libglabels/template.c
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <math.h>
 
 #include "libglabels-private.h"
 
@@ -34,6 +35,13 @@
 #include "paper.h"
 
 /*===========================================*/
+/* Private macros and constants.             */
+/*===========================================*/
+
+/* Allowed error when comparing dimensions. (0.5pts ~= .007in ~= .2mm) */
+#define EPSILON 0.5
+
+/*===========================================*/
 /* Private types                             */
 /*===========================================*/
 
@@ -325,31 +333,31 @@ lgl_template_are_templates_identical (const lglTemplate   *template1,
         {
 
         case LGL_TEMPLATE_FRAME_SHAPE_RECT:
-                if ((frame1->rect.w != frame2->rect.w) ||
-                    (frame1->rect.h != frame2->rect.h))
+                if ( (fabs(frame1->rect.w - frame2->rect.w) > EPSILON) ||
+                     (fabs(frame1->rect.h - frame2->rect.h) > EPSILON) )
                 {
                         return FALSE;
                 }
                 break;
 
         case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
-                if ((frame1->ellipse.w != frame2->ellipse.w) ||
-                    (frame1->ellipse.h != frame2->ellipse.h))
+                if ( (fabs(frame1->ellipse.w - frame2->ellipse.w) > EPSILON) ||
+                     (fabs(frame1->ellipse.h - frame2->ellipse.h) > EPSILON) )
                 {
                         return FALSE;
                 }
                 break;
 
         case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
-                if ((frame1->round.r != frame2->round.r))
+                if ( fabs(frame1->round.r - frame2->round.r) > EPSILON )
                 {
                         return FALSE;
                 }
                 break;
 
         case LGL_TEMPLATE_FRAME_SHAPE_CD:
-                if ((frame1->cd.r1 != frame2->cd.r1) ||
-                    (frame1->cd.r2 != frame2->cd.r2))
+                if ( (fabs(frame1->cd.r1 - frame2->cd.r1) > EPSILON) ||
+                     (fabs(frame1->cd.r2 - frame2->cd.r2) > EPSILON) )
                 {
                         return FALSE;
                 }
@@ -366,10 +374,10 @@ lgl_template_are_templates_identical (const lglTemplate   *template1,
 
                         if ( (layout1->nx == layout2->nx) &&
                              (layout1->ny == layout2->ny) &&
-                             (layout1->x0 == layout2->x0) &&
-                             (layout1->y0 == layout2->y0) &&
-                             (layout1->dx == layout2->dx) &&
-                             (layout1->dy == layout2->dy) )
+                             (fabs(layout1->x0 - layout2->x0) < EPSILON) &&
+                             (fabs(layout1->y0 - layout2->y0) < EPSILON) &&
+                             (fabs(layout1->dx - layout2->dx) < EPSILON) &&
+                             (fabs(layout1->dy - layout2->dy) < EPSILON) )
                         {
                                 match_found = TRUE;
                         }



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