Class: Geometer::Point

Inherits:
Struct
  • Object
show all
Defined in:
lib/geometer/point.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



2
3
4
# File 'lib/geometer/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/geometer/point.rb', line 2

def y
  @y
end

Instance Method Details

#divide(sz) ⇒ Object Also known as: /



17
18
19
# File 'lib/geometer/point.rb', line 17

def divide(sz)
  scale(1.0/sz)
end

#inspectObject



3
4
5
# File 'lib/geometer/point.rb', line 3

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

#invertObject Also known as: -@



7
8
9
# File 'lib/geometer/point.rb', line 7

def invert
  Point.new(-x,-y)
end

#scale(sz) ⇒ Object Also known as: *



12
13
14
# File 'lib/geometer/point.rb', line 12

def scale(sz)
  Point.new(x*sz,y*sz)
end

#to_iObject



27
28
29
# File 'lib/geometer/point.rb', line 27

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

#translate(other_point) ⇒ Object



22
23
24
25
# File 'lib/geometer/point.rb', line 22

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