Class: RubySGF::SGF::CompressedList

Inherits:
Object
  • Object
show all
Defined in:
lib/sgf/compressed_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(upper_left_x, upper_left_y, lower_right_x, lower_right_y) ⇒ CompressedList

Returns a new instance of CompressedList.



10
11
12
# File 'lib/sgf/compressed_list.rb', line 10

def initialize(upper_left_x, upper_left_y, lower_right_x, lower_right_y)
  @ulx, @uly, @lrx, @lry = upper_left_x, upper_left_y, lower_right_x, lower_right_y
end

Instance Attribute Details

#lrxObject (readonly)

Returns the value of attribute lrx.



9
10
11
# File 'lib/sgf/compressed_list.rb', line 9

def lrx
  @lrx
end

#lryObject (readonly)

Returns the value of attribute lry.



9
10
11
# File 'lib/sgf/compressed_list.rb', line 9

def lry
  @lry
end

#ulxObject (readonly)

Returns the value of attribute ulx.



9
10
11
# File 'lib/sgf/compressed_list.rb', line 9

def ulx
  @ulx
end

#ulyObject (readonly)

Returns the value of attribute uly.



9
10
11
# File 'lib/sgf/compressed_list.rb', line 9

def uly
  @uly
end

Instance Method Details

#to_aObject

expand compressed list to array



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sgf/compressed_list.rb', line 15

def to_a
  smallx, bigx = [ulx, lrx].sort.map { |i| Coordinates::HORIZONTAL.index(i) }
  xgap = bigx - smallx
  smally, bigy = [uly, lry].sort.map { |i| Coordinates::VERTICAL.index(i) }
  ygap = bigy - smally
  coord_list = []
  Coordinates::VERTICAL[smally..bigy].each do |y|
    Coordinates::HORIZONTAL[smallx..bigx].each do |x|
      coord_list << [x,y]
    end
  end
  coord_list.sort
end