psppire-axis: Use rint() instead of nearbyint(), for portability.
[pspp-builds.git] / src / ui / gui / sheet / psppire-axis.c
index 25f41afe7404840ddfeb9064cbab519824fce424..9cc879dc124c789333b6b7ed721a3d2e556bb5a0 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009  Free Software Foundation
+   Copyright (C) 2008, 2009, 2010  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -100,22 +100,17 @@ psppire_axis_unit_at_pixel (const PsppireAxis *a, glong pixel)
   struct tower_node *n;
   struct axis_node *an;
   gdouble fraction;
-  gint unit;
-  glong size;
 
-  g_return_val_if_fail (pixel >= 0, -1);
-
-  g_mutex_lock (a->mutex);
+  glong size = tower_height (&a->pixel_tower);
 
-  size = tower_height (&a->pixel_tower);
+  g_return_val_if_fail (pixel >= 0, -1);
 
   if (pixel >= size)
     {
       gint n_items = tower_height (&a->unit_tower);
       glong extra = pixel - size;
 
-      unit = n_items - 1 + DIV_RND_UP (extra,  a->default_size);
-      goto finish;
+      return n_items - 1 + DIV_RND_UP (extra,  a->default_size);
     }
 
 
@@ -124,14 +119,8 @@ psppire_axis_unit_at_pixel (const PsppireAxis *a, glong pixel)
 
   fraction = (pixel - start) / (gdouble) tower_node_get_size (&an->pixel_node);
 
-  unit = tower_node_get_level (&an->unit_node)
+  return  tower_node_get_level (&an->unit_node)
     + fraction * tower_node_get_size (&an->unit_node);
-
- finish:
-
-  g_mutex_unlock (a->mutex);
-
-  return unit;
 }
 
 
@@ -140,20 +129,13 @@ psppire_axis_unit_count (const PsppireAxis *a)
 {
   glong filler = 0;
   glong actual_size;
-  gint n_units;
-
-  g_mutex_lock (a->mutex);
 
   actual_size = tower_height (&a->pixel_tower);
 
   if ( actual_size < a->min_extent )
     filler = DIV_RND_UP (a->min_extent - actual_size, a->default_size);
 
-  n_units = tower_height (&a->unit_tower) + filler;
-
-  g_mutex_unlock (a->mutex);
-
-  return n_units;
+  return tower_height (&a->unit_tower) + filler;
 }
 
 
@@ -164,28 +146,24 @@ psppire_axis_start_pixel (const PsppireAxis *a, gint unit)
   gdouble fraction;
   struct tower_node *n ;
   struct axis_node *an;
-  glong pixel ;
 
   unsigned long int start;
 
   gint the_count, size ;
 
-  g_mutex_lock (a->mutex);
-
   the_count =  tower_height (&a->unit_tower);
   size = tower_height (&a->pixel_tower);
 
   if ( unit >= the_count)
     {
-      pixel = size + (unit - the_count) * a->default_size;
-      goto finish;
+      return  size + (unit - the_count) * a->default_size;
     }
 
   if ( unit < 0)
-    goto error;
+    return -1;
 
   if ( unit >= tower_height (&a->unit_tower))
-    goto error;
+    return -1;
 
   n = tower_lookup (&a->unit_tower, unit, &start);
 
@@ -193,16 +171,8 @@ psppire_axis_start_pixel (const PsppireAxis *a, gint unit)
 
   fraction = (unit - start) / (gdouble) tower_node_get_size (&an->unit_node);
 
-  pixel =  tower_node_get_level (&an->pixel_node) +
-    nearbyint (fraction * tower_node_get_size (&an->pixel_node));
-
- finish:
-  g_mutex_unlock (a->mutex);
-  return pixel;
-
- error:
-  g_mutex_unlock (a->mutex);
-  return  -1;
+  return  tower_node_get_level (&an->pixel_node) +
+    rint (fraction * tower_node_get_size (&an->pixel_node));
 }
 
 gint
@@ -210,39 +180,24 @@ psppire_axis_unit_size (const PsppireAxis *axis, gint unit)
 {
   struct tower_node *n ;
   struct axis_node *an;
-  gint size;
 
   unsigned long int start;
 
-  g_mutex_lock (axis->mutex);
-
   if  (unit >= tower_height (&axis->unit_tower))
-    {
-      size = axis->default_size;
-      goto finish;
-    }
+    return axis->default_size;
 
   if ( unit < 0)
-    {
-      size = 0;
-      goto finish;
-    }
+    return 0;
 
   if ( unit >= tower_height (&axis->unit_tower))
-    {
-      size = 0;
-      goto finish;
-    }
+    return 0;
 
   n = tower_lookup (&axis->unit_tower, unit, &start);
 
   an = tower_data (n, struct axis_node, unit_node);
 
-  size = nearbyint (tower_node_get_size (&an->pixel_node)
-                   / (gdouble) tower_node_get_size (&an->unit_node));
- finish:
-  g_mutex_unlock (axis->mutex);
-  return size;
+  return rint (tower_node_get_size (&an->pixel_node)
+               / (gdouble) tower_node_get_size (&an->unit_node));
 }
 
 
@@ -422,7 +377,6 @@ psppire_axis_class_init (PsppireAxisClass *class)
 static void
 psppire_axis_init (PsppireAxis *axis)
 {
-  axis->mutex = g_mutex_new ();
   tower_init (&axis->pixel_tower);
   tower_init (&axis->unit_tower);
 
@@ -436,7 +390,6 @@ psppire_axis_finalize (GObject *object)
 {
   PsppireAxis *a = PSPPIRE_AXIS (object);
   pool_destroy (a->pool);
-  g_mutex_free (a->mutex);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -472,20 +425,14 @@ psppire_axis_append_n (PsppireAxis *a, gint n_units, gint size)
 {
   struct axis_node *node;
 
-  g_mutex_lock (a->mutex);
-
   if  (n_units == 0)
-    goto finish;
+    return;
 
   node = pool_malloc (a->pool, sizeof *node);
 
   tower_insert (&a->unit_tower, n_units, &node->unit_node, NULL);
   tower_insert (&a->pixel_tower, (size + a->padding) * n_units,
     &node->pixel_node, NULL);
-
- finish:
-  g_mutex_unlock (a->mutex);
-  return;
 }
 
 
@@ -525,7 +472,7 @@ split (PsppireAxis *a, gint posn)
   tower_resize (&a->unit_tower, &existing_node->unit_node, posn - start);
 
   tower_resize (&a->pixel_tower, &existing_node->pixel_node,
-               nearbyintf (fraction * existing_pixel_size));
+               rintf (fraction * existing_pixel_size));
 
   tower_insert (&a->unit_tower,
                existing_unit_size - (posn - start),
@@ -534,7 +481,7 @@ split (PsppireAxis *a, gint posn)
 
 
   tower_insert (&a->pixel_tower,
-               nearbyintf (existing_pixel_size * (1 - fraction)),
+               rintf (existing_pixel_size * (1 - fraction)),
                &new_node->pixel_node,
                tower_next (&a->pixel_tower, &existing_node->pixel_node));
 }
@@ -553,8 +500,6 @@ psppire_axis_insert (PsppireAxis *a, gint posn, gint size)
   g_return_if_fail ( posn >= 0);
   g_return_if_fail ( posn <= tower_height (&a->unit_tower));
 
-  g_mutex_lock (a->mutex);
-
   if ( posn < tower_height (&a->unit_tower))
     {
       unsigned long int start = 0;
@@ -579,8 +524,6 @@ psppire_axis_insert (PsppireAxis *a, gint posn, gint size)
                size + a->padding,
                &new_node->pixel_node,
                before ? &before->pixel_node : NULL);
-
-  g_mutex_unlock (a->mutex);
 }
 
 
@@ -625,25 +568,16 @@ psppire_axis_resize (PsppireAxis *axis, gint posn, glong size)
   g_return_if_fail (posn >= 0);
   g_return_if_fail (size > 0);
 
-  g_mutex_lock (axis->mutex);
-
   /* Silently ignore this request if the position is greater than the number of
      units in the axis */
   if (posn >= tower_height (&axis->unit_tower))
-    goto error;
+    return ;
 
   an = make_single (axis, posn);
 
   tower_resize (&axis->pixel_tower, &an->pixel_node, size + axis->padding);
 
- finish:
-  g_mutex_unlock (axis->mutex);
   g_signal_emit (axis, signals[RESIZE_UNIT], 0, posn, size + axis->padding);
-  return;
-
- error:
-  g_mutex_unlock (axis->mutex);
-  return;
 }
 
 
@@ -654,13 +588,11 @@ psppire_axis_resize (PsppireAxis *axis, gint posn, glong size)
 void
 psppire_axis_clear (PsppireAxis *a)
 {
-  g_mutex_lock (a->mutex);
   pool_destroy (a->pool);
   a->pool = pool_create ();
 
   tower_init (&a->pixel_tower);
   tower_init (&a->unit_tower);
-  g_mutex_unlock (a->mutex);
 }
 
 
@@ -673,8 +605,6 @@ psppire_axis_delete (PsppireAxis *a, gint first, gint n_units)
   struct tower_node *unit_node ;
   g_return_if_fail (first + n_units <= tower_height (&a->unit_tower));
 
-  g_mutex_lock (a->mutex);
-
   split (a, first);
   split (a, first + n_units);
 
@@ -701,5 +631,4 @@ psppire_axis_delete (PsppireAxis *a, gint first, gint n_units)
 
       unit_node = next_unit_node;
     }
-  g_mutex_unlock (a->mutex);
 }