Sha256: 8d288a9fd57f7904b041fce0f8e1b8ff623072f517f0722895c82f69c837340a

Contents?: true

Size: 556 Bytes

Versions: 2

Compression:

Stored size: 556 Bytes

Contents

# CubeCoordinates erleichtern viele Berechnungen auf einem hexagonalen Spielfeld. Siehe
# https://www.redblobgames.com/grids/hexagons/#coordinates-cube
class CubeCoordinates

  attr_reader :x, :y, :z

  def initialize(x, y, z = nil)
    @x = x
    @y = y
    @z = z.nil? ? -x - y : z
    throw InvalidArgumentException("sum of coordinates #{@x}, #{@y}, #{@z} have to be equal 0") if @x + @y + @z != 0
  end

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

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

  def inspect
    to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
software_challenge_client-20.2.4 lib/software_challenge_client/cube_coordinates.rb
software_challenge_client-20.2.3 lib/software_challenge_client/cube_coordinates.rb