Flight of the AutoSum

created: August 26, 1999

I was working on describing how AutoFormulas work for my MScript reference.  [AutoSum is an AutoFormula.  It's the button on the Mesa 2 toolbar with the uppercase Greek letter Sigma on it.]  I thought the process would be simple, but the simple AutoSum has quite a few decisions to make.  I decided to give it a page of its own.

When I make a selection on a layer and press the AutoSum button, Mesa 2 makes these decisions for me:

if the selection is a single cell then
   if there's data above the cell then
       the selected cell loses its data
       sum the data above the cell
   else if there's data to the left of the cell
       the selected cell loses its data
       sum the data to the left of the cell
   else
       do nothing
   end if
else if the selection is only one row tall then
   if the leftmost cell is blank then
       for each cell in the selection
          if there is data above the cell then
             the cell loses its data
             make the cell sum above itself
          else
             do nothing
          end if
       end for
   else
       the rightmost cell loses its data
       sum the data to the left of the rightmost cell
   end if
else if the selection is only one column wide then
   if the top cell is blank then
       for each cell in the selection
          if there is data to the left of the cell then
             the cell loses its data
             make the cell sum to the left of itself
          else
             do nothing
          end if
       end for
   else
       the bottom cell loses its data
       sum the data above the bottom cell
   end if
else
   /* there is more than one row and more than one column */
   row_percent = percentage of blank cells in bottom row
   col_percent = percentage of blank cells in right column
   if both the right column and the bottom row are blank then
       turn the bottom row into cells that sum above it
       turn the rightmost column into cells that sum to the left
   else if col_percent >= row_percent
       the bottom row loses its data
       make the bottom row sum the cells above it
   else
       the right column loses its data
       make the right column sum the cells to the right of it
   end if
end if