From ecca9a0d663f95a3fbdaa0aad535a2d7981af2b7 Mon Sep 17 00:00:00 2001 From: ser1zw Date: Sat, 2 Jul 2011 13:42:44 +0900 Subject: [PATCH] modified some functions --- ext/opencv/cvmat.cpp | 13 ++++++++----- ext/opencv/cvpoint.cpp | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ext/opencv/cvmat.cpp b/ext/opencv/cvmat.cpp index efb474a..d16625b 100644 --- a/ext/opencv/cvmat.cpp +++ b/ext/opencv/cvmat.cpp @@ -468,7 +468,7 @@ rb_load_imageM(int argc, VALUE *argv, VALUE self) Check_Type(filename, T_STRING); int _iscolor; - if (TYPE(iscolor) == T_NIL) { + if (NIL_P(iscolor)) { _iscolor = CV_LOAD_IMAGE_COLOR; } else { @@ -552,9 +552,11 @@ rb_inside_q(VALUE self, VALUE object) if (cCvRect::rb_compatible_q(cCvRect::rb_class(), object)) { int width = NUM2INT(rb_funcall(object, rb_intern("width"), 0)); int height = NUM2INT(rb_funcall(object, rb_intern("height"), 0)); - return x >= 0 && y >= 0 && x < mat->width && x + width < mat->width && y < mat->height && y + height < mat->height ? Qtrue : Qfalse; - } else { - return x >= 0 && y >= 0 && x < mat->width && y < mat->height ? Qtrue : Qfalse; + return (x >= 0) && (y >= 0) && (x < mat->width) && ((x + width) < mat->width) + && (y < mat->height) && ((y + height) < mat->height) ? Qtrue : Qfalse; + } + else { + return (x >= 0) && (y >= 0) && (x < mat->width) && (y < mat->height) ? Qtrue : Qfalse; } } rb_raise(rb_eArgError, "argument 1 should have method \"x\", \"y\""); @@ -623,7 +625,8 @@ rb_height(VALUE self) VALUE rb_depth(VALUE self) { - return rb_hash_aref(rb_funcall(rb_const_get(rb_module_opencv(), rb_intern("DEPTH")), rb_intern("invert"), 0), INT2FIX(CV_MAT_DEPTH(CVMAT(self)->type))); + return rb_hash_aref(rb_funcall(rb_const_get(rb_module_opencv(), rb_intern("DEPTH")), rb_intern("invert"), 0), + INT2FIX(CV_MAT_DEPTH(CVMAT(self)->type))); } /* diff --git a/ext/opencv/cvpoint.cpp b/ext/opencv/cvpoint.cpp index abb559a..374a140 100644 --- a/ext/opencv/cvpoint.cpp +++ b/ext/opencv/cvpoint.cpp @@ -113,7 +113,8 @@ rb_initialize(int argc, VALUE *argv, VALUE self) 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{ + } + else { rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_klass)); } break;