# HG changeset patch # User jwe # Date 1076945002 0 # Node ID 22c4c2be473329cc8245fba31456231cdaefb321 # Parent 7207369b6c8286f2167e0c9d45c4a07304cd7c58 [project @ 2004-02-16 15:23:22 by jwe] diff -r 7207369b6c82 -r 22c4c2be4733 src/data.cc --- a/src/data.cc Mon Feb 16 07:08:24 2004 +0000 +++ b/src/data.cc Mon Feb 16 15:23:22 2004 +0000 @@ -669,10 +669,12 @@ cat_add_dims (dim_vector& dv_new, const dim_vector& dv_arg, int dim) { // dv_arg is [] + if (dv_arg.all_zero ()) return true; // dv_new is [] + if (dv_new.all_zero ()) { dv_new = dv_arg; @@ -683,12 +685,14 @@ int n_args = dv_arg.length (); // Find the max and min value of n_new and n_args + int n_max = n_new > n_args ? n_new : n_args; int n_min = n_new < n_args ? n_new : n_args; // The elements of the dimension vectors can only differ // if the dim variable differs from the actual dimension // they differ. + for (int i = 0; i < n_min; i++) { if (dv_new(i) != dv_arg(i) && dim != i) @@ -698,7 +702,8 @@ } } - // Ditto + // Ditto. + for (int i = n_min; i < n_max; i++) { if (n_new > n_min) @@ -722,9 +727,11 @@ // If we want to add the dimension vectors at a dimension // larger than both, then we need to set n_max to this number // so that we resize dv_new to the right dimension. + n_max = n_max > (dim + 1) ? n_max : (dim + 1); // Resize dv_new to new the appropriate dimensions. + if (n_max > n_new) { dv_new.resize (n_max); @@ -733,7 +740,9 @@ dv_new.elem (i) = 1; } - if (dim > n_args) + // Larger or equal since dim has been decremented by one. + + if (dim >= n_args) dv_new.elem (dim) = dv_new.elem (dim)++; else dv_new.elem (dim) += dv_arg(dim);