Class: GuiGeo::Point

Inherits:
Struct
  • Object
show all
Includes:
Tools
Defined in:
lib/gui_geometry/point.rb

Constant Summary

Constants included from GuiGeo

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tools

#minmax

Methods included from GuiGeo

#point, #rect

Constructor Details

#initialize(*args) ⇒ Point

Returns a new instance of Point.



5
6
7
8
# File 'lib/gui_geometry/point.rb', line 5

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

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



2
3
4
# File 'lib/gui_geometry/point.rb', line 2

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



2
3
4
# File 'lib/gui_geometry/point.rb', line 2

def y
  @y
end

Instance Method Details

#*(b) ⇒ Object



33
# File 'lib/gui_geometry/point.rb', line 33

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

#+(b) ⇒ Object



31
# File 'lib/gui_geometry/point.rb', line 31

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

#-(b) ⇒ Object



32
# File 'lib/gui_geometry/point.rb', line 32

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

#/(b) ⇒ Object



34
# File 'lib/gui_geometry/point.rb', line 34

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

#<(b) ⇒ Object



29
# File 'lib/gui_geometry/point.rb', line 29

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

#<=(b) ⇒ Object



27
# File 'lib/gui_geometry/point.rb', line 27

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

#>(b) ⇒ Object



28
# File 'lib/gui_geometry/point.rb', line 28

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

#>=(b) ⇒ Object



26
# File 'lib/gui_geometry/point.rb', line 26

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

#bound(a, b) ⇒ Object



12
# File 'lib/gui_geometry/point.rb', line 12

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

#cloneObject



21
# File 'lib/gui_geometry/point.rb', line 21

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

#clone_value(v) ⇒ Object



14
15
16
17
18
19
# File 'lib/gui_geometry/point.rb', line 14

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

#inspectObject



23
# File 'lib/gui_geometry/point.rb', line 23

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

#max(b) ⇒ Object



11
# File 'lib/gui_geometry/point.rb', line 11

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

#min(b) ⇒ Object



10
# File 'lib/gui_geometry/point.rb', line 10

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

#to_sObject



24
# File 'lib/gui_geometry/point.rb', line 24

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