Class: Coordinates
- Inherits:
-
Object
- Object
- Coordinates
- Includes:
- Comparable
- Defined in:
- lib/software_challenge_client/coordinates.rb
Overview
Einfache kartesische Koordinaten
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
-
.doubled_to_oddr(c) ⇒ Object
Konvertiert c in das odd-r Koordinatensystem.
-
.doubled_to_oddr_int(x, y) ⇒ Object
Konvertiert (x, y) in das doubled Koordinatensystem.
-
.oddr_to_doubled(c) ⇒ Object
Konvertiert (x, y) in das doubled Koordinatensystem.
-
.oddr_to_doubled_int(x, y) ⇒ Object
Konvertiert c in das doubled Koordinatensystem.
-
.origin ⇒ Object
Gibt die Ursprungs-Koordinaten (0, 0) zurück.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(x, y) ⇒ Coordinates
constructor
Erstellt neue leere Koordinaten.
- #inspect ⇒ Object
-
#to_s ⇒ Object
Gibt eine textuelle Repräsentation der Koordinaten aus.
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
#x ⇒ Object (readonly)
Returns the value of attribute x.
6 7 8 |
# File 'lib/software_challenge_client/coordinates.rb', line 6 def x @x end |
#y ⇒ Object (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
.doubled_to_oddr(c) ⇒ Object
Konvertiert c in das odd-r Koordinatensystem.
38 39 40 |
# File 'lib/software_challenge_client/coordinates.rb', line 38 def self.doubled_to_oddr(c) self.doubled_to_oddr_int(c.x, c.y) end |
.doubled_to_oddr_int(x, y) ⇒ Object
Konvertiert (x, y) in das doubled Koordinatensystem.
45 46 47 |
# File 'lib/software_challenge_client/coordinates.rb', line 45 def self.doubled_to_oddr_int(x, y) Coordinates.new((x / 2.0).ceil() - y % 2, y) end |
.oddr_to_doubled(c) ⇒ Object
Konvertiert (x, y) in das doubled Koordinatensystem.
26 27 28 |
# File 'lib/software_challenge_client/coordinates.rb', line 26 def self.oddr_to_doubled(c) self.oddr_to_doubled_int(c.x, c.y) end |
.oddr_to_doubled_int(x, y) ⇒ Object
Konvertiert c in das doubled Koordinatensystem.
32 33 34 |
# File 'lib/software_challenge_client/coordinates.rb', line 32 def self.oddr_to_doubled_int(x, y) Coordinates.new(x * 2 + y % 2, y) end |
.origin ⇒ Object
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
59 60 61 |
# File 'lib/software_challenge_client/coordinates.rb', line 59 def +(other) Coordinates.new(x + other.x, y + other.y) end |
#<=>(other) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/software_challenge_client/coordinates.rb', line 49 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 |
#inspect ⇒ Object
68 69 70 |
# File 'lib/software_challenge_client/coordinates.rb', line 68 def inspect to_s end |
#to_s ⇒ Object
Gibt eine textuelle Repräsentation der Koordinaten aus.
64 65 66 |
# File 'lib/software_challenge_client/coordinates.rb', line 64 def to_s "(#{x}, #{y})" end |