Sha256: 7002c1db49759672379923d0b1a3b54f9df6428925853b4d738a5002065cf3b7
Contents?: true
Size: 708 Bytes
Versions: 9
Compression:
Stored size: 708 Bytes
Contents
# frozen_string_literal: true # Einfache kartesische Koordinaten class Coordinates include Comparable attr_reader :x, :y # Erstellt neue leere Koordinaten. def initialize(x, y) @x = x @y = y end def ==(other) x == other.x && y == other.y end # Gibt die Ursprungs-Koordinaten (0, 0) zurück. def self.origin Coordinates.new(0, 0) end def <=>(other) xComp = x <=> other.x yComp = y <=> other.y if xComp == 0 yComp else xComp end end def +(other) Coordinates.new(x + other.x, y + other.y) end # Gibt eine textuelle Repräsentation der Koordinaten aus. def to_s "(#{x}, #{y})" end def inspect to_s end end
Version data entries
9 entries across 9 versions & 1 rubygems