Method: Grid#minmax
- Defined in:
- lib/cem/cruzzles.rb
#minmax(null = nil) ⇒ Object
Finds the top-left (min), bottom-right (max) coordinates of this Grid using the given value ‘null’ as an indicator for an empty field.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/cem/cruzzles.rb', line 360 def minmax(null=nil) min = nil max = nil @data.each_with_index { |l, y| l.each_with_index { |c, x| if c != null if min == nil || max == nil min = max = Point2D.new(x,y) end min = Point2D.new([min.x, x].min, [min.y, y].min) max = Point2D.new([max.x, x].max, [min.y, y].max) end } } return min, max end |