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

added error handling to some CvMat method

This commit is contained in:
ser1zw 2011-07-12 04:47:46 +09:00
parent d983d80fa6
commit 8b48490a43
3 changed files with 581 additions and 263 deletions

View file

@ -16,32 +16,32 @@ class OpenCVTestCase < Test::Unit::TestCase
CvMat.class_eval do
# Range check for debug
alias original_aref []
alias original_aset []=;
# alias original_aref []
# alias original_aset []=;
def [](*idx)
if idx.size == 1 and idx[0].is_a? Numeric
n = idx[0]
throw ArgumentError.new("index #{n} is out of range") if n >= rows * cols
elsif idx.all? { |elem| elem.is_a? Numeric }
j, i = *(idx.map { |x| x.to_i })
throw ArgumentError.new("index for row #{j} is out of range") if j >= rows
throw ArgumentError.new("index for column #{i} is out of range") if i >= cols
end
original_aref(*idx)
end
# def [](*idx)
# if idx.size == 1 and idx[0].is_a? Numeric
# n = idx[0]
# throw ArgumentError.new("index #{n} is out of range") if n >= rows * cols
# elsif idx.all? { |elem| elem.is_a? Numeric }
# j, i = *(idx.map { |x| x.to_i })
# throw ArgumentError.new("index for row #{j} is out of range") if j >= rows
# throw ArgumentError.new("index for column #{i} is out of range") if i >= cols
# end
# original_aref(*idx)
# end
def []=(*args)
if args.size == 2 and args[0].is_a? Numeric
n = args[0] # index
throw ArgumentError.new("index #{n} is out of range") if n >= rows * cols
elsif args[0..1].all? { |elem| elem.is_a? Numeric }
j, i = *args
throw ArgumentError.new("index for row #{j} is out of range") if j.to_i >= rows
throw ArgumentError.new("index for column #{i} is out of range") if i.to_i >= cols
end
original_aset(*args)
end
# def []=(*args)
# if args.size == 2 and args[0].is_a? Numeric
# n = args[0] # index
# throw ArgumentError.new("index #{n} is out of range") if n >= rows * cols
# elsif args[0..1].all? { |elem| elem.is_a? Numeric }
# j, i = *args
# throw ArgumentError.new("index for row #{j} is out of range") if j.to_i >= rows
# throw ArgumentError.new("index for column #{i} is out of range") if i.to_i >= cols
# end
# original_aset(*args)
# end
end
def snap(*images)