gimp r24842 - in trunk: . app/core app/gegl app/widgets



Author: mitch
Date: Sat Feb  9 17:40:57 2008
New Revision: 24842
URL: http://svn.gnome.org/viewvc/gimp?rev=24842&view=rev

Log:
2008-02-09  Michael Natterer  <mitch gimp org>

	* app/core/gimpcurve.[ch]: keep the anchor points as an array of
	GimpVector2 instead of plain doubles.

	* app/gegl/gimpcurvesconfig.c
	* app/widgets/gimpcurveview.c: changed accordingly.



Modified:
   trunk/ChangeLog
   trunk/app/core/gimpcurve.c
   trunk/app/core/gimpcurve.h
   trunk/app/gegl/gimpcurvesconfig.c
   trunk/app/widgets/gimpcurveview.c

Modified: trunk/app/core/gimpcurve.c
==============================================================================
--- trunk/app/core/gimpcurve.c	(original)
+++ trunk/app/core/gimpcurve.c	Sat Feb  9 17:40:57 2008
@@ -335,14 +335,14 @@
 
   for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
     {
-      curve->points[i][0] = -1.0;
-      curve->points[i][1] = -1.0;
+      curve->points[i].x = -1.0;
+      curve->points[i].y = -1.0;
     }
 
-  curve->points[0][0]  = 0.0;
-  curve->points[0][1]  = 0.0;
-  curve->points[GIMP_CURVE_NUM_POINTS - 1][0] = 1.0;
-  curve->points[GIMP_CURVE_NUM_POINTS - 1][1] = 1.0;
+  curve->points[0].x  = 0.0;
+  curve->points[0].y  = 0.0;
+  curve->points[GIMP_CURVE_NUM_POINTS - 1].x = 1.0;
+  curve->points[GIMP_CURVE_NUM_POINTS - 1].y = 1.0;
 
   g_object_freeze_notify (G_OBJECT (curve));
 
@@ -380,8 +380,8 @@
             {
               gint32 index = CLAMP0255 (i * 32);
 
-              curve->points[i * 2][0] = (gdouble) index / 255.0;
-              curve->points[i * 2][1] = curve->curve[index];
+              curve->points[i * 2].x = (gdouble) index / 255.0;
+              curve->points[i * 2].y = curve->curve[index];
             }
 
           g_object_notify (G_OBJECT (curve), "points");
@@ -417,12 +417,12 @@
 
   for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
     {
-      if (curve->points[i][0] >= 0.0)
-        if (fabs (x - curve->points[i][0]) < distance)
-          {
-            distance = fabs (x - curve->points[i][0]);
-            closest_point = i;
-          }
+      if (curve->points[i].x >= 0.0 &&
+          fabs (x - curve->points[i].x) < distance)
+        {
+          distance = fabs (x - curve->points[i].x);
+          closest_point = i;
+        }
     }
 
   if (distance > MIN_DISTANCE)
@@ -444,8 +444,8 @@
 
   g_object_freeze_notify (G_OBJECT (curve));
 
-  curve->points[point][0] = x;
-  curve->points[point][1] = y;
+  curve->points[point].x = x;
+  curve->points[point].y = y;
 
   g_object_notify (G_OBJECT (curve), "points");
 
@@ -466,7 +466,7 @@
 
   g_object_freeze_notify (G_OBJECT (curve));
 
-  curve->points[point][1] = y;
+  curve->points[point].y = y;
 
   g_object_notify (G_OBJECT (curve), "points");
 
@@ -557,17 +557,17 @@
       /*  cycle through the curves  */
       num_pts = 0;
       for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
-        if (curve->points[i][0] >= 0.0)
+        if (curve->points[i].x >= 0.0)
           points[num_pts++] = i;
 
       /*  Initialize boundary curve points */
       if (num_pts != 0)
         {
-          for (i = 0; i < (gint) (curve->points[points[0]][0] * 255.999); i++)
-            curve->curve[i] = curve->points[points[0]][1];
+          for (i = 0; i < (gint) (curve->points[points[0]].x * 255.999); i++)
+            curve->curve[i] = curve->points[points[0]].y;
 
-          for (i = (gint) (curve->points[points[num_pts - 1]][0] * 255.999); i < 256; i++)
-            curve->curve[i] = curve->points[points[num_pts - 1]][1];
+          for (i = (gint) (curve->points[points[num_pts - 1]].x * 255.999); i < 256; i++)
+            curve->curve[i] = curve->points[points[num_pts - 1]].y;
         }
 
       for (i = 0; i < num_pts - 1; i++)
@@ -583,8 +583,8 @@
       /* ensure that the control points are used exactly */
       for (i = 0; i < num_pts; i++)
         {
-          gdouble x = curve->points[points[i]][0];
-          gdouble y = curve->points[points[i]][1];
+          gdouble x = curve->points[points[i]].x;
+          gdouble y = curve->points[points[i]].y;
 
           curve->curve[(gint) (x * 255.999)] = y;
         }
@@ -621,10 +621,10 @@
   gdouble slope;
 
   /* the outer control points for the bezier curve. */
-  x0 = curve->points[p2][0];
-  y0 = curve->points[p2][1];
-  x3 = curve->points[p3][0];
-  y3 = curve->points[p3][1];
+  x0 = curve->points[p2].x;
+  y0 = curve->points[p2].y;
+  x3 = curve->points[p3].x;
+  y3 = curve->points[p3].y;
 
   /*
    * the x values of the inner control points are fixed at
@@ -655,8 +655,8 @@
        * the control handle of the right tangent, to ensure that the curve
        * does not have an inflection point.
        */
-      slope = (curve->points[p4][1] - y0) /
-              (curve->points[p4][0] - x0);
+      slope = (curve->points[p4].y - y0) /
+              (curve->points[p4].x - x0);
 
       y2 = y3 - slope * dx / 3.0;
       y1 = y0 + (y2 - y0) / 2.0;
@@ -664,8 +664,8 @@
   else if (p1 != p2 && p3 == p4)
     {
       /* see previous case */
-      slope = (y3 - curve->points[p1][1]) /
-              (x3 - curve->points[p1][0]);
+      slope = (y3 - curve->points[p1].y) /
+              (x3 - curve->points[p1].x);
 
       y1 = y0 + slope * dx / 3.0;
       y2 = y3 + (y1 - y3) / 2.0;
@@ -676,13 +676,13 @@
        * parallel to the line between the opposite endpoint and the adjacent
        * neighbor.
        */
-      slope = (y3 - curve->points[p1][1]) /
-              (x3 - curve->points[p1][0]);
+      slope = (y3 - curve->points[p1].y) /
+              (x3 - curve->points[p1].x);
 
       y1 = y0 + slope * dx / 3.0;
 
-      slope = (curve->points[p4][1] - y0) /
-              (curve->points[p4][0] - x0);
+      slope = (curve->points[p4].y - y0) /
+              (curve->points[p4].x - x0);
 
       y2 = y3 - slope * dx / 3.0;
     }

Modified: trunk/app/core/gimpcurve.h
==============================================================================
--- trunk/app/core/gimpcurve.h	(original)
+++ trunk/app/core/gimpcurve.h	Sat Feb  9 17:40:57 2008
@@ -21,6 +21,7 @@
 
 
 #include "gimpdata.h"
+#include "libgimpmath/gimpvector.h"
 
 
 #define GIMP_CURVE_NUM_POINTS 17 /* TODO: get rid of this limit */
@@ -42,7 +43,7 @@
 
   GimpCurveType  curve_type;
 
-  gdouble        points[GIMP_CURVE_NUM_POINTS][2];
+  GimpVector2    points[GIMP_CURVE_NUM_POINTS];
   gdouble        curve[256];
 };
 

Modified: trunk/app/gegl/gimpcurvesconfig.c
==============================================================================
--- trunk/app/gegl/gimpcurvesconfig.c	(original)
+++ trunk/app/gegl/gimpcurvesconfig.c	Sat Feb  9 17:40:57 2008
@@ -411,15 +411,15 @@
             {
               gint32 index = CLAMP0255 (j * 32);
 
-              curve->points[j * 2][0] = (gdouble) index / 255.0;
-              curve->points[j * 2][1] = curve->curve[index];
+              curve->points[j * 2].x = (gdouble) index / 255.0;
+              curve->points[j * 2].y = curve->curve[index];
             }
         }
 
       for (j = 0; j < GIMP_CURVE_NUM_POINTS; j++)
         fprintf (file, "%d %d ",
-                 (gint) (curve->points[j][0] * 255.999),
-                 (gint) (curve->points[j][1] * 255.999));
+                 (gint) (curve->points[j].x * 255.999),
+                 (gint) (curve->points[j].y * 255.999));
 
       fprintf (file, "\n");
     }

Modified: trunk/app/widgets/gimpcurveview.c
==============================================================================
--- trunk/app/widgets/gimpcurveview.c	(original)
+++ trunk/app/widgets/gimpcurveview.c	Sat Feb  9 17:40:57 2008
@@ -315,8 +315,8 @@
 {
   gdouble x, y;
 
-  x =       view->curve->points[i][0];
-  y = 1.0 - view->curve->points[i][1];
+  x =       view->curve->points[i].x;
+  y = 1.0 - view->curve->points[i].y;
 
   if (x < 0.0)
     return;
@@ -553,17 +553,17 @@
       /*  determine the leftmost and rightmost points  */
       view->leftmost = -1.0;
       for (i = closest_point - 1; i >= 0; i--)
-        if (curve->points[i][0] >= 0.0)
+        if (curve->points[i].x >= 0.0)
           {
-            view->leftmost = curve->points[i][0];
+            view->leftmost = curve->points[i].x;
             break;
           }
 
       view->rightmost = 2.0;
       for (i = closest_point + 1; i < GIMP_CURVE_NUM_POINTS; i++)
-        if (curve->points[i][0] >= 0.0)
+        if (curve->points[i].x >= 0.0)
           {
-            view->rightmost = curve->points[i][0];
+            view->rightmost = curve->points[i].x;
             break;
           }
 
@@ -635,7 +635,7 @@
     case GIMP_CURVE_SMOOTH:
       if (! view->grabbed) /*  If no point is grabbed...  */
         {
-          if (curve->points[closest_point][0] >= 0.0)
+          if (curve->points[closest_point].x >= 0.0)
             new_cursor = GDK_FLEUR;
           else
             new_cursor = GDK_TCROSS;
@@ -651,7 +651,7 @@
           if (x > view->leftmost && x < view->rightmost)
             {
               closest_point = ((gint) (x * 255.999) + 8) / 16;
-              if (curve->points[closest_point][0] < 0.0)
+              if (curve->points[closest_point].x < 0.0)
                 gimp_curve_view_set_selected (view, closest_point);
 
               gimp_curve_set_point (curve, view->selected, x, 1.0 - y);
@@ -737,7 +737,7 @@
   GimpCurveView *view   = GIMP_CURVE_VIEW (widget);
   GimpCurve     *curve  = view->curve;
   gint           i      = view->selected;
-  gdouble        y      = curve->points[i][1];
+  gdouble        y      = curve->points[i].y;
   gboolean       retval = FALSE;
 
   if (view->grabbed || ! curve ||
@@ -749,7 +749,7 @@
     case GDK_Left:
       for (i = i - 1; i >= 0 && ! retval; i--)
         {
-          if (curve->points[i][0] >= 0.0)
+          if (curve->points[i].x >= 0.0)
             {
               gimp_curve_view_set_selected (view, i);
 
@@ -761,7 +761,7 @@
     case GDK_Right:
       for (i = i + 1; i < GIMP_CURVE_NUM_POINTS && ! retval; i++)
         {
-          if (curve->points[i][0] >= 0.0)
+          if (curve->points[i].x >= 0.0)
             {
               gimp_curve_view_set_selected (view, i);
 



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