Class: Wildfire::Converter::SizeCalculator
- Defined in:
- lib/wildfire/converter/size_calculator.rb
Constant Summary
Constants inherited from Core
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
- #difference(point1, point2) ⇒ Object
-
#initialize(points) ⇒ SizeCalculator
constructor
A new instance of SizeCalculator.
- #max_height ⇒ Object
- #max_width ⇒ Object
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
#points ⇒ Object (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_height ⇒ Object
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_width ⇒ Object
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 |