module Math
Public Class Methods
max(a,b)
click to toggle source
# File lib/iron/extensions/math.rb, line 7 def self.max(a,b) a >= b ? a : b end
min(a,b)
click to toggle source
# 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)
click to toggle source
# 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