Module: Vector2d::Fitting
Instance Method Summary collapse
- #contain(other) ⇒ Object
- #fit(other) ⇒ Object (also: #constrain_both)
- #fit_either(other) ⇒ Object (also: #constrain_one)
Instance Method Details
#contain(other) ⇒ Object
15 16 17 18 |
# File 'lib/vector2d/fitting.rb', line 15 def contain(other) v, _ = coerce(other) (v.x > x || v.y > y) ? other.fit(self) : other end |
#fit(other) ⇒ Object Also known as: constrain_both
30 31 32 33 34 |
# File 'lib/vector2d/fitting.rb', line 30 def fit(other) v, _ = coerce(other) scale = v.to_f_vector / self self * ((scale.y == 0 || (scale.x > 0 && scale.x < scale.y)) ? scale.x : scale.y) end |
#fit_either(other) ⇒ Object Also known as: constrain_one
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vector2d/fitting.rb', line 44 def fit_either(other) v, _ = coerce(other) scale = v.to_f_vector / self if (scale.x > 0 && scale.y > 0) scale = (scale.x < scale.y) ? scale.y : scale.x self * scale else fit(v) end end |