Sha256: 5f59e8a801f1569b5b6b69c5bab27910ee195564fa3da8b89da3779bf708cfa2

Contents?: true

Size: 813 Bytes

Versions: 9

Compression:

Stored size: 813 Bytes

Contents

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


require 'rays/ext'


module Rays


  class Point

    include Comparable
    include Enumerable

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

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

    def zero? ()
      length == 0
    end

    def each (&block)
      to_a.each &block
    end

    def to_a (dimension = 2)
      case dimension
      when 1 then [x]
      when 2 then [x, y]
      when 3 then [x, y, z]
      else raise ArgumentError
      end
    end

    def to_s (dimension = 2)
      to_a(dimension).to_s
    end

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

    def inspect ()
      "#<Rays::Point #{to_a(3).join ', '}>"
    end

  end# Point


end# Rays

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rays-0.1.21 lib/rays/point.rb
rays-0.1.20 lib/rays/point.rb
rays-0.1.19 lib/rays/point.rb
rays-0.1.18 lib/rays/point.rb
rays-0.1.17 lib/rays/point.rb
rays-0.1.16 lib/rays/point.rb
rays-0.1.15 lib/rays/point.rb
rays-0.1.14 lib/rays/point.rb
rays-0.1.13 lib/rays/point.rb