Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03k
1import { Segment } from './parser.js';2 3// Normalize path to include only M, L, C, and Z commands4export function normalize(segments: Segment[]): Segment[] {5 const out: Segment[] = [];6 7 let lastType = '';8 let cx = 0, cy = 0;9 let subx = 0, suby = 0;10 let lcx = 0, lcy = 0;11 12 for (const { key, data } of segments) {13 switch (key) {14 case 'M':15 out.push({ key: 'M', data: [...data] });16 [cx, cy] = data;17 [subx, suby] = data;18 break;19 case 'C':20 out.push({ key: 'C', data: [...data] });21 cx = data[4];22 cy = data[5];23 lcx = data[2];24 lcy = data[3];25 break;26 case 'L':27 out.push({ key: 'L', data: [...data] });28 [cx, cy] = data;29 break;30 case 'H':31 cx = data[0];32 out.push({ key: 'L', data: [cx, cy] });33 break;34 case 'V':35 cy = data[0];36 out.push({ key: 'L', data: [cx, cy] });37 break;38 case 'S': {39 let cx1 = 0, cy1 = 0;40 if (lastType === 'C' || lastType === 'S') {41 cx1 = cx + (cx - lcx);42 cy1 = cy + (cy - lcy);43 } else {44 cx1 = cx;45 cy1 = cy;46 }47 out.push({ key: 'C', data: [cx1, cy1, ...data] });48 lcx = data[0];49 lcy = data[1];50 cx = data[2];51 cy = data[3];52 break;53 }54 case 'T': {55 const [x, y] = data;56 let x1 = 0, y1 = 0;57 if (lastType === 'Q' || lastType === 'T') {58 x1 = cx + (cx - lcx);59 y1 = cy + (cy - lcy);60 } else {61 x1 = cx;62 y1 = cy;63 }64 const cx1 = cx + 2 * (x1 - cx) / 3;65 const cy1 = cy + 2 * (y1 - cy) / 3;66 const cx2 = x + 2 * (x1 - x) / 3;67 const cy2 = y + 2 * (y1 - y) / 3;68 out.push({ key: 'C', data: [cx1, cy1, cx2, cy2, x, y] });69 lcx = x1;70 lcy = y1;71 cx = x;72 cy = y;73 break;74 }75 case 'Q': {76 const [x1, y1, x, y] = data;77 const cx1 = cx + 2 * (x1 - cx) / 3;78 const cy1 = cy + 2 * (y1 - cy) / 3;79 const cx2 = x + 2 * (x1 - x) / 3;80 const cy2 = y + 2 * (y1 - y) / 3;81 out.push({ key: 'C', data: [cx1, cy1, cx2, cy2, x, y] });82 lcx = x1;83 lcy = y1;84 cx = x;85 cy = y;86 break;87 }88 case 'A': {89 const r1 = Math.abs(data[0]);90 const r2 = Math.abs(data[1]);91 const angle = data[2];92 const largeArcFlag = data[3];93 const sweepFlag = data[4];94 const x = data[5];95 const y = data[6];96 if (r1 === 0 || r2 === 0) {97 out.push({ key: 'C', data: [cx, cy, x, y, x, y] });98 cx = x;99 cy = y;100 } else {101 if (cx !== x || cy !== y) {102 const curves: number[][] = arcToCubicCurves(cx, cy, x, y, r1, r2, angle, largeArcFlag, sweepFlag);103 curves.forEach(function (curve) {104 out.push({ key: 'C', data: curve });105 });106 cx = x;107 cy = y;108 }109 }110 break;111 }112 case 'Z':113 out.push({ key: 'Z', data: [] });114 cx = subx;115 cy = suby;116 break;117 }118 lastType = key;119 }120 return out;121}122 123function degToRad(degrees: number): number {124 return (Math.PI * degrees) / 180;125}126 127function rotate(x: number, y: number, angleRad: number): [number, number] {128 const X = x * Math.cos(angleRad) - y * Math.sin(angleRad);129 const Y = x * Math.sin(angleRad) + y * Math.cos(angleRad);130 return [X, Y];131}132 133function arcToCubicCurves(x1: number, y1: number, x2: number, y2: number, r1: number, r2: number, angle: number, largeArcFlag: number, sweepFlag: number, recursive?: number[]): number[][] {134 const angleRad = degToRad(angle);135 let params: number[][] = [];136 137 let f1 = 0, f2 = 0, cx = 0, cy = 0;138 if (recursive) {139 [f1, f2, cx, cy] = recursive;140 } else {141 [x1, y1] = rotate(x1, y1, -angleRad);142 [x2, y2] = rotate(x2, y2, -angleRad);143 144 const x = (x1 - x2) / 2;145 const y = (y1 - y2) / 2;146 let h = (x * x) / (r1 * r1) + (y * y) / (r2 * r2);147 if (h > 1) {148 h = Math.sqrt(h);149 r1 = h * r1;150 r2 = h * r2;151 }152 153 const sign = (largeArcFlag === sweepFlag) ? -1 : 1;154 155 const r1Pow = r1 * r1;156 const r2Pow = r2 * r2;157 158 const left = r1Pow * r2Pow - r1Pow * y * y - r2Pow * x * x;159 const right = r1Pow * y * y + r2Pow * x * x;160 161 const k = sign * Math.sqrt(Math.abs(left / right));162 163 cx = k * r1 * y / r2 + (x1 + x2) / 2;164 cy = k * -r2 * x / r1 + (y1 + y2) / 2;165 166 f1 = Math.asin(parseFloat(((y1 - cy) / r2).toFixed(9)));167 f2 = Math.asin(parseFloat(((y2 - cy) / r2).toFixed(9)));168 169 if (x1 < cx) {170 f1 = Math.PI - f1;171 }172 if (x2 < cx) {173 f2 = Math.PI - f2;174 }175 176 if (f1 < 0) {177 f1 = Math.PI * 2 + f1;178 }179 if (f2 < 0) {180 f2 = Math.PI * 2 + f2;181 }182 183 if (sweepFlag && f1 > f2) {184 f1 = f1 - Math.PI * 2;185 }186 if (!sweepFlag && f2 > f1) {187 f2 = f2 - Math.PI * 2;188 }189 }190 191 let df = f2 - f1;192 193 if (Math.abs(df) > (Math.PI * 120 / 180)) {194 const f2old = f2;195 const x2old = x2;196 const y2old = y2;197 198 if (sweepFlag && f2 > f1) {199 f2 = f1 + (Math.PI * 120 / 180) * (1);200 }201 else {202 f2 = f1 + (Math.PI * 120 / 180) * (-1);203 }204 205 x2 = cx + r1 * Math.cos(f2);206 y2 = cy + r2 * Math.sin(f2);207 params = arcToCubicCurves(x2, y2, x2old, y2old, r1, r2, angle, 0, sweepFlag, [f2, f2old, cx, cy]);208 }209 210 df = f2 - f1;211 212 const c1 = Math.cos(f1);213 const s1 = Math.sin(f1);214 const c2 = Math.cos(f2);215 const s2 = Math.sin(f2);216 const t = Math.tan(df / 4);217 const hx = 4 / 3 * r1 * t;218 const hy = 4 / 3 * r2 * t;219 220 const m1 = [x1, y1];221 const m2 = [x1 + hx * s1, y1 - hy * c1];222 const m3 = [x2 + hx * s2, y2 - hy * c2];223 const m4 = [x2, y2];224 225 m2[0] = 2 * m1[0] - m2[0];226 m2[1] = 2 * m1[1] - m2[1];227 228 if (recursive) {229 return [m2, m3, m4].concat(params);230 }231 else {232 params = [m2, m3, m4].concat(params);233 const curves = [];234 for (let i = 0; i < params.length; i += 3) {235 const r1 = rotate(params[i][0], params[i][1], angleRad);236 const r2 = rotate(params[i + 1][0], params[i + 1][1], angleRad);237 const r3 = rotate(params[i + 2][0], params[i + 2][1], angleRad);238 curves.push([r1[0], r1[1], r2[0], r2[1], r3[0], r3[1]]);239 }240 return curves;241 }242}