module ChunkyPNG

def self.build_point_from_object(source)

def self.build_point_from_object(source)
  case source
  when ChunkyPNG::Point
    source
  when ChunkyPNG::Dimension
    ChunkyPNG::Point.new(source.width, source.height)
  when Array
    ChunkyPNG::Point.new(source[0], source[1])
  when Hash
    x = source[:x] || source["x"]
    y = source[:y] || source["y"]
    ChunkyPNG::Point.new(x, y)
  when ChunkyPNG::Point::POINT_REGEXP
    ChunkyPNG::Point.new($1.to_i, $2.to_i)
  else
    if source.respond_to?(:x) && source.respond_to?(:y)
      ChunkyPNG::Point.new(source.x, source.y)
    else
      raise ArgumentError,
        "Don't know how to construct a point from #{source.inspect}!"
    end
  end
end