working more

This commit is contained in:
2025-10-02 15:31:30 -06:00
parent 72bd5fb9c0
commit ed3cd08130
6 changed files with 67 additions and 47 deletions
+41
View File
@@ -0,0 +1,41 @@
# 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
require 'byebug';debugger
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
def to_s
return "(#{@x_pos}, #{y_pos})"
end
end