Re: PATCH: gdk_rectangle_intersect simplification



Peter Osterlund <peter.osterlund@mailbox.swipnet.se> writes:

> Here is a small patch to simplify the gdk_rectangle_intersect function.
> The new implementation is analogous to the gdk_rectangle_union function,
> which is much simpler than a lot of if statements.

Since I got no response to my previous message, here is some more
information.

* The patch makes the source code smaller and easier to understand.
* The patch makes the object code smaller and faster, especially for
  PPro/PII/PIII CPUs with conditional move instructions.
* You are free to use the patch as you see fit.
* It is obviously correct.
* I have used it for about three weeks on my computer without
  problems.

What else is required to get the patch installed?

regards,

Index: gdk/gdkrectangle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkrectangle.c,v
retrieving revision 1.10
diff -u -d -u -r1.10 gdkrectangle.c
--- gdk/gdkrectangle.c	2000/07/26 11:32:26	1.10
+++ gdk/gdkrectangle.c	2000/07/29 14:23:43
@@ -50,9 +50,8 @@
 			 GdkRectangle *src2,
 			 GdkRectangle *dest)
 {
-  GdkRectangle *temp;
-  gint src1_x2, src1_y2;
-  gint src2_x2, src2_y2;
+  gint dest_x, dest_y;
+  gint dest_w, dest_h;
   gint return_val;
 
   g_return_val_if_fail (src1 != NULL, FALSE);
@@ -61,52 +60,20 @@
 
   return_val = FALSE;
 
-  if (src2->x < src1->x)
-    {
-      temp = src1;
-      src1 = src2;
-      src2 = temp;
-    }
-  src1_x2 = src1->x + src1->width;
-  src2_x2 = src2->x + src2->width;
+  dest_x = MAX (src1->x, src2->x);
+  dest_y = MAX (src1->y, src2->y);
+  dest_w = MIN (src1->x + src1->width, src2->x + src2->width) - dest_x;
+  dest_h = MIN (src1->y + src1->height, src2->y + src2->height) - dest_y;
 
-  if (src2->x < src1_x2)
+  if (dest_w > 0 && dest_h > 0)
     {
-      dest->x = src2->x;
-
-      if (src1_x2 < src2_x2)
-	dest->width = src1_x2 - dest->x;
-      else
-	dest->width = src2_x2 - dest->x;
-
-      if (src2->y < src1->y)
-	{
-	  temp = src1;
-	  src1 = src2;
-	  src2 = temp;
-	}
-      src1_y2 = src1->y + src1->height;
-      src2_y2 = src2->y + src2->height;
-
-      if (src2->y < src1_y2)
-	{
-	  return_val = TRUE;
-
-	  dest->y = src2->y;
-
-	  if (src1_y2 < src2_y2)
-	    dest->height = src1_y2 - dest->y;
-	  else
-	    dest->height = src2_y2 - dest->y;
-
-	  if (dest->height == 0)
-	    return_val = FALSE;
-	  if (dest->width == 0)
-	    return_val = FALSE;
-	}
+      dest->x = dest_x;
+      dest->y = dest_y;
+      dest->width = dest_w;
+      dest->height = dest_h;
+      return_val = TRUE;
     }
-
-  if (!return_val)
+  else
     {
       dest->width = 0;
       dest->height = 0;

-- 
Peter Österlund           Email:    peter.osterlund@mailbox.swipnet.se
Sköndalsvägen 35                    f90-pos@nada.kth.se
S-128 66 Sköndal          Homepage: http://home1.swipnet.se/~w-15919
Sweden                    Phone:    +46 8 942647




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