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.
03.1k
1import { getFiller } from './fillers/filler.js';2import { Random } from './math.js';3import { parsePath, normalize, absolutize } from 'path-data-parser';4const helper = {5 randOffset,6 randOffsetWithRange,7 ellipse,8 doubleLineOps: doubleLineFillOps,9};10export function line(x1, y1, x2, y2, o) {11 return { type: 'path', ops: _doubleLine(x1, y1, x2, y2, o) };12}13export function linearPath(points, close, o) {14 const len = (points || []).length;15 if (len > 2) {16 const ops = [];17 for (let i = 0; i < (len - 1); i++) {18 ops.push(..._doubleLine(points[i][0], points[i][1], points[i + 1][0], points[i + 1][1], o));19 }20 if (close) {21 ops.push(..._doubleLine(points[len - 1][0], points[len - 1][1], points[0][0], points[0][1], o));22 }23 return { type: 'path', ops };24 }25 else if (len === 2) {26 return line(points[0][0], points[0][1], points[1][0], points[1][1], o);27 }28 return { type: 'path', ops: [] };29}30export function polygon(points, o) {31 return linearPath(points, true, o);32}33export function rectangle(x, y, width, height, o) {34 const points = [35 [x, y],36 [x + width, y],37 [x + width, y + height],38 [x, y + height],39 ];40 return polygon(points, o);41}42export function curve(inputPoints, o) {43 if (inputPoints.length) {44 const p1 = inputPoints[0];45 const pointsList = (typeof p1[0] === 'number') ? [inputPoints] : inputPoints;46 const o1 = _curveWithOffset(pointsList[0], 1 * (1 + o.roughness * 0.2), o);47 const o2 = o.disableMultiStroke ? [] : _curveWithOffset(pointsList[0], 1.5 * (1 + o.roughness * 0.22), cloneOptionsAlterSeed(o));48 for (let i = 1; i < pointsList.length; i++) {49 const points = pointsList[i];50 if (points.length) {51 const underlay = _curveWithOffset(points, 1 * (1 + o.roughness * 0.2), o);52 const overlay = o.disableMultiStroke ? [] : _curveWithOffset(points, 1.5 * (1 + o.roughness * 0.22), cloneOptionsAlterSeed(o));53 for (const item of underlay) {54 if (item.op !== 'move') {55 o1.push(item);56 }57 }58 for (const item of overlay) {59 if (item.op !== 'move') {60 o2.push(item);61 }62 }63 }64 }65 return { type: 'path', ops: o1.concat(o2) };66 }67 return { type: 'path', ops: [] };68}69export function ellipse(x, y, width, height, o) {70 const params = generateEllipseParams(width, height, o);71 return ellipseWithParams(x, y, o, params).opset;72}73export function generateEllipseParams(width, height, o) {74 const psq = Math.sqrt(Math.PI * 2 * Math.sqrt((Math.pow(width / 2, 2) + Math.pow(height / 2, 2)) / 2));75 const stepCount = Math.ceil(Math.max(o.curveStepCount, (o.curveStepCount / Math.sqrt(200)) * psq));76 const increment = (Math.PI * 2) / stepCount;77 let rx = Math.abs(width / 2);78 let ry = Math.abs(height / 2);79 const curveFitRandomness = 1 - o.curveFitting;80 rx += _offsetOpt(rx * curveFitRandomness, o);81 ry += _offsetOpt(ry * curveFitRandomness, o);82 return { increment, rx, ry };83}84export function ellipseWithParams(x, y, o, ellipseParams) {85 const [ap1, cp1] = _computeEllipsePoints(ellipseParams.increment, x, y, ellipseParams.rx, ellipseParams.ry, 1, ellipseParams.increment * _offset(0.1, _offset(0.4, 1, o), o), o);86 let o1 = _curve(ap1, null, o);87 if ((!o.disableMultiStroke) && (o.roughness !== 0)) {88 const [ap2] = _computeEllipsePoints(ellipseParams.increment, x, y, ellipseParams.rx, ellipseParams.ry, 1.5, 0, o);89 const o2 = _curve(ap2, null, o);90 o1 = o1.concat(o2);91 }92 return {93 estimatedPoints: cp1,94 opset: { type: 'path', ops: o1 },95 };96}97export function arc(x, y, width, height, start, stop, closed, roughClosure, o) {98 const cx = x;99 const cy = y;100 let rx = Math.abs(width / 2);101 let ry = Math.abs(height / 2);102 rx += _offsetOpt(rx * 0.01, o);103 ry += _offsetOpt(ry * 0.01, o);104 let strt = start;105 let stp = stop;106 while (strt < 0) {107 strt += Math.PI * 2;108 stp += Math.PI * 2;109 }110 if ((stp - strt) > (Math.PI * 2)) {111 strt = 0;112 stp = Math.PI * 2;113 }114 const ellipseInc = (Math.PI * 2) / o.curveStepCount;115 const arcInc = Math.min(ellipseInc / 2, (stp - strt) / 2);116 const ops = _arc(arcInc, cx, cy, rx, ry, strt, stp, 1, o);117 if (!o.disableMultiStroke) {118 const o2 = _arc(arcInc, cx, cy, rx, ry, strt, stp, 1.5, o);119 ops.push(...o2);120 }121 if (closed) {122 if (roughClosure) {123 ops.push(..._doubleLine(cx, cy, cx + rx * Math.cos(strt), cy + ry * Math.sin(strt), o), ..._doubleLine(cx, cy, cx + rx * Math.cos(stp), cy + ry * Math.sin(stp), o));124 }125 else {126 ops.push({ op: 'lineTo', data: [cx, cy] }, { op: 'lineTo', data: [cx + rx * Math.cos(strt), cy + ry * Math.sin(strt)] });127 }128 }129 return { type: 'path', ops };130}131export function svgPath(path, o) {132 const segments = normalize(absolutize(parsePath(path)));133 const ops = [];134 let first = [0, 0];135 let current = [0, 0];136 for (const { key, data } of segments) {137 switch (key) {138 case 'M': {139 current = [data[0], data[1]];140 first = [data[0], data[1]];141 break;142 }143 case 'L':144 ops.push(..._doubleLine(current[0], current[1], data[0], data[1], o));145 current = [data[0], data[1]];146 break;147 case 'C': {148 const [x1, y1, x2, y2, x, y] = data;149 ops.push(..._bezierTo(x1, y1, x2, y2, x, y, current, o));150 current = [x, y];151 break;152 }153 case 'Z':154 ops.push(..._doubleLine(current[0], current[1], first[0], first[1], o));155 current = [first[0], first[1]];156 break;157 }158 }159 return { type: 'path', ops };160}161// Fills162export function solidFillPolygon(polygonList, o) {163 const ops = [];164 for (const points of polygonList) {165 if (points.length) {166 const offset = o.maxRandomnessOffset || 0;167 const len = points.length;168 if (len > 2) {169 ops.push({ op: 'move', data: [points[0][0] + _offsetOpt(offset, o), points[0][1] + _offsetOpt(offset, o)] });170 for (let i = 1; i < len; i++) {171 ops.push({ op: 'lineTo', data: [points[i][0] + _offsetOpt(offset, o), points[i][1] + _offsetOpt(offset, o)] });172 }173 }174 }175 }176 return { type: 'fillPath', ops };177}178export function patternFillPolygons(polygonList, o) {179 return getFiller(o, helper).fillPolygons(polygonList, o);180}181export function patternFillArc(x, y, width, height, start, stop, o) {182 const cx = x;183 const cy = y;184 let rx = Math.abs(width / 2);185 let ry = Math.abs(height / 2);186 rx += _offsetOpt(rx * 0.01, o);187 ry += _offsetOpt(ry * 0.01, o);188 let strt = start;189 let stp = stop;190 while (strt < 0) {191 strt += Math.PI * 2;192 stp += Math.PI * 2;193 }194 if ((stp - strt) > (Math.PI * 2)) {195 strt = 0;196 stp = Math.PI * 2;197 }198 const increment = (stp - strt) / o.curveStepCount;199 const points = [];200 for (let angle = strt; angle <= stp; angle = angle + increment) {201 points.push([cx + rx * Math.cos(angle), cy + ry * Math.sin(angle)]);202 }203 points.push([cx + rx * Math.cos(stp), cy + ry * Math.sin(stp)]);204 points.push([cx, cy]);205 return patternFillPolygons([points], o);206}207export function randOffset(x, o) {208 return _offsetOpt(x, o);209}210export function randOffsetWithRange(min, max, o) {211 return _offset(min, max, o);212}213export function doubleLineFillOps(x1, y1, x2, y2, o) {214 return _doubleLine(x1, y1, x2, y2, o, true);215}216// Private helpers217function cloneOptionsAlterSeed(ops) {218 const result = Object.assign({}, ops);219 result.randomizer = undefined;220 if (ops.seed) {221 result.seed = ops.seed + 1;222 }223 return result;224}225function random(ops) {226 if (!ops.randomizer) {227 ops.randomizer = new Random(ops.seed || 0);228 }229 return ops.randomizer.next();230}231function _offset(min, max, ops, roughnessGain = 1) {232 return ops.roughness * roughnessGain * ((random(ops) * (max - min)) + min);233}234function _offsetOpt(x, ops, roughnessGain = 1) {235 return _offset(-x, x, ops, roughnessGain);236}237function _doubleLine(x1, y1, x2, y2, o, filling = false) {238 const singleStroke = filling ? o.disableMultiStrokeFill : o.disableMultiStroke;239 const o1 = _line(x1, y1, x2, y2, o, true, false);240 if (singleStroke) {241 return o1;242 }243 const o2 = _line(x1, y1, x2, y2, o, true, true);244 return o1.concat(o2);245}246function _line(x1, y1, x2, y2, o, move, overlay) {247 const lengthSq = Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2);248 const length = Math.sqrt(lengthSq);249 let roughnessGain = 1;250 if (length < 200) {251 roughnessGain = 1;252 }253 else if (length > 500) {254 roughnessGain = 0.4;255 }256 else {257 roughnessGain = (-0.0016668) * length + 1.233334;258 }259 let offset = o.maxRandomnessOffset || 0;260 if ((offset * offset * 100) > lengthSq) {261 offset = length / 10;262 }263 const halfOffset = offset / 2;264 const divergePoint = 0.2 + random(o) * 0.2;265 let midDispX = o.bowing * o.maxRandomnessOffset * (y2 - y1) / 200;266 let midDispY = o.bowing * o.maxRandomnessOffset * (x1 - x2) / 200;267 midDispX = _offsetOpt(midDispX, o, roughnessGain);268 midDispY = _offsetOpt(midDispY, o, roughnessGain);269 const ops = [];270 const randomHalf = () => _offsetOpt(halfOffset, o, roughnessGain);271 const randomFull = () => _offsetOpt(offset, o, roughnessGain);272 const preserveVertices = o.preserveVertices;273 if (move) {274 if (overlay) {275 ops.push({276 op: 'move', data: [277 x1 + (preserveVertices ? 0 : randomHalf()),278 y1 + (preserveVertices ? 0 : randomHalf()),279 ],280 });281 }282 else {283 ops.push({284 op: 'move', data: [285 x1 + (preserveVertices ? 0 : _offsetOpt(offset, o, roughnessGain)),286 y1 + (preserveVertices ? 0 : _offsetOpt(offset, o, roughnessGain)),287 ],288 });289 }290 }291 if (overlay) {292 ops.push({293 op: 'bcurveTo',294 data: [295 midDispX + x1 + (x2 - x1) * divergePoint + randomHalf(),296 midDispY + y1 + (y2 - y1) * divergePoint + randomHalf(),297 midDispX + x1 + 2 * (x2 - x1) * divergePoint + randomHalf(),298 midDispY + y1 + 2 * (y2 - y1) * divergePoint + randomHalf(),299 x2 + (preserveVertices ? 0 : randomHalf()),300 y2 + (preserveVertices ? 0 : randomHalf()),301 ],302 });303 }304 else {305 ops.push({306 op: 'bcurveTo',307 data: [308 midDispX + x1 + (x2 - x1) * divergePoint + randomFull(),309 midDispY + y1 + (y2 - y1) * divergePoint + randomFull(),310 midDispX + x1 + 2 * (x2 - x1) * divergePoint + randomFull(),311 midDispY + y1 + 2 * (y2 - y1) * divergePoint + randomFull(),312 x2 + (preserveVertices ? 0 : randomFull()),313 y2 + (preserveVertices ? 0 : randomFull()),314 ],315 });316 }317 return ops;318}319function _curveWithOffset(points, offset, o) {320 if (!points.length) {321 return [];322 }323 const ps = [];324 ps.push([325 points[0][0] + _offsetOpt(offset, o),326 points[0][1] + _offsetOpt(offset, o),327 ]);328 ps.push([329 points[0][0] + _offsetOpt(offset, o),330 points[0][1] + _offsetOpt(offset, o),331 ]);332 for (let i = 1; i < points.length; i++) {333 ps.push([334 points[i][0] + _offsetOpt(offset, o),335 points[i][1] + _offsetOpt(offset, o),336 ]);337 if (i === (points.length - 1)) {338 ps.push([339 points[i][0] + _offsetOpt(offset, o),340 points[i][1] + _offsetOpt(offset, o),341 ]);342 }343 }344 return _curve(ps, null, o);345}346function _curve(points, closePoint, o) {347 const len = points.length;348 const ops = [];349 if (len > 3) {350 const b = [];351 const s = 1 - o.curveTightness;352 ops.push({ op: 'move', data: [points[1][0], points[1][1]] });353 for (let i = 1; (i + 2) < len; i++) {354 const cachedVertArray = points[i];355 b[0] = [cachedVertArray[0], cachedVertArray[1]];356 b[1] = [cachedVertArray[0] + (s * points[i + 1][0] - s * points[i - 1][0]) / 6, cachedVertArray[1] + (s * points[i + 1][1] - s * points[i - 1][1]) / 6];357 b[2] = [points[i + 1][0] + (s * points[i][0] - s * points[i + 2][0]) / 6, points[i + 1][1] + (s * points[i][1] - s * points[i + 2][1]) / 6];358 b[3] = [points[i + 1][0], points[i + 1][1]];359 ops.push({ op: 'bcurveTo', data: [b[1][0], b[1][1], b[2][0], b[2][1], b[3][0], b[3][1]] });360 }361 if (closePoint && closePoint.length === 2) {362 const ro = o.maxRandomnessOffset;363 ops.push({ op: 'lineTo', data: [closePoint[0] + _offsetOpt(ro, o), closePoint[1] + _offsetOpt(ro, o)] });364 }365 }366 else if (len === 3) {367 ops.push({ op: 'move', data: [points[1][0], points[1][1]] });368 ops.push({369 op: 'bcurveTo',370 data: [371 points[1][0], points[1][1],372 points[2][0], points[2][1],373 points[2][0], points[2][1],374 ],375 });376 }377 else if (len === 2) {378 ops.push(..._line(points[0][0], points[0][1], points[1][0], points[1][1], o, true, true));379 }380 return ops;381}382function _computeEllipsePoints(increment, cx, cy, rx, ry, offset, overlap, o) {383 const coreOnly = o.roughness === 0;384 const corePoints = [];385 const allPoints = [];386 if (coreOnly) {387 increment = increment / 4;388 allPoints.push([389 cx + rx * Math.cos(-increment),390 cy + ry * Math.sin(-increment),391 ]);392 for (let angle = 0; angle <= Math.PI * 2; angle = angle + increment) {393 const p = [394 cx + rx * Math.cos(angle),395 cy + ry * Math.sin(angle),396 ];397 corePoints.push(p);398 allPoints.push(p);399 }400 allPoints.push([401 cx + rx * Math.cos(0),402 cy + ry * Math.sin(0),403 ]);404 allPoints.push([405 cx + rx * Math.cos(increment),406 cy + ry * Math.sin(increment),407 ]);408 }409 else {410 const radOffset = _offsetOpt(0.5, o) - (Math.PI / 2);411 allPoints.push([412 _offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset - increment),413 _offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment),414 ]);415 const endAngle = Math.PI * 2 + radOffset - 0.01;416 for (let angle = radOffset; angle < endAngle; angle = angle + increment) {417 const p = [418 _offsetOpt(offset, o) + cx + rx * Math.cos(angle),419 _offsetOpt(offset, o) + cy + ry * Math.sin(angle),420 ];421 corePoints.push(p);422 allPoints.push(p);423 }424 allPoints.push([425 _offsetOpt(offset, o) + cx + rx * Math.cos(radOffset + Math.PI * 2 + overlap * 0.5),426 _offsetOpt(offset, o) + cy + ry * Math.sin(radOffset + Math.PI * 2 + overlap * 0.5),427 ]);428 allPoints.push([429 _offsetOpt(offset, o) + cx + 0.98 * rx * Math.cos(radOffset + overlap),430 _offsetOpt(offset, o) + cy + 0.98 * ry * Math.sin(radOffset + overlap),431 ]);432 allPoints.push([433 _offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset + overlap * 0.5),434 _offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset + overlap * 0.5),435 ]);436 }437 return [allPoints, corePoints];438}439function _arc(increment, cx, cy, rx, ry, strt, stp, offset, o) {440 const radOffset = strt + _offsetOpt(0.1, o);441 const points = [];442 points.push([443 _offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset - increment),444 _offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment),445 ]);446 for (let angle = radOffset; angle <= stp; angle = angle + increment) {447 points.push([448 _offsetOpt(offset, o) + cx + rx * Math.cos(angle),449 _offsetOpt(offset, o) + cy + ry * Math.sin(angle),450 ]);451 }452 points.push([453 cx + rx * Math.cos(stp),454 cy + ry * Math.sin(stp),455 ]);456 points.push([457 cx + rx * Math.cos(stp),458 cy + ry * Math.sin(stp),459 ]);460 return _curve(points, null, o);461}462function _bezierTo(x1, y1, x2, y2, x, y, current, o) {463 const ops = [];464 const ros = [o.maxRandomnessOffset || 1, (o.maxRandomnessOffset || 1) + 0.3];465 let f = [0, 0];466 const iterations = o.disableMultiStroke ? 1 : 2;467 const preserveVertices = o.preserveVertices;468 for (let i = 0; i < iterations; i++) {469 if (i === 0) {470 ops.push({ op: 'move', data: [current[0], current[1]] });471 }472 else {473 ops.push({ op: 'move', data: [current[0] + (preserveVertices ? 0 : _offsetOpt(ros[0], o)), current[1] + (preserveVertices ? 0 : _offsetOpt(ros[0], o))] });474 }475 f = preserveVertices ? [x, y] : [x + _offsetOpt(ros[i], o), y + _offsetOpt(ros[i], o)];476 ops.push({477 op: 'bcurveTo',478 data: [479 x1 + _offsetOpt(ros[i], o), y1 + _offsetOpt(ros[i], o),480 x2 + _offsetOpt(ros[i], o), y2 + _offsetOpt(ros[i], o),481 f[0], f[1],482 ],483 });484 }485 return ops;486}487 