octave-maintainers
[Top][All Lists]
Advanced

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

Re: Problem with Ben's change to preserve axis propers when used with co


From: John W. Eaton
Subject: Re: Problem with Ben's change to preserve axis propers when used with colorbars
Date: Thu, 16 Oct 2008 17:11:57 -0400

On 16-Oct-2008, Ben Abbott wrote:

| Recycling handles had also introduced a confusing dynamic for me :-(.

Since no one seems to like the recycling of handle values, then how
about the following change?

jwe


# HG changeset patch
# User John W. Eaton <address@hidden>
# Date 1224191222 14400
# Node ID 8c4e79668a5e1386d0146145d1cbe354316868a3
# Parent  beaf723a49ebbd2d1f7c6dec871d596080df2957
generate new fractional parts for recycled graphics handles

diff --git a/src/ChangeLog b/src/ChangeLog
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,4 +1,9 @@
 2008-10-16  John W. Eaton  <address@hidden>
+
+       * graphics.cc (make_handle_fraction): New static function.
+       (gh_manager::get_handle): Use it.
+       (gh_manager::do_free): Call make_handle_fraction to replace
+       fractional part of non-figure handles.
 
        * graphics.cc (base_properties::remove_child): Handle children as
        a column vector instead of a row vector.
diff --git a/src/graphics.cc b/src/graphics.cc
--- a/src/graphics.cc
+++ b/src/graphics.cc
@@ -1243,6 +1243,13 @@
     error ("set: invalid number of arguments");
 }
 
+static double
+make_handle_fraction (void)
+{
+  static double maxrand = RAND_MAX + 2.0;
+
+  return (rand () + 1.0) / maxrand;
+}
 
 graphics_handle
 gh_manager::get_handle (const std::string& go_name)
@@ -1251,6 +1258,9 @@
 
   if (go_name == "figure")
     {
+      // Figure handles are positive integers corresponding to the
+      // figure number.
+
       // We always want the lowest unused figure number.
 
       retval = 1;
@@ -1260,6 +1270,11 @@
     }
   else
     {
+      // Other graphics handles are negative integers plus some random
+      // fractional part.  To avoid running out of integers, we
+      // recycle the integer part but tack on a new random part each
+      // time.
+
       free_list_iterator p = handle_free_list.begin ();
 
       if (p != handle_free_list.end ())
@@ -1269,11 +1284,9 @@
        }
       else
        {
-         static double maxrand = RAND_MAX + 2.0;
-
          retval = graphics_handle (next_handle);
 
-         next_handle = ceil (next_handle) - 1.0 - (rand () + 1.0) / maxrand;
+         next_handle = ceil (next_handle) - 1.0 - make_handle_fraction ();
        }
     }
 
@@ -1310,10 +1323,15 @@
              // deleted object.  All its children will then have an
              // unknown backend.
 
+             // Graphics handles for non-figure objects are negative
+             // integers plus some random fractional part.  To avoid
+             // running out of integers, we recycle the integer part
+             // but tack on a new random part each time.
+
              handle_map.erase (p);
 
              if (h.value () < 0)
-               handle_free_list.insert (h);
+               handle_free_list.insert (ceil (h.value ()) - 
make_handle_fraction ());
            }
          else
            error ("graphics_handle::free: invalid object %g", h.value ());

reply via email to

[Prev in Thread] Current Thread [Next in Thread]