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

Overloads:

  • #inset(x, y) ⇒ Object
  • #inset(top, left, bottom, right) ⇒ Object

Raises:

  • (ArumentError)


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)
    options, args = args.partition {|a| a.is_a? Hash}
    options = options.reduce({}, :merge)
    raise ArumentError, "Can't specify both arguments and options" if !args.empty? && !options.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 options[:x] && options[:y]
	distance = Point[options[:x], options[:y]]
	Rectangle.new from:(min + distance), to:(max - distance)
    elsif options[:top] && options[:left] && options[:bottom] && options[:right]
	Rectangle.new from:(min + Point[options[:left], options[:bottom]]), to:(max - Point[options[:right], options[:top]])
    end
end