/* call-seq: f.each do |x,y| _code_ end Iterates over all the points in the Function, yielding X and Y for each point. */ static VALUE function_each(VALUE self) /* :yields: x,y */ { long x_len, y_len; VALUE x = get_x_vector(self); VALUE y = get_y_vector(self); double * x_values = Dvector_Data_for_Write(x, &x_len); double * y_values = Dvector_Data_for_Write(y, &y_len); if(x_len != y_len) rb_raise(rb_eRuntimeError,"X and Y must have the same size"); else { /* we temporarily freeze both Dvectors during iteration */ FL_SET(x, DVEC_TMPLOCK); FL_SET(y, DVEC_TMPLOCK); while(x_len--) { VALUE flt_x = rb_float_new(*x_values++); VALUE flt_y = rb_float_new(*y_values++); rb_yield_values(2, flt_x, flt_y); } /* and unfreeze them */ FL_UNSET(x, DVEC_TMPLOCK); FL_UNSET(y, DVEC_TMPLOCK); } return self; /* nothing interesting */ }