Class: Wildfire::Converter::SizeCalculator

Inherits:
Core
  • Object
show all
Defined in:
lib/wildfire/converter/size_calculator.rb

Constant Summary

Constants inherited from Core

Core::RED

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Core

#generate_path, #quick_save, #save, #temp_mat

Constructor Details

#initialize(points) ⇒ SizeCalculator

Returns a new instance of SizeCalculator.



6
7
8
# File 'lib/wildfire/converter/size_calculator.rb', line 6

def initialize(points)
  @points = Orderer.to_tl_tr_br_bl(points)
end

Instance Attribute Details

#pointsObject (readonly)

Returns the value of attribute points.



4
5
6
# File 'lib/wildfire/converter/size_calculator.rb', line 4

def points
  @points
end

Instance Method Details

#difference(point1, point2) ⇒ Object



26
27
28
29
# File 'lib/wildfire/converter/size_calculator.rb', line 26

def difference(point1, point2)
  d = (point2[0] - point1[0])**2 + (point2[1] - point1[1])**2
  Math.sqrt(d)
end

#max_heightObject



18
19
20
21
22
23
24
# File 'lib/wildfire/converter/size_calculator.rb', line 18

def max_height
  tl, tr, br, bl = @points

  height_right = difference(tr, br)
  height_left = difference(tl, bl)
  [height_right.to_i, height_left.to_i].max
end

#max_widthObject



10
11
12
13
14
15
16
# File 'lib/wildfire/converter/size_calculator.rb', line 10

def max_width
  tl, tr, br, bl = @points

  width_bottom = difference(br, bl)
  width_top = difference(tr, tl)
  [width_top.to_i, width_bottom.to_i].max
end