All files / src/converter/galactic galacticCoordinate.ts

100% Statements 27/27
100% Branches 3/3
100% Functions 3/3
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 391x 1x 1x 1x         1x             1x 4x 4x 4x 4x 1x 1x   1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 1x 1x 1x 4x 4x  
import { baseConverter } from '@/converter/baseConverter';
import { coords2Glyphs } from '@/functions/convertCoords/coords2Glyphs';
import { coords2XYZ } from '@/functions/convertCoords/coords2XYZ';
import { handleGalacticCoordinate } from '@/helper/handleGalacticInput';
import type { IConverterMethods } from '@/types/converter';
import type { GalacticInput } from '@/types/galacticTypes';
import type { GlyphOutput } from '@/types/glyphTypes';
import type { VoxelOutput } from '@/types/voxelTypes';
import { GalacticInputValidator } from '@/validation/galacticInputValidation';
 
/**
 * A converter that takes a Galactic coordinate and returns functions to convert to other portal types.
 * @param input multiple ways to input Galactic coordinates, see {@link GalacticInput| GalacticInput}
 * @returns functions defined in {@link IConverterMethods| IConverterMethods}
 */
export const GalacticCoordinate = (input: GalacticInput): Omit<IConverterMethods, 'toGalacticCoordinates'> => ({
  toGlyph: baseConverter<GalacticInput, GlyphOutput>({
    input,
    inputValidator: GalacticInputValidator,
    converter: (input: GalacticInput) => {
      const inputCoords = handleGalacticCoordinate(input);
      const result = coords2Glyphs(inputCoords);
 
      return {
        code: result,
        hexArray: result.split(''),
      };
    },
  }),
  toVoxel: baseConverter<GalacticInput, VoxelOutput>({
    input,
    inputValidator: GalacticInputValidator,
    converter: (input: GalacticInput) => {
      const inputCoords = handleGalacticCoordinate(input);
      return coords2XYZ(inputCoords);
    },
  }),
});