Download static/layout.js from VIDraft/zero-token-confidence: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/VIDraft/zero-token-confidence/resolve/main/static/layout.js
- Command line
-
hf download hf://spaces/VIDraft/zero-token-confidence/static/layout.js
-
curl -L -o layout.js https://huggingface.co/spaces/VIDraft/zero-token-confidence/resolve/main/static/layout.js
1.87 kB
| // ๋ถํด ๋ฐฐ์น โ ๋ณด์ด๋ ์กฐ๊ฐ๋ง ๊ฒน์น์ง ์๊ฒ ์ ๋ฐ ์ฑ์ฐ๊ธฐ(shelf packing) | |
| // ํก์ ์ถ์ฒ: ashemag/human-atlas (MIT) ์ explosion-layout ๊ฐ๋ . ๊ตฌํ์ ์ฐ๋ฆฌ ๊ฒ. | |
| // ํต์ฌ ๊ท์จ: "๊ฒน์น์ง ์๋๋ค"๋ฅผ ๋์ด ์๋๋ผ **์คํฌ๋ฆฝํธ๊ฐ ๋จ์ธ**ํ๋ค. | |
| /** | |
| * @param {{id:string, w:number, h:number}[]} parts ์กฐ๊ฐ์ ํฌ์ ํฌ๊ธฐ | |
| * @param {number} aspect ํ๋ฉด ๊ฐ๋ก/์ธ๋ก ๋น | |
| * @returns {{cells:Map<string,{x:number,y:number,w:number,h:number}>, width:number, height:number}} | |
| */ | |
| export function explodeLayout(parts, aspect = 1) { | |
| const PAD = 0.10; | |
| const cards = parts.map(p => ({ | |
| id: p.id, | |
| w: Math.max(0.05, p.w) + PAD, | |
| h: Math.max(0.05, p.h) + PAD, | |
| })); | |
| const area = cards.reduce((n, c) => n + c.w * c.h, 0); | |
| const maxW = Math.max(0.3, ...cards.map(c => c.w)); | |
| // ๋ชฉํ ํญ: ๋ฉด์ ์ ํ๋ฉด๋น์ ๋ง์ถฐ ์ ์ฌ๊ฐ์ ๊ฐ๊น๊ฒ | |
| const targetW = Math.max(maxW, Math.sqrt(area * Math.max(0.5, Math.min(1.8, aspect))) * 1.15); | |
| // ๋์ ๊ฒ๋ถํฐ ์ฑ์ฐ๋ฉด ์ ๋ฐ ๋ญ๋น๊ฐ ์ค๋ค. id ๋ก ํ์ด๋ธ๋ ์ดํฌํด ๊ฒฐ๊ณผ๋ฅผ ๊ฒฐ์ ์ ์ผ๋ก. | |
| cards.sort((a, b) => b.h - a.h || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)); | |
| const cells = new Map(); | |
| let x = 0, y = 0, rowH = 0, usedW = 0; | |
| for (const c of cards) { | |
| if (x > 0 && x + c.w > targetW) { x = 0; y += rowH; rowH = 0; } | |
| cells.set(c.id, { x: x + c.w / 2, y: -y - c.h / 2, w: c.w, h: c.h }); | |
| x += c.w; | |
| usedW = Math.max(usedW, x); | |
| rowH = Math.max(rowH, c.h); | |
| } | |
| const height = y + rowH; | |
| // ์ค์ ์ ๋ ฌ | |
| cells.forEach(c => { c.x -= usedW / 2; c.y += height / 2; }); | |
| return { cells, width: usedW, height }; | |
| } | |
| /** ๋ ์นธ์ด ๊ฒน์น๋๊ฐ (๊ฒฝ๊ณ ์ ์ด์ ํ์ฉ) */ | |
| export function overlaps(a, b, eps = 1e-9) { | |
| return Math.abs(a.x - b.x) < (a.w + b.w) / 2 - eps && | |
| Math.abs(a.y - b.y) < (a.h + b.h) / 2 - eps; | |
| } | |