# A number of data tables, mainly used for coordinate conversion

const x2pix = [
    0,
    1,
    4,
    5,
    16,
    17,
    20,
    21,
    64,
    65,
    68,
    69,
    80,
    81,
    84,
    85,
    256,
    257,
    260,
    261,
    272,
    273,
    276,
    277,
    320,
    321,
    324,
    325,
    336,
    337,
    340,
    341,
    1024,
    1025,
    1028,
    1029,
    1040,
    1041,
    1044,
    1045,
    1088,
    1089,
    1092,
    1093,
    1104,
    1105,
    1108,
    1109,
    1280,
    1281,
    1284,
    1285,
    1296,
    1297,
    1300,
    1301,
    1344,
    1345,
    1348,
    1349,
    1360,
    1361,
    1364,
    1365,
    4096,
    4097,
    4100,
    4101,
    4112,
    4113,
    4116,
    4117,
    4160,
    4161,
    4164,
    4165,
    4176,
    4177,
    4180,
    4181,
    4352,
    4353,
    4356,
    4357,
    4368,
    4369,
    4372,
    4373,
    4416,
    4417,
    4420,
    4421,
    4432,
    4433,
    4436,
    4437,
    5120,
    5121,
    5124,
    5125,
    5136,
    5137,
    5140,
    5141,
    5184,
    5185,
    5188,
    5189,
    5200,
    5201,
    5204,
    5205,
    5376,
    5377,
    5380,
    5381,
    5392,
    5393,
    5396,
    5397,
    5440,
    5441,
    5444,
    5445,
    5456,
    5457,
    5460,
    5461,
]

################################################################################

const y2pix = [
    0,
    2,
    8,
    10,
    32,
    34,
    40,
    42,
    128,
    130,
    136,
    138,
    160,
    162,
    168,
    170,
    512,
    514,
    520,
    522,
    544,
    546,
    552,
    554,
    640,
    642,
    648,
    650,
    672,
    674,
    680,
    682,
    2048,
    2050,
    2056,
    2058,
    2080,
    2082,
    2088,
    2090,
    2176,
    2178,
    2184,
    2186,
    2208,
    2210,
    2216,
    2218,
    2560,
    2562,
    2568,
    2570,
    2592,
    2594,
    2600,
    2602,
    2688,
    2690,
    2696,
    2698,
    2720,
    2722,
    2728,
    2730,
    8192,
    8194,
    8200,
    8202,
    8224,
    8226,
    8232,
    8234,
    8320,
    8322,
    8328,
    8330,
    8352,
    8354,
    8360,
    8362,
    8704,
    8706,
    8712,
    8714,
    8736,
    8738,
    8744,
    8746,
    8832,
    8834,
    8840,
    8842,
    8864,
    8866,
    8872,
    8874,
    10240,
    10242,
    10248,
    10250,
    10272,
    10274,
    10280,
    10282,
    10368,
    10370,
    10376,
    10378,
    10400,
    10402,
    10408,
    10410,
    10752,
    10754,
    10760,
    10762,
    10784,
    10786,
    10792,
    10794,
    10880,
    10882,
    10888,
    10890,
    10912,
    10914,
    10920,
    10922,
]

################################################################################

const pix2x = [
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    0,
    1,
    0,
    1,
    2,
    3,
    2,
    3,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    4,
    5,
    4,
    5,
    6,
    7,
    6,
    7,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    8,
    9,
    8,
    9,
    10,
    11,
    10,
    11,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    12,
    13,
    12,
    13,
    14,
    15,
    14,
    15,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    16,
    17,
    16,
    17,
    18,
    19,
    18,
    19,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    20,
    21,
    20,
    21,
    22,
    23,
    22,
    23,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    24,
    25,
    24,
    25,
    26,
    27,
    26,
    27,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
    28,
    29,
    28,
    29,
    30,
    31,
    30,
    31,
]

const pix2y = [
    0,
    0,
    1,
    1,
    0,
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    2,
    2,
    3,
    3,
    0,
    0,
    1,
    1,
    0,
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    2,
    2,
    3,
    3,
    4,
    4,
    5,
    5,
    4,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    6,
    6,
    7,
    7,
    4,
    4,
    5,
    5,
    4,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    6,
    6,
    7,
    7,
    0,
    0,
    1,
    1,
    0,
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    2,
    2,
    3,
    3,
    0,
    0,
    1,
    1,
    0,
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    2,
    2,
    3,
    3,
    4,
    4,
    5,
    5,
    4,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    6,
    6,
    7,
    7,
    4,
    4,
    5,
    5,
    4,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    6,
    6,
    7,
    7,
    8,
    8,
    9,
    9,
    8,
    8,
    9,
    9,
    10,
    10,
    11,
    11,
    10,
    10,
    11,
    11,
    8,
    8,
    9,
    9,
    8,
    8,
    9,
    9,
    10,
    10,
    11,
    11,
    10,
    10,
    11,
    11,
    12,
    12,
    13,
    13,
    12,
    12,
    13,
    13,
    14,
    14,
    15,
    15,
    14,
    14,
    15,
    15,
    12,
    12,
    13,
    13,
    12,
    12,
    13,
    13,
    14,
    14,
    15,
    15,
    14,
    14,
    15,
    15,
    8,
    8,
    9,
    9,
    8,
    8,
    9,
    9,
    10,
    10,
    11,
    11,
    10,
    10,
    11,
    11,
    8,
    8,
    9,
    9,
    8,
    8,
    9,
    9,
    10,
    10,
    11,
    11,
    10,
    10,
    11,
    11,
    12,
    12,
    13,
    13,
    12,
    12,
    13,
    13,
    14,
    14,
    15,
    15,
    14,
    14,
    15,
    15,
    12,
    12,
    13,
    13,
    12,
    12,
    13,
    13,
    14,
    14,
    15,
    15,
    14,
    14,
    15,
    15,
    0,
    0,
    1,
    1,
    0,
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    2,
    2,
    3,
    3,
    0,
    0,
    1,
    1,
    0,
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    2,
    2,
    3,
    3,
    4,
    4,
    5,
    5,
    4,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    6,
    6,
    7,
    7,
    4,
    4,
    5,
    5,
    4,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    6,
    6,
    7,
    7,
    0,
    0,
    1,
    1,
    0,
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    2,
    2,
    3,
    3,
    0,
    0,
    1,
    1,
    0,
    0,
    1,
    1,
    2,
    2,
    3,
    3,
    2,
    2,
    3,
    3,
    4,
    4,
    5,
    5,
    4,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    6,
    6,
    7,
    7,
    4,
    4,
    5,
    5,
    4,
    4,
    5,
    5,
    6,
    6,
    7,
    7,
    6,
    6,
    7,
    7,
    8,
    8,
    9,
    9,
    8,
    8,
    9,
    9,
    10,
    10,
    11,
    11,
    10,
    10,
    11,
    11,
    8,
    8,
    9,
    9,
    8,
    8,
    9,
    9,
    10,
    10,
    11,
    11,
    10,
    10,
    11,
    11,
    12,
    12,
    13,
    13,
    12,
    12,
    13,
    13,
    14,
    14,
    15,
    15,
    14,
    14,
    15,
    15,
    12,
    12,
    13,
    13,
    12,
    12,
    13,
    13,
    14,
    14,
    15,
    15,
    14,
    14,
    15,
    15,
    8,
    8,
    9,
    9,
    8,
    8,
    9,
    9,
    10,
    10,
    11,
    11,
    10,
    10,
    11,
    11,
    8,
    8,
    9,
    9,
    8,
    8,
    9,
    9,
    10,
    10,
    11,
    11,
    10,
    10,
    11,
    11,
    12,
    12,
    13,
    13,
    12,
    12,
    13,
    13,
    14,
    14,
    15,
    15,
    14,
    14,
    15,
    15,
    12,
    12,
    13,
    13,
    12,
    12,
    13,
    13,
    14,
    14,
    15,
    15,
    14,
    14,
    15,
    15,
    16,
    16,
    17,
    17,
    16,
    16,
    17,
    17,
    18,
    18,
    19,
    19,
    18,
    18,
    19,
    19,
    16,
    16,
    17,
    17,
    16,
    16,
    17,
    17,
    18,
    18,
    19,
    19,
    18,
    18,
    19,
    19,
    20,
    20,
    21,
    21,
    20,
    20,
    21,
    21,
    22,
    22,
    23,
    23,
    22,
    22,
    23,
    23,
    20,
    20,
    21,
    21,
    20,
    20,
    21,
    21,
    22,
    22,
    23,
    23,
    22,
    22,
    23,
    23,
    16,
    16,
    17,
    17,
    16,
    16,
    17,
    17,
    18,
    18,
    19,
    19,
    18,
    18,
    19,
    19,
    16,
    16,
    17,
    17,
    16,
    16,
    17,
    17,
    18,
    18,
    19,
    19,
    18,
    18,
    19,
    19,
    20,
    20,
    21,
    21,
    20,
    20,
    21,
    21,
    22,
    22,
    23,
    23,
    22,
    22,
    23,
    23,
    20,
    20,
    21,
    21,
    20,
    20,
    21,
    21,
    22,
    22,
    23,
    23,
    22,
    22,
    23,
    23,
    24,
    24,
    25,
    25,
    24,
    24,
    25,
    25,
    26,
    26,
    27,
    27,
    26,
    26,
    27,
    27,
    24,
    24,
    25,
    25,
    24,
    24,
    25,
    25,
    26,
    26,
    27,
    27,
    26,
    26,
    27,
    27,
    28,
    28,
    29,
    29,
    28,
    28,
    29,
    29,
    30,
    30,
    31,
    31,
    30,
    30,
    31,
    31,
    28,
    28,
    29,
    29,
    28,
    28,
    29,
    29,
    30,
    30,
    31,
    31,
    30,
    30,
    31,
    31,
    24,
    24,
    25,
    25,
    24,
    24,
    25,
    25,
    26,
    26,
    27,
    27,
    26,
    26,
    27,
    27,
    24,
    24,
    25,
    25,
    24,
    24,
    25,
    25,
    26,
    26,
    27,
    27,
    26,
    26,
    27,
    27,
    28,
    28,
    29,
    29,
    28,
    28,
    29,
    29,
    30,
    30,
    31,
    31,
    30,
    30,
    31,
    31,
    28,
    28,
    29,
    29,
    28,
    28,
    29,
    29,
    30,
    30,
    31,
    31,
    30,
    30,
    31,
    31,
    16,
    16,
    17,
    17,
    16,
    16,
    17,
    17,
    18,
    18,
    19,
    19,
    18,
    18,
    19,
    19,
    16,
    16,
    17,
    17,
    16,
    16,
    17,
    17,
    18,
    18,
    19,
    19,
    18,
    18,
    19,
    19,
    20,
    20,
    21,
    21,
    20,
    20,
    21,
    21,
    22,
    22,
    23,
    23,
    22,
    22,
    23,
    23,
    20,
    20,
    21,
    21,
    20,
    20,
    21,
    21,
    22,
    22,
    23,
    23,
    22,
    22,
    23,
    23,
    16,
    16,
    17,
    17,
    16,
    16,
    17,
    17,
    18,
    18,
    19,
    19,
    18,
    18,
    19,
    19,
    16,
    16,
    17,
    17,
    16,
    16,
    17,
    17,
    18,
    18,
    19,
    19,
    18,
    18,
    19,
    19,
    20,
    20,
    21,
    21,
    20,
    20,
    21,
    21,
    22,
    22,
    23,
    23,
    22,
    22,
    23,
    23,
    20,
    20,
    21,
    21,
    20,
    20,
    21,
    21,
    22,
    22,
    23,
    23,
    22,
    22,
    23,
    23,
    24,
    24,
    25,
    25,
    24,
    24,
    25,
    25,
    26,
    26,
    27,
    27,
    26,
    26,
    27,
    27,
    24,
    24,
    25,
    25,
    24,
    24,
    25,
    25,
    26,
    26,
    27,
    27,
    26,
    26,
    27,
    27,
    28,
    28,
    29,
    29,
    28,
    28,
    29,
    29,
    30,
    30,
    31,
    31,
    30,
    30,
    31,
    31,
    28,
    28,
    29,
    29,
    28,
    28,
    29,
    29,
    30,
    30,
    31,
    31,
    30,
    30,
    31,
    31,
    24,
    24,
    25,
    25,
    24,
    24,
    25,
    25,
    26,
    26,
    27,
    27,
    26,
    26,
    27,
    27,
    24,
    24,
    25,
    25,
    24,
    24,
    25,
    25,
    26,
    26,
    27,
    27,
    26,
    26,
    27,
    27,
    28,
    28,
    29,
    29,
    28,
    28,
    29,
    29,
    30,
    30,
    31,
    31,
    30,
    30,
    31,
    31,
    28,
    28,
    29,
    29,
    28,
    28,
    29,
    29,
    30,
    30,
    31,
    31,
    30,
    30,
    31,
    31,
]
