{"version":3,"file":"aruco-marker.cjs","sources":["../src/aruco-marker.ts"],"sourcesContent":["// Based on https://github.com/rmsalinas/aruco/blob/master/trunk/src/arucofidmarkers.cpp\n\n/** Generate a marker as a 5x5 matrix of 0s and 1s. */\nexport function arucoMarkerMatrix(id: number) {\n\tif (id < 0 || id > 1023) {\n\t\tthrow new RangeError('Marker ID must be in the range [0..1023]');\n\t}\n\n\tconst ids = [16, 23, 9, 14];\n\tlet index = 0,\n\t\tval = 0,\n\t\tx = 0,\n\t\ty = 0;\n\tconst marker = [\n\t\t[0, 0, 0, 0, 0],\n\t\t[0, 0, 0, 0, 0],\n\t\t[0, 0, 0, 0, 0],\n\t\t[0, 0, 0, 0, 0],\n\t\t[0, 0, 0, 0, 0],\n\t];\n\n\tfor (y = 0; y < 5; y++) {\n\t\tindex = (id >> (2 * (4 - y))) & 3;\n\t\tval = ids[index];\n\t\tfor (x = 0; x < 5; x++) {\n\t\t\tmarker[x][y] = (val >> (4 - x)) & 1;\n\t\t}\n\t}\n\n\treturn marker;\n}\n\n/**\n * Create an SVG image of the marker, as a string.\n * Optionally pass a size (in any SVG-compatible units) or leave it out to size it on your own.\n */\nexport function arucoToSVGString(id: number, size?: number | string) {\n\tlet x = 0,\n\t\ty = 0;\n\tconst marker = arucoMarkerMatrix(id);\n\tlet image = '';\n\n\tif (size) {\n\t\tsize = 'height=\"' + size + '\" width=\"' + size + '\"';\n\t} else {\n\t\tsize = '';\n\t}\n\n\timage =\n\t\t'<svg ' +\n\t\tsize +\n\t\t' viewBox=\"0 0 7 7\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\\n' +\n\t\t'  <rect x=\"0\" y=\"0\" width=\"7\" height=\"7\" fill=\"black\"/>\\n';\n\n\tfor (y = 0; y < 5; y++) {\n\t\tfor (x = 0; x < 5; x++) {\n\t\t\tif (marker[x][y] === 1) {\n\t\t\t\timage +=\n\t\t\t\t\t'  <rect x=\"' +\n\t\t\t\t\t(x + 1) +\n\t\t\t\t\t'\" y=\"' +\n\t\t\t\t\t(y + 1) +\n\t\t\t\t\t'\" width=\"1\" height=\"1\" fill=\"white\" ' +\n\t\t\t\t\t// Slight stroke to get around aliasing issues with adjacent rectangles\n\t\t\t\t\t'stroke=\"white\" stroke-width=\"0.01\" />\\n';\n\t\t\t}\n\t\t}\n\t}\n\n\timage += '</svg>';\n\n\treturn image;\n}\n"],"names":["arucoMarkerMatrix","id","RangeError","ids","val","x","y","marker","size","image"],"mappings":"SAGgBA,EAAkBC,GACjC,GAAIA,EAAK,GAAKA,EAAK,KAClB,MAAU,IAAAC,WAAW,4CAGtB,IAAMC,EAAM,CAAC,GAAI,GAAI,EAAG,IAEvBC,EAAM,EACNC,EAAI,EACJC,EAAI,EACCC,EAAS,CACd,CAAC,EAAG,EAAG,EAAG,EAAG,GACb,CAAC,EAAG,EAAG,EAAG,EAAG,GACb,CAAC,EAAG,EAAG,EAAG,EAAG,GACb,CAAC,EAAG,EAAG,EAAG,EAAG,GACb,CAAC,EAAG,EAAG,EAAG,EAAG,IAGd,IAAKD,EAAI,EAAGA,EAAI,EAAGA,IAGlB,IADAF,EAAMD,EADGF,GAAO,GAAK,EAAIK,GAAO,GAE3BD,EAAI,EAAGA,EAAI,EAAGA,IAClBE,EAAOF,GAAGC,GAAMF,GAAQ,EAAIC,EAAM,EAIpC,OAAOE,CACR,sDAMgB,SAAiBN,EAAYO,GAC5C,IAAIH,EAAI,EACPC,EAAI,EACCC,EAASP,EAAkBC,GAC7BQ,EAAQ,GAcZ,IANAA,EACC,SANAD,EADGA,EACI,WAAaA,EAAO,YAAcA,EAAO,IAEzC,IAIP,kIAKIF,EAAI,EAAGA,EAAI,EAAGA,IAClB,IAAKD,EAAI,EAAGA,EAAI,EAAGA,IACG,IAAjBE,EAAOF,GAAGC,KACbG,GACC,eACCJ,EAAI,GACL,SACCC,EAAI,GAHL,+EAaJ,OAFAG,EAAS,QAGV"}