Sha256: 89defaa35c002c6ba03838f337f180128003c6c0179315bad916cf6f49fb471f

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

# -*- coding: utf-8 -*-


module Reflex


  class Point

    include Comparable

    attr_accessor :x, :y

    def initialize (*args)
      case args.size
      when 0 then @x = @y = 0
      when 1 then @x = @y = args[0]
      when 2 then @x, @y = args
      else raise ArgumentError
      end
    end

    def offset_to! (*args)
      case args.size
      when 1 then @x = @y = args[0]
      when 2 then @x, @y = args
      else raise ArgumentError
      end
      self
    end

    def offset_to (*args)
      dup.offset_to! *args
    end

    def offset_by! (*args)
      case args.size
      when 1 then @x += args[0]; @y += args[0]
      when 2 then @x += args[0]; @y += args[1]
      else raise ArgumentError
      end
      self
    end

    def offset_by (*args)
      dup.offset_by! *args
    end

    def to_a ()
      [@x, @y]
    end

    def [] (index)
      case index
      when 0 then @x
      when 1 then @y
      else raise IndexError
      end
    end

    def <=> (o)
      ret = @x <=> o.x
      return ret if ret != 0
      @y <=> o.y
    end

  end# Point


end# Reflex

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reflexion-0.1.3 lib/reflex/point.rb
reflexion-0.1.2 lib/reflex/point.rb
reflexion-0.1.1 lib/reflex/point.rb