Class: Dir2D

Inherits:
Point2D show all
Defined in:
lib/cem/cruzzles.rb

Constant Summary collapse

N =
UP    = Dir2D.new( 0, -1).freeze
E =
RIGHT = Dir2D.new( 1,  0).freeze
S =
DOWN  = Dir2D.new( 0,  1).freeze
W =
LEFT  = Dir2D.new(-1,  0).freeze
All =
[N, E, S, W]

Instance Attribute Summary

Attributes inherited from Point2D

#x, #y

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Point2D

#+, #-, #<=>, #==, #add!, #area, #dist, #down, #down!, #flip, from_dir_bitmask, from_s, #left, #left!, #manhattan, #max, #min, #minmax, minmax, #right, #right!, #to_dir_bitmask, #to_s, #up, #up!

Class Method Details

.hori(length = 1) ⇒ Object



261
262
263
# File 'lib/cem/cruzzles.rb', line 261

def self.hori(length=1)
  return [E * (1..length), W * (1..length)].flatten
end

.vert(length = 1) ⇒ Object



257
258
259
# File 'lib/cem/cruzzles.rb', line 257

def self.vert(length=1)
  return [N * (1..length), S * (1..length)].flatten
end

.x(length = 1) ⇒ Object



265
266
267
# File 'lib/cem/cruzzles.rb', line 265

def self.x(length=1)
  return vert(length) + hori(length)
end

Instance Method Details

#*(other) ⇒ Object

Dir2D * Range = array of Dir2D E * (1..3) = [E, E*2, E*3]



249
250
251
252
253
254
255
# File 'lib/cem/cruzzles.rb', line 249

def *(other)
  if other.is_a? Range
    other.to_a.map { |b| self * b }
  else
    super
  end  
end