Sha256: ff12aca007a2bd13bf79eec5805ec4afe7fe158cb9fa78a7ec38b248a79b3056

Contents?: true

Size: 562 Bytes

Versions: 1

Compression:

Stored size: 562 Bytes

Contents

module Geometer
  class Point < Struct.new(:x, :y)
    def inspect
      "(#{x},#{y})"
    end

    def invert
      Point.new(-x,-y)
    end
    alias_method :-@, :invert
    
    def scale(sz)
      Point.new(x*sz,y*sz)
    end
    alias_method :*, :scale

    def divide(sz)
      scale(1.0/sz)
    end
    alias_method :/, :divide

    def translate(other_point)
      dx,dy = *other_point
      Point.new(x+dx, y+dy)
    end

    def to_i
      Point.new(x.to_i, y.to_i)
    end
  end

  module PointHelpers
    def coord(x,y); Point.new(x,y) end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geometer-0.1.3 lib/geometer/point.rb