Module: Math

Defined in:
lib/iron/extensions/math.rb

Class Method Summary collapse

Class Method Details

.max(a, b) ⇒ Object



7
8
9
# File 'lib/iron/extensions/math.rb', line 7

def self.max(a,b)
  a >= b ? a : b
end

.min(a, b) ⇒ Object



3
4
5
# File 'lib/iron/extensions/math.rb', line 3

def self.min(a,b)
  a <= b ? a : b
end

.scale_to_fit(w, h, max_w, max_h) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/iron/extensions/math.rb', line 11

def self.scale_to_fit(w,h,max_w,max_h)
  ratio = max_w.to_f / max_h.to_f
  nw, nh = w, h
  cur_ratio = nw.to_f / nh.to_f

  if cur_ratio >= ratio
    nw = max_w
    nh = max_w / cur_ratio
  else
    nh = max_h
    nw = max_h * cur_ratio
  end

  return nw.to_i, nh.to_i
end