All files / src/functions/convertXYZ xyz2Glyphs.ts

96.66% Statements 29/30
87.5% Branches 7/8
100% Functions 1/1
96.66% Lines 29/30

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    1x 13x 13x 13x 13x 13x 13x 13x 13x 2x 13x 11x 11x 13x 2x 13x 11x 11x 13x   13x 13x 13x   13x 13x 13x 13x 13x   13x 13x  
import type { VoxelCoordinates } from '@/types/voxelTypes';
 
export function xyz2Glyphs({
  VoxelX,
  VoxelY,
  VoxelZ,
  SolarSystemIndex,
  PlanetIndex,
}: VoxelCoordinates): string {
  let x_glyphs, y_glyphs, z_glyphs;
  if (VoxelX < 0) {
    x_glyphs = VoxelX + 4096;
  } else {
    x_glyphs = VoxelX;
  }
  if (VoxelZ < 0) {
    z_glyphs = VoxelZ + 4096;
  } else {
    z_glyphs = VoxelZ;
  }
  if (VoxelY < 0) {
    y_glyphs = VoxelY + 256;
  } else {
    y_glyphs = VoxelY;
  }
 
  const hexAddress = [SolarSystemIndex, y_glyphs, z_glyphs, x_glyphs];
  const address = hexAddress.map((coord) => coord.toString(16).toUpperCase());
  const glyphY = address.splice(1, 1)[0].padStart(2, '0');
  const paddedAddress = address.map((coord) => coord.padStart(3, '0'));
  paddedAddress.splice(1, 0, glyphY);
 
  return `${PlanetIndex}${paddedAddress.join('')}`;
}