+
+ // merge the middle pairs of points - each middle point merges with its counterpart
+ while(left_same < iter1-1 && right_same < iter2-1)
+ {
+ old1 = *(left_same++);
+ old2 = *(right_same++);
+ if (print) printf(" copy middle from left %d and right %d\n", tpos1++, tpos2++);
+ ret.push_back(CPoint(old1.pos, old1.color+old2.color));
+ }
+ // if one gradient has more middle points than the other, merge the rest with the last point in the other gradient
+ for(old2 = (*(iter2-1)); left_same < iter1-1; left_same++)
+ {
+ old1 = *left_same;
+ if (print) printf(" copy middle from left %d plus end of right\n", tpos1++);
+ ret.push_back(CPoint(old1.pos, old1.color + old2.color));
+ }
+ for(old1 = (*(iter1-1)); right_same < iter2-1; right_same++)
+ {
+ old2 = *right_same;
+ if (print) printf(" copy middle from right %d plus end of left\n", tpos2++);
+ ret.push_back(CPoint(old2.pos, old1.color + old2.color));
+ }
+ // merge the back two cpoints
+ if (print) printf(" copy end from left %d right %d\n", pos1++, pos2++);