37 lines
1013 B
Ruby
37 lines
1013 B
Ruby
# Nathan Hinton 2 Oct 2025
|
|
|
|
|
|
# A helper class for storing and converting universe point formats:
|
|
class Position
|
|
attr_reader :x_pos, :y_pos, :a, :b, :c
|
|
def initialize(*args)
|
|
if args.length == 2
|
|
# initialize with x, y position:
|
|
if args.sum.odd?
|
|
raise ArgumentError.new('A position created in (x, y) must sum to an even number!')
|
|
end
|
|
x_pos = args[0]
|
|
y_pos = args[1]
|
|
elsif args.length == 3
|
|
# initialize with a, b, c position
|
|
raise NotImplementedError.new('(a, b, c) positioning not implimented!')
|
|
else
|
|
raise ArgumentError.new('Creation of a position requires two or three integer args for a position.')
|
|
end
|
|
end
|
|
|
|
# Returns the corrdinates in the 2d plane in a 3 axis notation.
|
|
#
|
|
# @return [Array<Integer>] The (a, b, c) position
|
|
def two_d_hexagonal
|
|
return [a, b, c]
|
|
end
|
|
|
|
# Returns the coordinates in the 2d plane
|
|
#
|
|
# @return [Array<Integer>] The (x, y) position
|
|
def two_d_cartesian
|
|
return [x_pos, y_pos]
|
|
end
|
|
end
|