Sha256: 704810645426d7541e20b003693dbb5dda9cf730745eeac8894c937dd19ff215

Contents?: true

Size: 1017 Bytes

Versions: 2

Compression:

Stored size: 1017 Bytes

Contents

module GuiGeo
class Point < Struct.new(:x, :y)
  include Tools

  def initialize(*args)
    self.x = self.y = 0
    super if args.length!=0
  end

  def min(b); point(Tools::min(x, b.x), Tools::min(y, b.y)); end
  def max(b); point(Tools::max(x, b.x), Tools::max(y, b.y)); end
  def bound(a, b); point(Tools::bound(a.x, x, b.x), Tools::bound(a.y, y, b.y)); end

  def clone_value(v)
    case v
    when Fixnum, Bignum, Float then v
    else v.clone
    end
  end

  def clone; point(clone_value(x), clone_value(y)); end

  def inspect; "point(#{x},#{y})" end
  def to_s; "(#{x},#{y})" end

  def >=(b) x>=b.x && y>=b.y end
  def <=(b) x<=b.x && y<=b.y end
  def >(b) x>b.x && y>b.y end
  def <(b) x<b.x && y<b.y end

  def +(b) b.kind_of?(Point) ? point(x+b.x, y+b.y) : point(x+b, y+b) end
  def -(b) b.kind_of?(Point) ? point(x-b.x, y-b.y) : point(x-b, y-b) end
  def *(b) b.kind_of?(Point) ? point(x*b.x, y*b.y) : point(x*b, y*b) end
  def /(b) b.kind_of?(Point) ? point(x/b.x, y/b.y) : point(x/b, y/b) end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gui_geometry-0.2.1 lib/gui_geometry/point.rb
gui_geometry-0.2.0 lib/gui_geometry/point.rb