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

fixed the format of CvScalar#to_s to handle float values

This commit is contained in:
ser1zw 2011-01-01 17:25:42 +09:00
parent 5b9cf918b9
commit 252814b057
3 changed files with 35 additions and 8 deletions

View file

@ -181,7 +181,7 @@ rb_to_s(VALUE self)
{
const int i = 6;
VALUE str[i];
str[0] = rb_str_new2("<%s:%d,%d,%d,%d>");
str[0] = rb_str_new2("<%s:%g,%g,%g,%g>");
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
str[2] = rb_aref(self, INT2FIX(0));
str[3] = rb_aref(self, INT2FIX(1));

View file

@ -394,18 +394,22 @@ class TestCvMat < TestOpenCV
def test_diag
m = make_cvmat(5, 5)
# a = [1.1, 7.7, 14.3, 20.9, 27.5].map { |x| CvScalar.new(x, x, x, x) }
a = [1, 7, 13, 19, 25].map { |x| CvScalar.new(x, x, x, x) }
d = m.diag
a.each_with_index { |s, i|
assert(is_same_float_array(s.to_ary, d[i].to_ary))
}
# a = [2.2, 8.8, 15.4, 22.0].map { |x| CvScalar.new(x, x, x, x) }
a = [2, 8, 14, 20].map { |x| CvScalar.new(x, x, x, x) }
d = m.diag(1)
a.each_with_index { |s, i|
assert(is_same_float_array(s.to_ary, d[i].to_ary))
}
# a = [6.6, 13.2, 19.8, 26.4].map { |x| CvScalar.new(x, x, x, x) }
a = [6, 12, 18, 24].map { |x| CvScalar.new(x, x, x, x) }
d = m.diag(-1)
a.each_with_index { |s, i|
@ -413,6 +417,7 @@ class TestCvMat < TestOpenCV
}
# Alias
# a = [1.1, 7.7, 14.3, 20.9, 27.5].map { |x| CvScalar.new(x, x, x, x) }
a = [1, 7, 13, 19, 25].map { |x| CvScalar.new(x, x, x, x) }
d = m.diagonal
a.each_with_index { |s, i|

View file

@ -16,6 +16,11 @@ class TestCvScalar < TestOpenCV
[10, 20, 30, 40].each_with_index { |x, i|
assert_in_delta(x, s[i], 0.01)
}
s = CvScalar.new(0.1, 0.2, 0.3, 0.4)
[0.1, 0.2, 0.3, 0.4].each_with_index { |x, i|
assert_in_delta(x, s[i], 0.01)
}
end
def test_aset
@ -26,6 +31,14 @@ class TestCvScalar < TestOpenCV
[10, 20, 30, 40].each_with_index { |x, i|
assert_in_delta(x, s[i], 0.01)
}
s = CvScalar.new
[0.1, 0.2, 0.3, 0.4].each_with_index { |x, i|
s[i] = x
}
[0.1, 0.2, 0.3, 0.4].each_with_index { |x, i|
assert_in_delta(x, s[i], 0.01)
}
end
def test_sub
@ -37,20 +50,29 @@ class TestCvScalar < TestOpenCV
assert_in_delta(24, s[2], 0.01)
assert_in_delta(32, s[3], 0.01)
}
s3 = CvScalar.new(0.2, 0.4, 0.6, 0.8)
[s2.sub(s3), s2 - s3].each { |s|
assert_in_delta(1.8, s[0], 0.01)
assert_in_delta(3.6, s[1], 0.01)
assert_in_delta(5.4, s[2], 0.01)
assert_in_delta(7.2, s[3], 0.01)
}
end
def test_to_s
assert_equal("<OpenCV::CvScalar:10,20,30,40>", CvScalar.new(10, 20, 30, 40).to_s)
assert_equal("<OpenCV::CvScalar:0.1,0.2,0.3,0.4>", CvScalar.new(0.1, 0.2, 0.3, 0.4).to_s)
end
def test_to_ary
a = [10, 20, 30, 40]
s = CvScalar.new(*a)
b = s.to_ary
assert_equal(Array, b.class)
a.each_with_index { |x, i|
assert_in_delta(x, b[i], 0.01)
[[10, 20, 30, 40], [0.1, 0.2, 0.3, 0.4]].each { |a|
s = CvScalar.new(*a)
b = s.to_ary
assert_equal(Array, b.class)
a.each_with_index { |x, i|
assert_in_delta(x, b[i], 0.01)
}
}
end