mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
added raise_typeerror, raise_compatible_typeerror
This commit is contained in:
parent
ecca9a0d66
commit
76f2933061
17 changed files with 65 additions and 42 deletions
|
@ -102,8 +102,6 @@ rb_center(VALUE self)
|
|||
VALUE
|
||||
rb_set_center(VALUE self, VALUE value)
|
||||
{
|
||||
if (!cCvPoint2D32f::rb_compatible_q(rb_klass, value))
|
||||
rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(cCvPoint2D32f::rb_class()));
|
||||
CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(value);
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -38,17 +38,20 @@ VALUE new_object(CvBox2D box);
|
|||
|
||||
__NAMESPACE_END_CVBOX2D
|
||||
|
||||
inline CvBox2D *CVBOX2D(VALUE object){
|
||||
inline CvBox2D*
|
||||
CVBOX2D(VALUE object){
|
||||
CvBox2D *ptr;
|
||||
Data_Get_Struct(object, CvBox2D, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline CvBox2D VALUE_TO_CVBOX2D(VALUE object){
|
||||
inline CvBox2D
|
||||
VALUE_TO_CVBOX2D(VALUE object){
|
||||
if (rb_obj_is_kind_of(object, cCvBox2D::rb_class())) {
|
||||
return *CVBOX2D(object);
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvBox2D::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_typeerror(object, cCvBox2D::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ rb_set_size(VALUE self, VALUE value)
|
|||
result = cvSetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_HEIGHT, height);
|
||||
}
|
||||
else
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSize::rb_class()));
|
||||
raise_compatible_typeerror(object, cCvSize::rb_class());
|
||||
return DBL2NUM(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ rb_detect_objects(int argc, VALUE *argv, VALUE self)
|
|||
rb_scan_args(argc, argv, "11", &image, &options);
|
||||
|
||||
if (!rb_obj_is_kind_of(image, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "argument 1(target-image) should be %s.", rb_class2name(cCvMat::rb_class()));
|
||||
raise_typeerror(image, cCvMat::rb_class());
|
||||
|
||||
double scale_factor;
|
||||
int flags, min_neighbors;
|
||||
|
|
|
@ -278,7 +278,6 @@ VALUE new_mat_kind_object(CvSize size, VALUE ref_obj, int cvmat_depth, int chann
|
|||
|
||||
__NAMESPACE_END_CVMAT
|
||||
|
||||
|
||||
inline CvMat*
|
||||
CVMAT(VALUE object)
|
||||
{
|
||||
|
@ -291,8 +290,7 @@ inline CvMat*
|
|||
CVMAT_WITH_CHECK(VALUE object)
|
||||
{
|
||||
if (!rb_obj_is_kind_of(object, cCvMat::rb_class()))
|
||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
||||
rb_class2name(CLASS_OF(object)), rb_class2name(cCvMat::rb_class()));
|
||||
raise_typeerror(object, cCvMat::rb_class());
|
||||
return CVMAT(object);
|
||||
}
|
||||
|
||||
|
@ -306,7 +304,7 @@ MASK(VALUE object)
|
|||
CV_MAT_CN(CVMAT(object)->type) == 1)
|
||||
return CVMAT(object);
|
||||
else
|
||||
rb_raise(rb_eTypeError, "object is not mask.");
|
||||
rb_raise(rb_eTypeError, "object is not a mask.");
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
|
@ -49,8 +49,9 @@ inline CvPoint VALUE_TO_CVPOINT(VALUE object){
|
|||
if (cCvPoint::rb_compatible_q(cCvPoint::rb_class(), object)) {
|
||||
return cvPoint(NUM2INT(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("y"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvPoint::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvPoint::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,9 @@ VALUE_TO_CVPOINT2D32F(VALUE object)
|
|||
if (cCvPoint2D32f::rb_compatible_q(cCvPoint2D32f::rb_class(), object)) {
|
||||
return cvPoint2D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("y"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvPoint2D32f::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvPoint2D32f::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,8 +55,9 @@ VALUE_TO_CVPOINT3D32F(VALUE object)
|
|||
return cvPoint3D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("y"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("z"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvPoint3D32f::rb_class()));
|
||||
}
|
||||
else{
|
||||
raise_compatible_typeerror(object, cCvPoint3D32f::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,10 @@ define_ruby_class()
|
|||
VALUE
|
||||
rb_compatible_q(VALUE klass, VALUE object)
|
||||
{
|
||||
return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y")) && rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
||||
return (rb_respond_to(object, rb_intern("x")) &&
|
||||
rb_respond_to(object, rb_intern("y")) &&
|
||||
rb_respond_to(object, rb_intern("width")) &&
|
||||
rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -158,7 +161,8 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
|
|||
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{
|
||||
}
|
||||
else{
|
||||
rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_klass));
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -68,8 +68,9 @@ VALUE_TO_CVRECT(VALUE object)
|
|||
NUM2INT(rb_funcall(object, rb_intern("y"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvRect::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvRect::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ VALUE_TO_CVSCALAR(VALUE object)
|
|||
NUM2DBL(rb_funcall(object, rb_intern("[]"), 1, INT2FIX(2))),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("[]"), 1, INT2FIX(3))));
|
||||
else
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvScalar::rb_class()));
|
||||
raise_compatible_typeerror(object, cCvScalar::rb_class());
|
||||
}
|
||||
|
||||
__NAMESPACE_END_OPENCV
|
||||
|
|
|
@ -53,8 +53,9 @@ VALUE_TO_CVSIZE(VALUE object)
|
|||
if (cCvSize::rb_compatible_q(cCvSize::rb_class(), object)) {
|
||||
return cvSize(NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSize::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvSize::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,9 @@ VALUE_TO_CVSIZE2D32F(VALUE object)
|
|||
if (cCvSize2D32f::rb_compatible_q(cCvSize2D32f::rb_class(), object)) {
|
||||
return cvSize2D32f(NUM2DBL(rb_funcall(object, rb_intern("width"), 0)),
|
||||
NUM2DBL(rb_funcall(object, rb_intern("height"), 0)));
|
||||
}else{
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSize2D32f::rb_class()));
|
||||
}
|
||||
else {
|
||||
raise_compatible_typeerror(object, cCvSize2D32f::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ VALUE_TO_CVSLICE(VALUE object)
|
|||
rb_funcall(object, rb_intern("exclude_end?"), 0) ? NUM2INT(rb_funcall(object, rb_intern("end"), 0)) : NUM2INT(rb_funcall(object, rb_intern("end"), 0)) - 1);
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvSlice::rb_class()));
|
||||
raise_compatible_typeerror(object, cCvSlice::rb_class());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -276,6 +276,18 @@ rb_cvCreateMemStorage(int block_size)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
void
|
||||
raise_typeerror(VALUE object, VALUE expected_class) {
|
||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
||||
rb_obj_classname(object), rb_class2name(expected_class));
|
||||
}
|
||||
|
||||
void
|
||||
raise_compatible_typeerror(VALUE object, VALUE expected_class) {
|
||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s or compatible object)",
|
||||
rb_obj_classname(object), rb_class2name(expected_class));
|
||||
}
|
||||
|
||||
VALUE rb_module;
|
||||
VALUE rb_opencv_constants;
|
||||
|
||||
|
|
|
@ -160,7 +160,6 @@ extern "C"{
|
|||
#define INT2BOOL(x) (x ? Qtrue : Qfalse)
|
||||
#endif
|
||||
|
||||
|
||||
// wrapper for <= 1.8
|
||||
#ifndef RARRAY_LEN
|
||||
#define RARRAY_LEN(arg) (RARRAY(arg)->len)
|
||||
|
@ -194,6 +193,9 @@ void free_object(void *ptr);
|
|||
void release_object(void *ptr);
|
||||
void release_iplconvkernel_object(void *ptr);
|
||||
|
||||
void raise_typeerror(VALUE object, VALUE expected_class);
|
||||
void raise_compatible_typeerror(VALUE object, VALUE expected_class);
|
||||
|
||||
VALUE rb_module_opencv();
|
||||
void define_ruby_module();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue