Class: Ein::Position

Inherits:
Object
  • Object
show all
Defined in:
lib/ein/position.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Position

Returns a new instance of Position.



10
11
12
# File 'lib/ein/position.rb', line 10

def initialize(x,y)
  @x, @y = x,y
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/ein/position.rb', line 8

def x
  @x
end

#yObject

Returns the value of attribute y.



8
9
10
# File 'lib/ein/position.rb', line 8

def y
  @y
end

Instance Method Details

#distance_to(position) ⇒ Object



14
15
16
# File 'lib/ein/position.rb', line 14

def distance_to(position)
  Math.sqrt((@x - position.x)**2 + (@y - position.y)**2) # Pythagoras, miss you buddy. RIP
end

#roundObject



18
19
20
# File 'lib/ein/position.rb', line 18

def round
  Position.new(@x.round, @y.round)
end

#to_sObject



22
23
24
# File 'lib/ein/position.rb', line 22

def to_s
  "x: #@x, y: #@y"
end