Method: Geometry::SizedRectangle#initialize

Defined in:
lib/geometry/rectangle.rb

#new(width, height) ⇒ Object #new(size) ⇒ Object #new(origin, size) ⇒ Object

Returns a new instance of SizedRectangle.

Overloads:

  • #new(width, height) ⇒ Object

    Creates a Rectangle of the given width and height with its origin at [0,0]

    Parameters:

    • height (Number)

      Height

    • width (Number)

      Width

  • #new(size) ⇒ Object

    Creates a Rectangle of the given Geometry::Size with its origin at [0,0]

    Parameters:

    • size (Size)

      Width and height

  • #new(origin, size) ⇒ Object

    Creates a Rectangle with the given origin point and size

    Parameters:



312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/geometry/rectangle.rb', line 312

def initialize(*args)
    options, args = args.partition {|a| a.is_a? Hash}
    options = options.reduce({}, :merge)

    @origin = options[:origin] ? Point[options[:origin]] : PointZero.new

    if options.has_key?(:size)
  @size = Geometry::Size[options[:size]]
    elsif options.has_key?(:height) and options.has_key?(:width)
  @size = Geometry::Size[options[:width], options[:height]]
    else
  raise ArgumentError, "Bad arguments to SizeRectangle#new"
    end
end