class Griddle::Point
Public Instance Methods
<=>(point)
click to toggle source
TODO: not sure this is really necessary,
it seemed like a good idea at the time
# File lib/griddle/point.rb, line 9 def <=>(point) [row, col] <=> [point.row, point.col] end
delta(point)
click to toggle source
# File lib/griddle/point.rb, line 25 def delta(point) Point.new( (self.row - point.row).abs, (self.col - point.col).abs ) end
move(directions)
click to toggle source
# File lib/griddle/point.rb, line 45 def move(directions) directions.each_pair do |direction, amount| amount = amount.to_i case direction.to_sym when :up self.row -= amount when :down self.row += amount when :left self.col -= amount when :right self.col += amount end end end
nil?()
click to toggle source
# File lib/griddle/point.rb, line 17 def nil? row.nil? && col.nil? end
to_rectangle(point)
click to toggle source
‘point` is used to calculate the width and height
of the new rectangle
# File lib/griddle/point.rb, line 34 def to_rectangle(point) d = delta(point) Rectangle.new( row, col, d.col + 1, d.row + 1 ) end
to_s()
click to toggle source
# File lib/griddle/point.rb, line 13 def to_s "[#{row}, #{col}]" end
zero?()
click to toggle source
# File lib/griddle/point.rb, line 21 def zero? row.zero? && col.zero? end