Class: RubySGF::SGF::CompressedList
- Inherits:
-
Object
- Object
- RubySGF::SGF::CompressedList
- Defined in:
- lib/sgf/compressed_list.rb
Instance Attribute Summary collapse
-
#lrx ⇒ Object
readonly
Returns the value of attribute lrx.
-
#lry ⇒ Object
readonly
Returns the value of attribute lry.
-
#ulx ⇒ Object
readonly
Returns the value of attribute ulx.
-
#uly ⇒ Object
readonly
Returns the value of attribute uly.
Instance Method Summary collapse
-
#initialize(upper_left_x, upper_left_y, lower_right_x, lower_right_y) ⇒ CompressedList
constructor
A new instance of CompressedList.
-
#to_a ⇒ Object
expand compressed list to array.
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
#lrx ⇒ Object (readonly)
Returns the value of attribute lrx.
9 10 11 |
# File 'lib/sgf/compressed_list.rb', line 9 def lrx @lrx end |
#lry ⇒ Object (readonly)
Returns the value of attribute lry.
9 10 11 |
# File 'lib/sgf/compressed_list.rb', line 9 def lry @lry end |
#ulx ⇒ Object (readonly)
Returns the value of attribute ulx.
9 10 11 |
# File 'lib/sgf/compressed_list.rb', line 9 def ulx @ulx end |
#uly ⇒ Object (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_a ⇒ Object
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 |