Method: Geometry::Rectangle#inset
- Defined in:
- lib/geometry/rectangle.rb
#inset(x, y) ⇒ Object #inset(top, left, bottom, right) ⇒ Object #inset(x, y) ⇒ Object #inset(top, left, bottom, right) ⇒ Object
Create a new Geometry::Rectangle from the receiver that’s inset by the given amount
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/geometry/rectangle.rb', line 189 def inset(*args) , args = args.partition {|a| a.is_a? Hash} = .reduce({}, :merge) raise ArumentError, "Can't specify both arguments and options" if !args.empty? && !.empty? if 1 == args.size distance = args.shift Rectangle.new from:(min + distance), to:(max - distance) elsif 2 == args.size distance = Point[*args] Rectangle.new from:(min + distance), to:(max - distance) elsif 4 == args.size top, left, bottom, right = *args Rectangle.new from:(min + Point[left, bottom]), to:(max - Point[right, top]) elsif [:x] && [:y] distance = Point[[:x], [:y]] Rectangle.new from:(min + distance), to:(max - distance) elsif [:top] && [:left] && [:bottom] && [:right] Rectangle.new from:(min + Point[[:left], [:bottom]]), to:(max - Point[[:right], [:top]]) end end |