/* * call-seq: * new * new(obj) * new(x, y) * * Create new 2D-coordinate, (x, y). * * new() is same as new(0.0, 0.0) * * new(obj) is same as new(obj.x.to_f, obj.y.to_f) */ VALUE rb_point_initialize(int argc, VALUE *argv, VALUE self) { VALUE obj, x, y; switch (argc) { case 0: break; case 1: obj = argv[0]; if (rb_point_compatible_q(rb_point_klass, obj)) { CVPOINT2D32F(self)->x = NUM2DBL(rb_funcall(rb_funcall(obj, rb_intern("x"), 0), rb_intern("to_f"), 0)); CVPOINT2D32F(self)->y = NUM2DBL(rb_funcall(rb_funcall(obj, rb_intern("y"), 0), rb_intern("to_f"), 0)); } else { rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_point_klass)); } break; case 2: x = argv[0], y = argv[1]; CVPOINT2D32F(self)->x = NUM2DBL(x); CVPOINT2D32F(self)->y = NUM2DBL(y); break; default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc); } return Qnil; }
VALUE new_object(CvPoint2D32f point) { VALUE object = rb_allocate(rb_klass); *CVPOINT2D32F(object) = point; return object; }
/* * call-seq: * == -> true * * Compare point with other point, returns Boolean */ VALUE rb_point_equal(VALUE self, VALUE other_point) { CvPoint2D32f* this_pt = CVPOINT2D32F(self); CvPoint2D32f* other_pt = CVPOINT2D32F(other_point); return (((this_pt->x == other_pt->x) && (this_pt->y == other_pt->y)) ? Qtrue : Qfalse); }
/* * call-seq: * y = val * * Set y-axis parameter, return self. */ VALUE rb_point_set_y(VALUE self, VALUE y) { CVPOINT2D32F(self)->y = NUM2DBL(y); return self; }
/* * Return parameter on y-axis. */ VALUE rb_point_y(VALUE self) { return rb_float_new(CVPOINT2D32F(self)->y); }
/* * call-seq: * x = val * * Set x-axis parameter, return self. */ VALUE rb_point_set_x(VALUE self, VALUE x) { CVPOINT2D32F(self)->x = NUM2DBL(x); return self; }
/* * Return parameter on x-axis. */ VALUE rb_x(VALUE self) { return rb_float_new(CVPOINT2D32F(self)->x); }