/* * 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; }
VALUE new_object(CvPoint point) { VALUE object = rb_allocate(rb_klass); *CVPOINT(object) = point; return object; }
VALUE new_object() { VALUE object = rb_allocate(rb_klass); *CVPOINT(object) = cvPoint(0, 0); return object; }
/* * 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) { CvPoint* self_ptr = CVPOINT(self); switch (argc) { case 0: break; case 1: { CvPoint point = VALUE_TO_CVPOINT(argv[0]); self_ptr->x = point.x; self_ptr->y = point.y; break; } case 2: self_ptr->x = NUM2INT(argv[0]); self_ptr->y = NUM2INT(argv[1]); break; default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc); break; } return self; }
/* * call-seq: * to_ary -> [x, y] * * Return x and y by Array. */ VALUE rb_to_ary(VALUE self) { CvPoint* self_ptr = CVPOINT(self); return rb_ary_new3(2, INT2NUM(self_ptr->x), INT2NUM(self_ptr->y)); }
/* * call-seq: * y = val * * Set y-axis parameter, return self. * It is dropped below the decimal point. */ VALUE rb_set_y(VALUE self, VALUE y) { CVPOINT(self)->y = NUM2INT(y); return self; }
/* * Return parameter on y-axis. */ VALUE rb_y(VALUE self) { return INT2FIX(CVPOINT(self)->y); }
/* * call-seq: * x = val * * Set x-axis parameter, return self. * It is dropped below the decimal point. * pt = CvPoint.new * pt.x = 1.1 * pt.x #=> 1 * pt.x = 100.9 * pt.x #=> 100 */ VALUE rb_set_x(VALUE self, VALUE x) { CVPOINT(self)->x = NUM2INT(x); return self; }
/* * Return parameter on x-axis. */ VALUE rb_x(VALUE self) { return INT2FIX(CVPOINT(self)->x); }