Class: WindowBlessing::WindowRedrawAreas

Inherits:
Object
  • Object
show all
Includes:
Tools
Defined in:
lib/window_blessing/window_redraw_areas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tools

#buffer, #clone_value, #color, #fill_line, #gen_array2d, #gray_screen_color, #log, #overlapping_span, #overlay2d, #overlay_span, #range_length, #resize2d, #rgb_screen_color, #subarray2d, #window

Constructor Details

#initializeWindowRedrawAreas

Returns a new instance of WindowRedrawAreas.



6
7
8
# File 'lib/window_blessing/window_redraw_areas.rb', line 6

def initialize
  @areas = []
end

Instance Attribute Details

#areasObject (readonly)

Returns the value of attribute areas.



4
5
6
# File 'lib/window_blessing/window_redraw_areas.rb', line 4

def areas
  @areas
end

Instance Method Details

#<<(area) ⇒ Object

first pass merging algorithm: merge all overlapping areas with area until no overlapping areas This creates a non-overlapping set of areas, but it may be much bigger total area than before. TODO - for “two-point” overlaps - just shrink one of the rectangles so they don’t overlap but still cover the same area



14
15
16
17
18
19
20
21
# File 'lib/window_blessing/window_redraw_areas.rb', line 14

def <<(area)
  overlapping, non_overlapping = @areas.partition {|a| a.overlaps?(area)}
  while overlapping.length > 0
    overlapping.each {|a| area &= a}
    overlapping, non_overlapping = non_overlapping.partition {|a| a.overlaps?(area)}
  end
  @areas = non_overlapping + [area]
end