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)
  self.class.new(x + coordinate.x, y + coordinate.y)
end

#distance(coordinate) ⇒ Object



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

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

#mult(coeficient) ⇒ Object



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

def mult(coeficient)
  self.class.new(x * coeficient, y * coeficient)
end

#to_hashObject



21
22
23
# File 'lib/rubygoal/coordinate.rb', line 21

def to_hash
  { x: x, y: y }
end

#to_sObject



17
18
19
# File 'lib/rubygoal/coordinate.rb', line 17

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