1 line
10 KiB
JSON
1 line
10 KiB
JSON
{"ast":null,"code":"/*!\n * (C) Ionic http://ionicframework.com - MIT License\n */\n\n/**\n * Based on:\n * https://stackoverflow.com/questions/7348009/y-coordinate-for-a-given-x-cubic-bezier\n * https://math.stackexchange.com/questions/26846/is-there-an-explicit-form-for-cubic-b%C3%A9zier-curves\n * TODO: Reduce rounding error\n */\n\n/**\n * EXPERIMENTAL\n * Given a cubic-bezier curve, get the x value (time) given\n * the y value (progression).\n * Ex: cubic-bezier(0.32, 0.72, 0, 1);\n * P0: (0, 0)\n * P1: (0.32, 0.72)\n * P2: (0, 1)\n * P3: (1, 1)\n *\n * If you give a cubic bezier curve that never reaches the\n * provided progression, this function will return an empty array.\n */\nconst getTimeGivenProgression = (p0, p1, p2, p3, progression) => {\n return solveCubicBezier(p0[1], p1[1], p2[1], p3[1], progression).map(tValue => {\n return solveCubicParametricEquation(p0[0], p1[0], p2[0], p3[0], tValue);\n });\n};\n/**\n * Solve a cubic equation in one dimension (time)\n */\n\n\nconst solveCubicParametricEquation = (p0, p1, p2, p3, t) => {\n const partA = 3 * p1 * Math.pow(t - 1, 2);\n const partB = -3 * p2 * t + 3 * p2 + p3 * t;\n const partC = p0 * Math.pow(t - 1, 3);\n return t * (partA + t * partB) - partC;\n};\n/**\n * Find the `t` value for a cubic bezier using Cardano's formula\n */\n\n\nconst solveCubicBezier = (p0, p1, p2, p3, refPoint) => {\n p0 -= refPoint;\n p1 -= refPoint;\n p2 -= refPoint;\n p3 -= refPoint;\n const roots = solveCubicEquation(p3 - 3 * p2 + 3 * p1 - p0, 3 * p2 - 6 * p1 + 3 * p0, 3 * p1 - 3 * p0, p0);\n return roots.filter(root => root >= 0 && root <= 1);\n};\n\nconst solveQuadraticEquation = (a, b, c) => {\n const discriminant = b * b - 4 * a * c;\n\n if (discriminant < 0) {\n return [];\n } else {\n return [(-b + Math.sqrt(discriminant)) / (2 * a), (-b - Math.sqrt(discriminant)) / (2 * a)];\n }\n};\n\nconst solveCubicEquation = (a, b, c, d) => {\n if (a === 0) {\n return solveQuadraticEquation(b, c, d);\n }\n\n b /= a;\n c /= a;\n d /= a;\n const p = (3 * c - b * b) / 3;\n const q = (2 * b * b * b - 9 * b * c + 27 * d) / 27;\n\n if (p === 0) {\n return [Math.pow(-q, 1 / 3)];\n } else if (q === 0) {\n return [Math.sqrt(-p), -Math.sqrt(-p)];\n }\n\n const discriminant = Math.pow(q / 2, 2) + Math.pow(p / 3, 3);\n\n if (discriminant === 0) {\n return [Math.pow(q / 2, 1 / 2) - b / 3];\n } else if (discriminant > 0) {\n return [Math.pow(-(q / 2) + Math.sqrt(discriminant), 1 / 3) - Math.pow(q / 2 + Math.sqrt(discriminant), 1 / 3) - b / 3];\n }\n\n const r = Math.sqrt(Math.pow(-(p / 3), 3));\n const phi = Math.acos(-(q / (2 * Math.sqrt(Math.pow(-(p / 3), 3)))));\n const s = 2 * Math.pow(r, 1 / 3);\n return [s * Math.cos(phi / 3) - b / 3, s * Math.cos((phi + 2 * Math.PI) / 3) - b / 3, s * Math.cos((phi + 4 * Math.PI) / 3) - b / 3];\n};\n\nexport { getTimeGivenProgression as g };","map":{"version":3,"names":["getTimeGivenProgression","p0","p1","p2","p3","progression","solveCubicBezier","map","tValue","solveCubicParametricEquation","t","partA","Math","pow","partB","partC","refPoint","roots","solveCubicEquation","filter","root","solveQuadraticEquation","a","b","c","discriminant","sqrt","d","p","q","r","phi","acos","s","cos","PI","g"],"sources":["D:/MobileDev/WRB/WrenchBoard2023a/node_modules/@ionic/core/dist/esm/cubic-bezier-c313947a.js"],"sourcesContent":["/*!\n * (C) Ionic http://ionicframework.com - MIT License\n */\n/**\n * Based on:\n * https://stackoverflow.com/questions/7348009/y-coordinate-for-a-given-x-cubic-bezier\n * https://math.stackexchange.com/questions/26846/is-there-an-explicit-form-for-cubic-b%C3%A9zier-curves\n * TODO: Reduce rounding error\n */\n/**\n * EXPERIMENTAL\n * Given a cubic-bezier curve, get the x value (time) given\n * the y value (progression).\n * Ex: cubic-bezier(0.32, 0.72, 0, 1);\n * P0: (0, 0)\n * P1: (0.32, 0.72)\n * P2: (0, 1)\n * P3: (1, 1)\n *\n * If you give a cubic bezier curve that never reaches the\n * provided progression, this function will return an empty array.\n */\nconst getTimeGivenProgression = (p0, p1, p2, p3, progression) => {\n return solveCubicBezier(p0[1], p1[1], p2[1], p3[1], progression).map((tValue) => {\n return solveCubicParametricEquation(p0[0], p1[0], p2[0], p3[0], tValue);\n });\n};\n/**\n * Solve a cubic equation in one dimension (time)\n */\nconst solveCubicParametricEquation = (p0, p1, p2, p3, t) => {\n const partA = 3 * p1 * Math.pow(t - 1, 2);\n const partB = -3 * p2 * t + 3 * p2 + p3 * t;\n const partC = p0 * Math.pow(t - 1, 3);\n return t * (partA + t * partB) - partC;\n};\n/**\n * Find the `t` value for a cubic bezier using Cardano's formula\n */\nconst solveCubicBezier = (p0, p1, p2, p3, refPoint) => {\n p0 -= refPoint;\n p1 -= refPoint;\n p2 -= refPoint;\n p3 -= refPoint;\n const roots = solveCubicEquation(p3 - 3 * p2 + 3 * p1 - p0, 3 * p2 - 6 * p1 + 3 * p0, 3 * p1 - 3 * p0, p0);\n return roots.filter((root) => root >= 0 && root <= 1);\n};\nconst solveQuadraticEquation = (a, b, c) => {\n const discriminant = b * b - 4 * a * c;\n if (discriminant < 0) {\n return [];\n }\n else {\n return [(-b + Math.sqrt(discriminant)) / (2 * a), (-b - Math.sqrt(discriminant)) / (2 * a)];\n }\n};\nconst solveCubicEquation = (a, b, c, d) => {\n if (a === 0) {\n return solveQuadraticEquation(b, c, d);\n }\n b /= a;\n c /= a;\n d /= a;\n const p = (3 * c - b * b) / 3;\n const q = (2 * b * b * b - 9 * b * c + 27 * d) / 27;\n if (p === 0) {\n return [Math.pow(-q, 1 / 3)];\n }\n else if (q === 0) {\n return [Math.sqrt(-p), -Math.sqrt(-p)];\n }\n const discriminant = Math.pow(q / 2, 2) + Math.pow(p / 3, 3);\n if (discriminant === 0) {\n return [Math.pow(q / 2, 1 / 2) - b / 3];\n }\n else if (discriminant > 0) {\n return [\n Math.pow(-(q / 2) + Math.sqrt(discriminant), 1 / 3) - Math.pow(q / 2 + Math.sqrt(discriminant), 1 / 3) - b / 3,\n ];\n }\n const r = Math.sqrt(Math.pow(-(p / 3), 3));\n const phi = Math.acos(-(q / (2 * Math.sqrt(Math.pow(-(p / 3), 3)))));\n const s = 2 * Math.pow(r, 1 / 3);\n return [\n s * Math.cos(phi / 3) - b / 3,\n s * Math.cos((phi + 2 * Math.PI) / 3) - b / 3,\n s * Math.cos((phi + 4 * Math.PI) / 3) - b / 3,\n ];\n};\n\nexport { getTimeGivenProgression as g };\n"],"mappings":"AAAA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,uBAAuB,GAAG,CAACC,EAAD,EAAKC,EAAL,EAASC,EAAT,EAAaC,EAAb,EAAiBC,WAAjB,KAAiC;EAC/D,OAAOC,gBAAgB,CAACL,EAAE,CAAC,CAAD,CAAH,EAAQC,EAAE,CAAC,CAAD,CAAV,EAAeC,EAAE,CAAC,CAAD,CAAjB,EAAsBC,EAAE,CAAC,CAAD,CAAxB,EAA6BC,WAA7B,CAAhB,CAA0DE,GAA1D,CAA+DC,MAAD,IAAY;IAC/E,OAAOC,4BAA4B,CAACR,EAAE,CAAC,CAAD,CAAH,EAAQC,EAAE,CAAC,CAAD,CAAV,EAAeC,EAAE,CAAC,CAAD,CAAjB,EAAsBC,EAAE,CAAC,CAAD,CAAxB,EAA6BI,MAA7B,CAAnC;EACD,CAFM,CAAP;AAGD,CAJD;AAKA;AACA;AACA;;;AACA,MAAMC,4BAA4B,GAAG,CAACR,EAAD,EAAKC,EAAL,EAASC,EAAT,EAAaC,EAAb,EAAiBM,CAAjB,KAAuB;EAC1D,MAAMC,KAAK,GAAG,IAAIT,EAAJ,GAASU,IAAI,CAACC,GAAL,CAASH,C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