1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

added type check to some CvMat methods

This commit is contained in:
ser1zw 2011-06-30 14:00:26 +09:00
parent 20d71ff11c
commit d3ecd00428
2 changed files with 39 additions and 1 deletions

View file

@ -1786,9 +1786,11 @@ rb_mul(int argc, VALUE *argv, VALUE self)
if (rb_scan_args(argc, argv, "11", &val, &scale) < 2)
scale = rb_float_new(1.0);
dest = new_mat_kind_object(cvGetSize(CVARR(self)), self);
if (rb_obj_is_kind_of(val, rb_klass)) {
cvMul(CVARR(self), CVARR(val), CVARR(dest), NUM2DBL(scale));
}else{
}
else {
CvScalar scl = VALUE_TO_CVSCALAR(val);
VALUE mat = new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self)));
cvSet(CVARR(mat), scl);

View file

@ -992,6 +992,10 @@ class TestCvMat < OpenCVTestCase
assert_cvscalar_equal(CvScalar.new(0, 0, 0, 0), m4[j, i])
}
}
assert_raise(TypeError) {
m0.convert_scale(DUMMY_OBJ)
}
end
def test_convert_scale_abs
@ -1018,6 +1022,10 @@ class TestCvMat < OpenCVTestCase
assert_cvscalar_equal(m0[j, i], m4[j, i])
}
}
assert_raise(TypeError) {
m0.convert_scale(DUMMY_OBJ)
}
end
def test_add
@ -1105,6 +1113,13 @@ class TestCvMat < OpenCVTestCase
n += 1
}
}
assert_raise(TypeError) {
m1.add(DUMMY_OBJ)
}
assert_raise(TypeError) {
m1.add(CvScalar.new(1), DUMMY_OBJ)
}
end
def test_sub
@ -1192,6 +1207,13 @@ class TestCvMat < OpenCVTestCase
n += 1
}
}
assert_raise(TypeError) {
m1.sub(DUMMY_OBJ)
}
assert_raise(TypeError) {
m1.sub(CvScalar.new(1), DUMMY_OBJ)
}
end
def test_mul
@ -1236,6 +1258,13 @@ class TestCvMat < OpenCVTestCase
n = (c + 1) * scale
CvScalar.new(n * 0.1, n * 0.2, n * 0.3, n * 0.4)
}
assert_raise(TypeError) {
m1.mul(DUMMY_OBJ)
}
assert_raise(TypeError) {
m1.mul(m2, DUMMY_OBJ)
}
end
def test_mat_mul
@ -1280,6 +1309,13 @@ class TestCvMat < OpenCVTestCase
assert_in_delta(17, m[2, 1][0], 0.001)
assert_in_delta(20.1, m[2, 2][0], 0.001)
}
assert_raise(TypeError) {
m0.mat_mul(DUMMY_OBJ)
}
assert_raise(TypeError) {
m0.mat_mul(m1, DUMMY_OBJ)
}
end
def test_div