Class: Rubygoal::Coordinate

Inherits:
Struct
  • Object
show all
Defined in:
lib/rubygoal/coordinate.rb

Direct Known Subclasses

Position, Velocity

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



4
5
6
# File 'lib/rubygoal/coordinate.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



4
5
6
# File 'lib/rubygoal/coordinate.rb', line 4

def y
  @y
end

Instance Method Details

#add(coordinate) ⇒ Object



9
10
11
# File 'lib/rubygoal/coordinate.rb', line 9

def add(coordinate)
  Coordinate.new(x + coordinate.x, y + coordinate.y)
end

#distance(coordinate) ⇒ Object



5
6
7
# File 'lib/rubygoal/coordinate.rb', line 5

def distance(coordinate)
  Gosu.distance(x, y, coordinate.x, coordinate.y)
end

#to_sObject



13
14
15
# File 'lib/rubygoal/coordinate.rb', line 13

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