Beispiel #1
0
/*
 * call-seq:
 *   new -> CvRect.new(0, 0, 0, 0)
 *   new(obj) -> CvRect.new(obj.x.to_i, obj.y.to_i, obj.width.to_i, obj.height.to_i)
 *   new(x, y, width, height)
 *
 * Create new rectangle area. (x, y) is top-left point, and width, height is size of area.
 * It is dropped below the decimal point.
 *
 * new() is same as new(0, 0, 0, 0)
 *
 * new(obj) is same as new(obj.x.to_i, obj.y.to_i, obj.width.to_i, obj.height.to_i)
 */
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE object, x, y, width, height;
  switch (argc) {
  case 0:
    break;
  case 1:
    object = argv[0];
    if(rb_compatible_q(rb_klass, object)) {
      CVRECT(self)->x = NUM2INT(rb_funcall(rb_funcall(object, rb_intern("x"), 0), rb_intern("to_i"), 0));
      CVRECT(self)->y = NUM2INT(rb_funcall(rb_funcall(object, rb_intern("y"), 0), rb_intern("to_i"), 0));
      CVRECT(self)->width = NUM2INT(rb_funcall(rb_funcall(object, rb_intern("width"), 0), rb_intern("to_i"), 0));
      CVRECT(self)->height = NUM2INT(rb_funcall(rb_funcall(object, rb_intern("height"), 0), rb_intern("to_i"), 0));
    }else{
      rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_klass));
    }
    break;
  case 4:
    x = argv[0], y = argv[1], width = argv[2], height = argv[3];
    CVRECT(self)->x = NUM2INT(x);
    CVRECT(self)->y = NUM2INT(y);
    CVRECT(self)->width = NUM2INT(width);
    CVRECT(self)->height = NUM2INT(height);
    break;
  default:
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
  }
  return Qnil;      
}
Beispiel #2
0
/*
 * call-seq:
 *   new -> CvPoint.new(0, 0)
 *   new(obj) -> CvPoint.new(obj.x.to_i, obj.y.to_i)
 *   new(x, y)
 *
 * Create new 2D-coordinate, (x, y). It is dropped below the decimal point.
 *
 * new() is same as new(0, 0)
 *
 * new(obj) is same as new(obj.x.to_i, obj.y.to_i)
 */
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE obj, x, y;
  switch (argc) {
  case 0:
    break;
  case 1:
    obj = argv[0];
    if (rb_compatible_q(rb_klass, obj)) {
      CVPOINT(self)->x = NUM2INT(rb_funcall(rb_funcall(obj, rb_intern("x"), 0), rb_intern("to_i"), 0));
      CVPOINT(self)->y = NUM2INT(rb_funcall(rb_funcall(obj, rb_intern("y"), 0), rb_intern("to_i"), 0));
    }else{
      rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_klass));
    }
    break;
  case 2:
    x = argv[0], y = argv[1];
    CVPOINT(self)->x = NUM2INT(x);
    CVPOINT(self)->y = NUM2INT(y);
    break;
  default:
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
  }
  return Qnil;    
}