# HG changeset patch # User John W. Eaton # Date 1231140015 -3600 # Node ID 9e07dffc8a6032e57f949915cc8d639eaa70ed16 # Parent bfac13fcb6feaaa5183ecd95b1d75ddc23bb739e generate new fractional parts for recycled graphics handles diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2008-10-16 John W. Eaton + * 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 @@ -430,6 +430,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) @@ -438,6 +445,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; @@ -447,6 +457,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 ()) @@ -456,11 +471,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 (); } } @@ -481,7 +494,7 @@ 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 ());