[gimp] app: change the unit of angles in the draw tool's draw_arc() functions



commit 02924e1e70d901780d76990b991912d743bbb9e9
Author: Michael Natterer <mitch gimp org>
Date:   Sat Sep 25 17:35:40 2010 +0200

    app: change the unit of angles in the draw tool's draw_arc() functions
    
    from the weird X 1/64 of a degree to radian.

 app/tools/gimpdrawtool.c             |   22 ++++++++--------------
 app/tools/gimpdrawtool.h             |    8 ++++----
 app/tools/gimpellipseselecttool.c    |    2 +-
 app/tools/gimpforegroundselecttool.c |    3 ++-
 app/tools/gimpmeasuretool.c          |   16 ++++++++--------
 app/tools/gimprectangleselecttool.c  |    8 ++++----
 6 files changed, 27 insertions(+), 32 deletions(-)
---
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index 09c42c4..a815813 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -518,22 +518,19 @@ gimp_draw_tool_draw_arc (GimpDrawTool *draw_tool,
                          gdouble       y,
                          gdouble       width,
                          gdouble       height,
-                         gint          angle1,
-                         gint          angle2)
+                         gdouble       start_angle,
+                         gdouble       slice_angle)
 {
   GimpCanvasItem *item;
-  gdouble         a1, a2;
 
   g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
 
-  a1 = (gdouble) angle1 / 64.0 / 180.0 * G_PI;
-  a2 = (gdouble) angle2 / 64.0 / 180.0 * G_PI;
-
   item = gimp_canvas_arc_new (x + width  / 2.0,
                               y + height / 2.0,
                               width  / 2.0,
                               height / 2.0,
-                              a1, a2,
+                              start_angle,
+                              slice_angle,
                               FALSE);
 
   gimp_draw_tool_add_item (draw_tool, item);
@@ -547,12 +544,11 @@ gimp_draw_tool_draw_arc_by_anchor (GimpDrawTool  *draw_tool,
                                    gdouble        y,
                                    gint           width,
                                    gint           height,
-                                   gint           angle1,
-                                   gint           angle2,
+                                   gdouble        start_angle,
+                                   gdouble        slice_angle,
                                    GtkAnchorType  anchor)
 {
   GimpCanvasItem *item;
-  gdouble         a1, a2;
 
   g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
 
@@ -561,10 +557,8 @@ gimp_draw_tool_draw_arc_by_anchor (GimpDrawTool  *draw_tool,
                                  GIMP_HANDLE_CIRCLE,
                                  anchor, x, y, width, height);
 
-  a1 = (gdouble) angle1 / 64.0 / 180.0 * G_PI;
-  a2 = (gdouble) angle2 / 64.0 / 180.0 * G_PI;
-
-  gimp_canvas_handle_set_angles (GIMP_CANVAS_HANDLE (item), a1, a2);
+  gimp_canvas_handle_set_angles (GIMP_CANVAS_HANDLE (item),
+                                 start_angle, slice_angle);
 
   gimp_draw_tool_add_item (draw_tool, item);
   g_object_unref (item);
diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h
index 32d9c55..e1c9043 100644
--- a/app/tools/gimpdrawtool.h
+++ b/app/tools/gimpdrawtool.h
@@ -114,8 +114,8 @@ void       gimp_draw_tool_draw_arc                 (GimpDrawTool     *draw_tool,
                                                     gdouble           y,
                                                     gdouble           width,
                                                     gdouble           height,
-                                                    gint              angle1,
-                                                    gint              angle2);
+                                                    gdouble           start_angle,
+                                                    gdouble           slice_angle);
 
 void       gimp_draw_tool_draw_arc_by_anchor       (GimpDrawTool     *draw_tool,
                                                     gboolean          filled,
@@ -123,8 +123,8 @@ void       gimp_draw_tool_draw_arc_by_anchor       (GimpDrawTool     *draw_tool,
                                                     gdouble           y,
                                                     gint              width,
                                                     gint              height,
-                                                    gint              angle1,
-                                                    gint              angle2,
+                                                    gdouble           start_angle,
+                                                    gdouble           slice_angle,
                                                     GtkAnchorType     anchor);
 
 void       gimp_draw_tool_draw_handle              (GimpDrawTool     *draw_tool,
diff --git a/app/tools/gimpellipseselecttool.c b/app/tools/gimpellipseselecttool.c
index 9e7b0cc..c5bc477 100644
--- a/app/tools/gimpellipseselecttool.c
+++ b/app/tools/gimpellipseselecttool.c
@@ -114,7 +114,7 @@ gimp_ellipse_select_tool_draw (GimpDrawTool *draw_tool)
                            FALSE,
                            x1, y1,
                            x2 - x1, y2 - y1,
-                           0, 360 * 64);
+                           0.0, 2 * G_PI);
 }
 
 static void
diff --git a/app/tools/gimpforegroundselecttool.c b/app/tools/gimpforegroundselecttool.c
index f23fa62..37ee31f 100644
--- a/app/tools/gimpforegroundselecttool.c
+++ b/app/tools/gimpforegroundselecttool.c
@@ -614,7 +614,8 @@ gimp_foreground_select_tool_draw (GimpDrawTool *draw_tool)
 
       gimp_draw_tool_draw_arc (draw_tool, FALSE,
                                x - radius, y - radius,
-                               2 * radius, 2 * radius, 0, 360 * 64);
+                               2 * radius, 2 * radius,
+                               0.0, 2.0 * G_PI);
     }
   else
     {
diff --git a/app/tools/gimpmeasuretool.c b/app/tools/gimpmeasuretool.c
index f2448fd..1be8526 100644
--- a/app/tools/gimpmeasuretool.c
+++ b/app/tools/gimpmeasuretool.c
@@ -663,7 +663,6 @@ gimp_measure_tool_draw (GimpDrawTool *draw_tool)
   GimpMeasureTool *measure = GIMP_MEASURE_TOOL (draw_tool);
   GimpTool        *tool    = GIMP_TOOL (draw_tool);
   gint             i;
-  gint             angle1, angle2;
   gint             draw_arc = 0;
 
   for (i = 0; i < measure->num_points; i++)
@@ -711,15 +710,16 @@ gimp_measure_tool_draw (GimpDrawTool *draw_tool)
 
   if (measure->num_points > 1 && draw_arc == measure->num_points - 1)
     {
-      angle1 = measure->angle2 * 64.0;
-      angle2 = (measure->angle1 - measure->angle2) * 64.0;
+      gdouble angle1 = measure->angle2 / 180.0 * G_PI;
+      gdouble angle2 = (measure->angle1 - measure->angle2) / 180.0 * G_PI;
 
-      if (angle2 > 11520)
-          angle2 -= 23040;
-      if (angle2 < -11520)
-          angle2 += 23040;
+      if (angle2 > G_PI)
+        angle2 -= 2.0 * G_PI;
 
-      if (angle2 != 0)
+      if (angle2 < -G_PI)
+        angle2 += 2.0 * G_PI;
+
+      if (angle2 != 0.0)
         {
           gimp_draw_tool_draw_arc_by_anchor (draw_tool,
                                              FALSE,
diff --git a/app/tools/gimprectangleselecttool.c b/app/tools/gimprectangleselecttool.c
index fb80467..a8ee136 100644
--- a/app/tools/gimprectangleselecttool.c
+++ b/app/tools/gimprectangleselecttool.c
@@ -313,22 +313,22 @@ gimp_rectangle_select_tool_draw (GimpDrawTool *draw_tool)
       gimp_draw_tool_draw_arc (draw_tool, FALSE,
                                x1, y1,
                                square_size, square_size,
-                               90 * 64,  90 * 64);
+                               G_PI / 2.0, G_PI / 2.0);
 
       gimp_draw_tool_draw_arc (draw_tool, FALSE,
                                x2 - square_size, y1,
                                square_size, square_size,
-                               0,        90 * 64);
+                               0.0, G_PI / 2.0);
 
       gimp_draw_tool_draw_arc (draw_tool, FALSE,
                                x2 - square_size, y2 - square_size,
                                square_size, square_size,
-                               270 * 64, 90 * 64);
+                               G_PI * 1.5, G_PI / 2.0);
 
       gimp_draw_tool_draw_arc (draw_tool, FALSE,
                                x1, y2 - square_size,
                                square_size, square_size,
-                               180 * 64, 90 * 64);
+                               G_PI, G_PI / 2.0);
     }
 
   gimp_rectangle_tool_draw (draw_tool);



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