Class: Coordinates

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/software_challenge_client/coordinates.rb

Overview

Einfache kartesische Koordinaten

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Coordinates

Erstellt neue leere Koordinaten.



9
10
11
12
# File 'lib/software_challenge_client/coordinates.rb', line 9

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

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



6
7
8
# File 'lib/software_challenge_client/coordinates.rb', line 6

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



6
7
8
# File 'lib/software_challenge_client/coordinates.rb', line 6

def y
  @y
end

Class Method Details

.originObject

Gibt die Ursprungs-Koordinaten (0, 0) zurück.



19
20
21
# File 'lib/software_challenge_client/coordinates.rb', line 19

def self.origin
  Coordinates.new(0, 0)
end

Instance Method Details

#+(other) ⇒ Object



33
34
35
# File 'lib/software_challenge_client/coordinates.rb', line 33

def +(other)
  Coordinates.new(x + other.x, y + other.y)
end

#<=>(other) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/software_challenge_client/coordinates.rb', line 23

def <=>(other)
  xComp = x <=> other.x
  yComp = y <=> other.y
  if xComp == 0
    yComp
  else
    xComp
  end
end

#==(other) ⇒ Object



14
15
16
# File 'lib/software_challenge_client/coordinates.rb', line 14

def ==(other)
  x == other.x && y == other.y
end

#inspectObject



42
43
44
# File 'lib/software_challenge_client/coordinates.rb', line 42

def inspect
  to_s
end

#to_sObject

Gibt eine textuelle Repräsentation der Koordinaten aus.



38
39
40
# File 'lib/software_challenge_client/coordinates.rb', line 38

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