Class: Tsunami::Bucket

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tsunami/bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frames, width, height) ⇒ Bucket

Returns a new instance of Bucket.



12
13
14
15
16
17
# File 'lib/tsunami/bucket.rb', line 12

def initialize(frames, width, height)
  @values = []
  @frames = frames
  @width = width
  @height = height
end

Instance Attribute Details

#framesObject (readonly)

Returns the value of attribute frames.



10
11
12
# File 'lib/tsunami/bucket.rb', line 10

def frames
  @frames
end

#heightObject (readonly)

Returns the value of attribute height.



10
11
12
# File 'lib/tsunami/bucket.rb', line 10

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



10
11
12
# File 'lib/tsunami/bucket.rb', line 10

def width
  @width
end

Instance Method Details

#frames_per_pixelObject



27
28
29
# File 'lib/tsunami/bucket.rb', line 27

def frames_per_pixel
  @frames_per_pixel ||= frames / @width
end

#index(frame) ⇒ Object



31
32
33
# File 'lib/tsunami/bucket.rb', line 31

def index(frame)
  frame / frames_per_pixel
end

#set(frame, value) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/tsunami/bucket.rb', line 19

def set(frame, value)
  frame_values = values(frame)

  frame_values[:min] = value if value < frame_values[:min]

  frame_values[:max] = value if value > frame_values[:max]
end

#values(frame) ⇒ Object



35
36
37
# File 'lib/tsunami/bucket.rb', line 35

def values(frame)
  @values[index(frame)] ||= { :max => -1, :min => 1 }
end