{esc(summary["title"])}
{family_description(summary)}
from __future__ import annotations import html import inspect import json import math import re from datetime import datetime from functools import lru_cache from pathlib import Path from typing import Any import gradio as gr from packing_benchmark.dates import ( date_from_friedman_record, date_from_submission, display_date_info, is_recent_date_info, parse_friedman_date_text, ) from packing_benchmark.hub_sync import maybe_hydrate_from_dataset from packing_benchmark.store import SolutionStore, is_trivial_record from packing_benchmark.verifier import ( DEFAULT_TOLERANCE, load_solution_json, make_container_shape, make_item_shape, normalize_solution, solution_case, solution_hash, verify_solution, ) SPACE_ROOT = Path(__file__).resolve().parent DATA_DIR = SPACE_ROOT / "data" DATA_DIR.mkdir(parents=True, exist_ok=True) FAVICON_PATH = SPACE_ROOT / "assets" / "favicon.svg" HYDRATE_STATUS = maybe_hydrate_from_dataset(DATA_DIR) STORE = SolutionStore(DATA_DIR) SUBMISSION_MIN_IMPROVEMENT = 1.0e-4 SUBMISSION_MAX_NEW_CASE_N = 100 VERIFIER_REPO_URL = "https://github.com/Nathan-Roll1/packing-verifier" @lru_cache(maxsize=1) def cached_reference_records() -> list[dict[str, Any]]: return STORE.load_reference_records() @lru_cache(maxsize=1) def cached_verified_records() -> list[dict[str, Any]]: return STORE.load_records() @lru_cache(maxsize=1) def cached_family_updates() -> dict[str, Any]: path = DATA_DIR / "friedman_family_updates.json" if not path.exists(): return {} try: payload = json.loads(path.read_text()) except Exception: return {} families = payload.get("families", {}) return families if isinstance(families, dict) else {} @lru_cache(maxsize=64) def cached_public_records(setup: str = "", show_all: bool = False) -> list[dict[str, Any]]: return STORE.public_records(setup or None, show_all=show_all) def clear_page_caches() -> None: cached_reference_records.cache_clear() cached_verified_records.cache_clear() cached_family_updates.cache_clear() cached_public_records.cache_clear() setup_choices.cache_clear() coordinate_records_by_case.cache_clear() family_page_html.cache_clear() directory_html.cache_clear() CSS = """ :root { color-scheme: light; --page: #f3eddf; --paper: #fffdf7; --paper-soft: #faf6ec; --ink: #151515; --muted: #58544d; --quiet: #7b766d; --line: #1b1b1b; --line-soft: #d4cab8; --green: #b9e7bd; --green-strong: #2e7d32; --link: #174f8a; --tri: #e69f00; --cir: #56b4e9; --squ: #009e73; --pen: #f0e442; --hex: #0072b2; --oct: #d55e00; --dom: #cc79a7; --unknown-shape: #999999; --radius: 6px; } html, body, gradio-app, .gradio-container, .main, .app { background: var(--page) !important; color: var(--ink) !important; font-family: Helvetica, Arial, sans-serif !important; } .gradio-container { max-width: none !important; margin: 0 !important; padding: 0 !important; font-family: Helvetica, Arial, sans-serif !important; line-height: 1.45; } .gradio-container *, .gradio-container button, .gradio-container input, .gradio-container textarea, .gradio-container select { box-sizing: border-box; font-family: Helvetica, Arial, sans-serif !important; letter-spacing: 0 !important; } .gradio-container a { color: var(--link) !important; text-decoration: underline; text-underline-offset: 2px; } .contain { width: min(1180px, calc(100% - 32px)); margin: 0 auto; } .packing-shell { min-height: 0; background: var(--page); color: var(--ink); font-family: Helvetica, Arial, sans-serif !important; padding-bottom: 44px; } .packing-shell * { font-family: Helvetica, Arial, sans-serif !important; } #leaderboard-panel, #submit-entry-panel { display: none; } #leaderboard-panel:target, #submit-entry-panel:target, #leaderboard-panel:target #leaderboard-panel, #submit-entry-panel:target #submit-entry-panel, html:has(#leaderboard-table:target) #leaderboard-panel, html:has(.leaderboard-modal:target) #leaderboard-panel { display: block !important; } html:has(#leaderboard-panel:target) #home-panel, html:has(#submit-entry-panel:target) #home-panel, html:has(#leaderboard-table:target) #home-panel, html:has(.leaderboard-modal:target) #home-panel { display: none !important; } html:has(#leaderboard-panel:target) #submit-entry-panel, html:has(#leaderboard-table:target) #submit-entry-panel, html:has(.leaderboard-modal:target) #submit-entry-panel, html:has(#submit-entry-panel:target) #leaderboard-panel { display: none !important; } .hero-stage { border-bottom: 2px solid var(--line); padding: 30px 0 20px; } .hero-stage h1 { margin: 0 0 10px; color: var(--ink); font-size: 36px; line-height: 1.05; font-weight: 700; } .hero-copy { max-width: 820px; margin: 0; color: var(--muted); font-size: 16px; line-height: 1.55; } .gradio-container .tab-nav, .gradio-container [role="tablist"] { display: none !important; } .site-nav { position: sticky !important; top: 0; z-index: 50; min-height: 48px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 7px max(16px, calc((100% - 1180px) / 2)) !important; background: rgba(243, 237, 223, 0.98) !important; border-bottom: 1px solid var(--line) !important; } .site-nav-link { display: inline-flex; align-items: center; justify-content: center; min-height: 32px !important; padding: 5px 11px !important; background: transparent !important; border: 1px solid transparent !important; border-radius: 4px !important; box-shadow: none !important; color: var(--ink) !important; font-size: 14px !important; font-weight: 700 !important; line-height: 1.2; text-decoration: none !important; } .site-nav-link:hover, .site-nav-link.active { background: var(--paper) !important; border-color: var(--line) !important; } .site-nav-link.submit-link { margin-left: auto !important; background: var(--green-strong) !important; border-color: #1f5d25 !important; color: #fff !important; } .site-nav-link.submit-link:hover, .site-nav-link.submit-link.active { background: #236c29 !important; color: #fff !important; } footer, .gradio-container footer, .gradio-container .footer, .gradio-container .built-with, .gradio-container .api-docs, .gradio-container .app > header, .gradio-container .app > .header, .gradio-container .contain > button:not(.site-nav-link), .gradio-container a[href*="view=api"], .gradio-container a[href*="/api"], .gradio-container button[aria-label="Settings"], .gradio-container button[title="Settings"], .gradio-container button[aria-label="More"], .gradio-container button[aria-label="More options"], .gradio-container button[title="More"], .gradio-container button[title="More options"], .gradio-container [data-testid="settings-button"], .gradio-container [data-testid="more-button"], .gradio-container [data-testid="app-menu"], .gradio-container [data-testid="menu-button"], .gradio-container [class*="settings"], .gradio-container [class*="kebab"], .gradio-container [class*="ellipsis"] { display: none !important; } .section { padding: 30px 0 8px; } .section-head { display: flex; justify-content: space-between; gap: 20px; align-items: end; margin-bottom: 16px; } .section-head h2, .family-title-card h2 { margin: 0 0 4px; color: var(--ink); font-size: 24px; line-height: 1.2; font-weight: 700; } .section-note, .family-subtitle { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; } .family-matrix { display: grid; gap: 22px; } .family-row { padding-top: 14px; border-top: 1px solid var(--line); } .family-row:first-child { padding-top: 0; border-top: 0; } .family-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 10px; } .family-card { display: block; min-height: 218px; padding: 12px; color: var(--ink) !important; text-decoration: none !important; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); } .family-card:hover, .family-card:focus-visible { background: #fffaf0; outline: 2px solid var(--line); outline-offset: 2px; } .family-card-top { display: block; } .family-render { height: 150px; margin: 8px 0 10px; } .family-render .packing-svg { max-width: 160px; max-height: 160px; } .family-code { margin: 0 0 7px; color: var(--quiet); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; font-size: 12px; text-transform: uppercase; } .family-card h3 { margin: 0; color: var(--ink); font-size: 18px; line-height: 1.22; font-weight: 700; } .front-family-card { min-height: 232px; margin-bottom: 8px; } .front-family-card .family-render { height: 154px; } .record-book { padding: 10px 0 0; } .family-section { margin-top: 34px; padding-top: 22px; border-top: 2px solid var(--line); } .family-title-card { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; } .record-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 12px; } .record-card { overflow: hidden; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); } .record-card:hover, .record-card:focus-within { background: #fffaf0; outline: 2px solid var(--line); outline-offset: 2px; } .record-open { display: block; color: inherit !important; text-decoration: none !important; } .record-top { padding: 9px 10px 0; } .record-case { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; font-size: 12px; font-weight: 700; } .recent-dot { display: inline-block; width: 9px; height: 9px; margin-left: 7px; background: var(--green-strong); border: 1px solid #174c1b; border-radius: 999px; vertical-align: 1px; } .family-card h3 .recent-dot { width: 10px; height: 10px; vertical-align: 2px; } .render-stage { height: 178px; margin: 8px 10px 0; display: grid; place-items: center; background: transparent; border: 0; border-radius: 0; } .placeholder, .empty-state { padding: 0 14px; color: var(--quiet); font-size: 12px; line-height: 1.35; text-align: center; } .packing-svg { display: block; width: 100%; height: 100%; max-width: 162px; max-height: 162px; overflow: visible; } .shape-item { fill: var(--unknown-shape); stroke: #000; stroke-width: 1.5px !important; stroke-linejoin: round; vector-effect: non-scaling-stroke; } .shape-item.inner-tri { fill: var(--tri); } .shape-item.inner-cir { fill: var(--cir); } .shape-item.inner-squ { fill: var(--squ); } .shape-item.inner-pen { fill: var(--pen); } .shape-item.inner-hex { fill: var(--hex); } .shape-item.inner-oct { fill: var(--oct); } .shape-item.inner-dom { fill: var(--dom); } .shape-container { fill: none; stroke: #000; stroke-width: 2.6px !important; stroke-linejoin: round; vector-effect: non-scaling-stroke; } .record-body { padding: 9px 10px 12px; } .metric { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; color: var(--ink); } .metric strong { color: var(--ink); font-size: 17px; line-height: 1.2; } .metric span { color: var(--muted); font-size: 12px; white-space: nowrap; } .expression { min-height: 18px; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; } .meta { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 12px; line-height: 1.4; } .meta strong { color: var(--ink); } .record-author { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.35; } .record-author strong { color: var(--ink); } .trivial-badge { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 7px; background: var(--paper-soft); border: 1px solid var(--line); border-radius: 4px; color: var(--ink); font-size: 11px; font-weight: 700; line-height: 1.1; text-transform: uppercase; } .page-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; } .record-modal { display: none; position: fixed; inset: 0; z-index: 1000; align-items: center; justify-content: center; padding: 24px; } .record-modal:target { display: flex; } .modal-backdrop { position: absolute; inset: 0; background: rgba(21, 21, 21, 0.42); } .modal-panel { position: relative; z-index: 1; width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; background: var(--paper) !important; border: 2px solid var(--line); border-radius: var(--radius); color: var(--ink) !important; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24); } .record-modal, .record-modal .modal-panel, .record-modal .modal-panel * { color: var(--ink) !important; } .modal-close { position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 32px; height: 32px; background: var(--paper) !important; border: 1px solid var(--line); border-radius: 4px; color: var(--ink) !important; font-size: 18px; font-weight: 700; line-height: 1; text-decoration: none !important; } .modal-close:hover, .modal-close:focus-visible { background: #fffaf0 !important; outline: 2px solid var(--line); outline-offset: 2px; } .modal-head { padding: 18px 58px 12px 18px; border-bottom: 1px solid var(--line); } .modal-case { margin: 0 0 4px; color: var(--quiet) !important; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; font-size: 12px; font-weight: 700; text-transform: uppercase; } .modal-head h3 { margin: 0; color: var(--ink) !important; font-size: 22px; line-height: 1.2; } .modal-subtitle { margin-top: 7px; color: var(--muted) !important; font-size: 13px; line-height: 1.45; } .modal-layout { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 18px; padding: 18px; } .modal-visual .render-stage { height: 320px; margin: 0; } .modal-visual .packing-svg { max-width: 300px; max-height: 300px; } .download-actions { display: flex; justify-content: center; gap: 8px; margin-top: 10px; } .download-btn { appearance: none; min-height: 32px; padding: 6px 10px; background: var(--paper-soft) !important; border: 1px solid var(--line); border-radius: 4px; color: var(--ink) !important; cursor: pointer; font-size: 12px; font-weight: 700; line-height: 1; } .download-btn:hover, .download-btn:focus-visible { background: #fffaf0 !important; outline: 2px solid var(--line); outline-offset: 2px; } .modal-metric { margin-bottom: 14px; padding: 10px 12px; background: var(--paper-soft) !important; border: 1px solid var(--line-soft); border-radius: var(--radius); } .modal-metric strong { display: block; color: var(--ink) !important; font-size: 20px; line-height: 1.2; } .modal-metric span { display: block; margin-top: 3px; color: var(--muted) !important; font-size: 13px; } .modal-details { margin: 0; display: grid; grid-template-columns: 142px minmax(0, 1fr); gap: 8px 14px; color: var(--muted) !important; font-size: 13px; line-height: 1.42; } .modal-details dt { color: var(--ink) !important; font-weight: 700; } .modal-details dd { margin: 0; color: var(--muted) !important; overflow-wrap: anywhere; } .modal-details a { color: var(--link) !important; } .previous-bests-table { width: 100%; border-collapse: collapse; background: var(--paper) !important; color: var(--ink) !important; font-size: 12px; } .previous-bests-table th, .previous-bests-table td { padding: 6px 7px; border: 1px solid var(--line-soft); color: var(--ink) !important; text-align: left; vertical-align: top; } .previous-bests-table th { background: var(--paper-soft) !important; font-weight: 700; } .date-source { color: var(--muted) !important; } .record-modal .modal-panel .modal-case { color: var(--quiet) !important; } .record-modal .modal-panel .modal-subtitle, .record-modal .modal-panel .modal-metric span, .record-modal .modal-panel .modal-details, .record-modal .modal-panel .modal-details dd { color: var(--muted) !important; } .record-modal .modal-panel .modal-head h3, .record-modal .modal-panel .modal-metric strong, .record-modal .modal-panel .modal-details dt, .record-modal .modal-panel .modal-subtitle strong, .record-modal .modal-panel .modal-close { color: var(--ink) !important; } .record-modal .modal-panel .modal-details a { color: var(--link) !important; } .leaderboard-table { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); } .leaderboard-table th, .leaderboard-table td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); color: var(--ink); text-align: left; vertical-align: top; } .leaderboard-table th { background: var(--paper-soft); font-size: 12px; text-transform: uppercase; } .leaderboard-table th:not(:nth-child(2)), .leaderboard-table td:not(:nth-child(2)) { text-align: center; } .leaderboard-table th:nth-child(2), .leaderboard-table td:nth-child(2) { text-align: left; } .leaderboard-table strong, .leaderboard-table a { color: var(--ink) !important; } .leaderboard-best { font-weight: 800; } .leaderboard-best strong { font-weight: 800; } .case-links { max-width: 560px; color: var(--ink); font-size: 13px; line-height: 1.55; } .case-links a { display: inline-block; margin-right: 6px; color: var(--link) !important; } .leaderboard-author-link, .leaderboard-author-link strong { color: var(--ink) !important; font-weight: 700; } .leaderboard-author-link { text-decoration: underline; text-underline-offset: 2px; } .leaderboard-table .leaderboard-open { white-space: nowrap; } .leaderboard-stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0 0 16px; } .leaderboard-stat { padding: 10px 12px; background: var(--paper-soft); border: 1px solid var(--line-soft); border-radius: var(--radius); } .leaderboard-stat strong { display: block; color: var(--ink) !important; font-size: 22px; line-height: 1.15; } .leaderboard-stat span { display: block; margin-top: 3px; color: var(--muted) !important; font-size: 12px; } .leaderboard-class-strip { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 14px; } .leaderboard-class-strip span { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; background: #fff !important; border: 1px solid var(--line-soft); border-radius: 4px; color: var(--muted) !important; font-size: 12px; } .leaderboard-class-strip strong { color: var(--ink) !important; } .leaderboard-full-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 260px; overflow: auto; padding: 1px; } .leaderboard-full-list a { display: inline-block; padding: 4px 7px; color: var(--ink) !important; background: #fff !important; border: 1px solid var(--line-soft); border-radius: 4px; font-size: 12px; line-height: 1.2; text-decoration: none; } .leaderboard-modal .modal-layout { grid-template-columns: 1fr; } .leaderboard-modal .case-links { max-width: none; margin-bottom: 14px; } .submit-shell, .schema-shell, .family-button-shell { width: min(1180px, calc(100% - 32px)); margin: 18px auto 44px; color: var(--ink) !important; } .submit-hero { padding-bottom: 0; } .submit-hero .section-head { align-items: start; } .submit-flow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; } .submission-guide { margin-top: 18px; } .guide-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } .guide-card { min-width: 0; padding: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); } .guide-card.wide { grid-column: 1 / -1; } .guide-card h3 { margin: 0 0 8px; color: var(--ink); font-size: 16px; line-height: 1.25; } .guide-card p, .guide-card li { color: var(--muted) !important; font-size: 13px; line-height: 1.45; } .guide-card ul { margin: 8px 0 0; padding-left: 18px; } .code-block { max-height: 360px; overflow: auto; margin: 10px 0 0; padding: 12px; background: #fff !important; color: var(--ink) !important; border: 1px solid var(--line-soft); border-radius: var(--radius); font-size: 12px; line-height: 1.45; white-space: pre; } .code-block code { color: var(--ink) !important; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; } .submit-step { min-height: 96px; padding: 12px; background: var(--paper-soft); border: 1px solid var(--line); border-radius: var(--radius); } .submit-step strong { display: block; margin-bottom: 4px; color: var(--ink); font-size: 14px; } .submit-step span { color: var(--muted) !important; font-size: 13px; line-height: 1.4; } .submit-shell > .gradio-group, .schema-shell > .gradio-group, .family-button-shell > .gradio-group, .gradio-container .accordion, .gradio-container .block, .gradio-container .form, .gradio-container .panel, .gradio-container .input-container, .gradio-container .wrap { background: var(--paper) !important; color: var(--ink) !important; border-color: var(--line-soft) !important; box-shadow: none !important; } .submit-shell > .gradio-group { padding: 0 !important; background: transparent !important; border: 0 !important; } .submit-layout { align-items: stretch !important; gap: 14px !important; } .submit-editor, .submit-meta, .submit-results { min-width: 0; } .submit-panel, .submit-doc-panel, .submit-results-card { height: 100%; padding: 14px !important; background: var(--paper) !important; border: 1px solid var(--line) !important; border-radius: var(--radius) !important; box-shadow: none !important; } .submit-panel-title { margin: 0 0 10px; color: var(--ink); font-size: 16px; line-height: 1.25; font-weight: 700; } .submit-panel-note { margin: -4px 0 12px; color: var(--muted) !important; font-size: 13px; line-height: 1.45; } .submit-actions { gap: 8px !important; } .submit-actions button { min-height: 38px !important; font-weight: 700 !important; } .verification-report { min-height: 152px; margin-top: 8px; padding: 12px; background: var(--paper-soft) !important; color: var(--ink) !important; border: 1px solid var(--line-soft) !important; border-radius: var(--radius); } .verification-report, .verification-report *, .submit-results-card .verification-report, .submit-results-card .verification-report * { color: var(--ink) !important; } .verification-report .markdown, .verification-report .prose, .verification-report [data-testid="markdown"], .verification-report [class*="markdown"], .verification-report [class*="prose"] { background: transparent !important; color: var(--ink) !important; } .verification-report h1, .verification-report h2, .verification-report h3, .verification-report h4 { margin-top: 0 !important; color: var(--ink) !important; } .verification-report p, .verification-report li, .verification-report ul, .verification-report ol { color: var(--ink) !important; } .verification-report code { display: inline-block; padding: 1px 5px; background: #fff !important; color: var(--ink) !important; border: 1px solid var(--line-soft); border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; } .verification-report pre, .verification-report pre code { display: block; background: #fff !important; color: var(--ink) !important; border-color: var(--line-soft) !important; } .submit-docs { margin-top: 14px; } .submit-docs .accordion, .submit-docs details { border: 1px solid var(--line) !important; border-radius: var(--radius) !important; background: var(--paper) !important; } .submit-docs code, .submit-docs pre { background: #fff !important; border-color: var(--line-soft) !important; } .gradio-container label, .gradio-container .label-wrap, .gradio-container .markdown, .gradio-container .prose, .gradio-container p, .gradio-container span, .gradio-container h1, .gradio-container h2, .gradio-container h3, .gradio-container h4, .gradio-container code, .gradio-container pre { color: var(--ink) !important; } .gradio-container textarea, .gradio-container input, .gradio-container select, .gradio-container [role="combobox"], .gradio-container .input-container textarea, .gradio-container .input-container input { background: #fff !important; color: var(--ink) !important; border-color: var(--line-soft) !important; } .gradio-container [role="listbox"], .gradio-container [role="option"], .gradio-container .dropdown, .gradio-container .options, .gradio-container .item { background: #fff !important; color: var(--ink) !important; } .gradio-container .code_wrap, .gradio-container .cm-editor, .gradio-container .cm-scroller, .gradio-container .cm-content, .gradio-container .cm-gutters, .gradio-container .cm-line, .gradio-container .cm-activeLine, .gradio-container .cm-activeLineGutter { background: #fff !important; color: var(--ink) !important; border-color: var(--line-soft) !important; } .gradio-container .cm-cursor { border-left-color: var(--ink) !important; } .gradio-container button { border-radius: 4px !important; border: 1px solid var(--line) !important; box-shadow: none !important; color: var(--ink) !important; background: #fff !important; } .gradio-container button.primary, .gradio-container button[variant="primary"] { color: #fff !important; background: var(--green-strong) !important; } .preview-card { max-width: 420px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; } .preview-card .render-stage { height: 340px; margin: 0; } .preview-card .packing-svg { max-width: 315px; max-height: 315px; } @media (max-width: 720px) { .contain, .submit-shell, .schema-shell, .family-button-shell { width: min(100% - 22px, 1180px); } .hero-stage { padding-top: 26px; } .hero-stage h1 { font-size: 30px; } .family-title-card, .section-head { display: block; } .submit-flow { grid-template-columns: 1fr; } .guide-grid { grid-template-columns: 1fr; } .site-nav { padding: 7px 11px !important; } .site-nav-link.submit-link { margin-left: 0 !important; } .record-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } .record-modal { padding: 12px; } .modal-head { padding: 16px 54px 12px 14px; } .modal-layout { display: block; padding: 14px; } .modal-visual { margin-bottom: 14px; } .modal-visual .render-stage { height: 240px; } .modal-visual .packing-svg { max-width: 220px; max-height: 220px; } .modal-details { grid-template-columns: 1fr; gap: 3px; } .modal-details dd { margin-bottom: 8px; } .leaderboard-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .render-stage { height: 154px; } .packing-svg { max-width: 140px; max-height: 140px; } } """ APP_JS = """ () => { const cleanHomeUrl = () => `${window.location.origin}${window.location.pathname}`; const SVG_DOWNLOAD_STYLE = ` .shape-item { fill: #999999; stroke: #000000; stroke-width: 1.5px; stroke-linejoin: round; vector-effect: non-scaling-stroke; } .shape-item.inner-tri { fill: #e69f00; } .shape-item.inner-cir { fill: #56b4e9; } .shape-item.inner-squ { fill: #009e73; } .shape-item.inner-pen { fill: #f0e442; } .shape-item.inner-hex { fill: #0072b2; } .shape-item.inner-oct { fill: #d55e00; } .shape-item.inner-dom { fill: #cc79a7; } .shape-container { fill: none; stroke: #000000; stroke-width: 2.6px; stroke-linejoin: round; vector-effect: non-scaling-stroke; } `; const sanitizedFileName = (name, extension) => { const base = (name || "packing-record") .replace(/@/g, "-") .replace(/[^a-zA-Z0-9._-]+/g, "-") .replace(/^-+|-+$/g, "") || "packing-record"; return base.toLowerCase().endsWith(`.${extension}`) ? base : `${base}.${extension}`; }; const serializePackingSvg = (svg) => { const clone = svg.cloneNode(true); clone.setAttribute("xmlns", "http://www.w3.org/2000/svg"); clone.setAttribute("width", "900"); clone.setAttribute("height", "900"); if (!clone.getAttribute("viewBox")) { const box = svg.getBBox ? svg.getBBox() : null; if (box) { clone.setAttribute("viewBox", `${box.x} ${box.y} ${box.width} ${box.height}`); } } const style = document.createElementNS("http://www.w3.org/2000/svg", "style"); style.textContent = SVG_DOWNLOAD_STYLE; clone.insertBefore(style, clone.firstChild); return `\n${new XMLSerializer().serializeToString(clone)}`; }; const triggerFileDownload = (blob, filename) => { const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = filename; document.body.appendChild(link); link.click(); link.remove(); window.setTimeout(() => URL.revokeObjectURL(url), 1000); }; const downloadSvg = (svg, filenameBase) => { const source = serializePackingSvg(svg); triggerFileDownload(new Blob([source], {type: "image/svg+xml;charset=utf-8"}), sanitizedFileName(filenameBase, "svg")); }; const downloadPng = (svg, filenameBase) => { const source = serializePackingSvg(svg); const svgBlob = new Blob([source], {type: "image/svg+xml;charset=utf-8"}); const url = URL.createObjectURL(svgBlob); const image = new Image(); image.onload = () => { const size = 900; const canvas = document.createElement("canvas"); canvas.width = size; canvas.height = size; const context = canvas.getContext("2d"); context.clearRect(0, 0, size, size); context.drawImage(image, 0, 0, size, size); URL.revokeObjectURL(url); canvas.toBlob((blob) => { if (blob) { triggerFileDownload(blob, sanitizedFileName(filenameBase, "png")); } }, "image/png"); }; image.onerror = () => { URL.revokeObjectURL(url); window.alert("Could not prepare this rendering for download."); }; image.src = url; }; const handleImageDownload = (event) => { const button = event.target && event.target.closest ? event.target.closest("[data-download-image]") : null; if (!button) { return; } event.preventDefault(); event.stopPropagation(); if (event.stopImmediatePropagation) { event.stopImmediatePropagation(); } const scope = button.closest(".modal-panel, .preview-card, .record-card, .family-card, .packing-shell") || document; const svg = scope.querySelector("svg.packing-svg"); if (!svg) { window.alert("No coordinate rendering is available for this record yet."); return; } const format = button.getAttribute("data-download-image"); const filenameBase = button.getAttribute("data-download-filename") || svg.getAttribute("aria-label") || "packing-record"; if (format === "png") { downloadPng(svg, filenameBase); } else { downloadSvg(svg, filenameBase); } }; const normalizedLabels = (element) => { if (!element) { return []; } return [ element.getAttribute("aria-label"), element.innerText, element.textContent, ].map((value) => (value || "").replace(/\\s+/g, " ").trim().toLowerCase()).filter(Boolean); }; const isInsideBenchmarkUi = (element) => Boolean( element.closest(".packing-shell, .site-nav, .submit-shell, .schema-shell, .record-modal, .modal-panel") ); const hideGradioChrome = () => { Array.from(document.querySelectorAll("footer, button, a")).forEach((element) => { if (isInsideBenchmarkUi(element)) { return; } const labels = normalizedLabels(element).join(" "); const text = (element.innerText || element.textContent || "").replace(/\\s+/g, "").trim(); const rect = element.getBoundingClientRect ? element.getBoundingClientRect() : null; const iconOnlyTopRight = rect && rect.top >= 0 && rect.top < 84 && rect.right > window.innerWidth - 120 && rect.width <= 84 && rect.height <= 84 && Boolean(element.querySelector && element.querySelector("svg")); const chromeText = /settings|more|menu|useviaapi|builtwithgradio/.test(labels.replace(/\\s+/g, "")) || /^(\\.\\.\\.|…|⋯|⋮)$/.test(text); if (chromeText || iconOnlyTopRight || element.tagName.toLowerCase() === "footer") { element.style.setProperty("display", "none", "important"); element.setAttribute("aria-hidden", "true"); } }); }; const panelIds = { home: "home-panel", leaderboard: "leaderboard-panel", submit: "submit-entry-panel", }; const panelElements = (id) => Array.from(document.querySelectorAll(`[id="${id}"]`)); const setPanelVisible = (id, visible) => { const elements = panelElements(id); if (!elements.length) { return; } elements.forEach((element) => { if (visible) { element.style.setProperty("display", "block", "important"); } else { element.style.setProperty("display", "none", "important"); } }); }; const applyRoute = (route) => { const selected = route === "leaderboard" || route === "submit" ? route : "home"; if (document.body) { document.body.dataset.packingRoute = selected; } Object.entries(panelIds).forEach(([name, id]) => setPanelVisible(id, name === selected)); document.querySelectorAll("[data-route]").forEach((element) => { element.classList.toggle("active", element.getAttribute("data-route") === selected); }); hideGradioChrome(); }; const currentRoute = () => { const hash = (window.location.hash || "").replace(/^#/, ""); if (hash === "home" || hash === "home-panel") { return "home"; } if (hash === "leaderboard" || hash === "leaderboard-panel") { return "leaderboard"; } if (hash === "submit" || hash === "submit-entry-panel") { return "submit"; } if (hash === "leaderboard-table" || hash.startsWith("leaderboard-author-")) { return "leaderboard"; } const view = new URLSearchParams(window.location.search).get("view"); if (view === "leaderboard" || view === "submit") { return view; } return (document.body && document.body.dataset.packingRoute) || "home"; }; const syncRoute = () => applyRoute(currentRoute()); const routeFromClick = (event) => { const control = event.target && event.target.closest ? event.target.closest("[data-route], .site-nav-link") : null; if (!control) { return; } const route = control.getAttribute("data-route"); if (!route) { return; } if (route === "home") { event.preventDefault(); event.stopPropagation(); if (event.stopImmediatePropagation) { event.stopImmediatePropagation(); } window.location.assign(cleanHomeUrl()); return; } if (route === "leaderboard" || route === "submit") { event.preventDefault(); event.stopPropagation(); if (event.stopImmediatePropagation) { event.stopImmediatePropagation(); } window.history.pushState(null, "", `${cleanHomeUrl()}#${panelIds[route]}`); applyRoute(route); window.setTimeout(syncRoute, 40); } }; document.addEventListener("click", handleImageDownload, true); document.addEventListener("click", routeFromClick, true); window.addEventListener("popstate", syncRoute); window.addEventListener("hashchange", syncRoute); document.addEventListener("DOMContentLoaded", syncRoute); syncRoute(); [40, 140, 400, 900, 1800, 3200].forEach((delay) => window.setTimeout(syncRoute, delay)); new MutationObserver(syncRoute).observe(document.documentElement || document, {childList: true, subtree: true}); } """ APP_HEAD = f""" """ SAMPLE_JSON = """{ "schema_version": "packing-benchmark/v1", "case": "triincir@3", "item": {"type": "regular_polygon", "sides": 3, "side_length": 1}, "container": {"type": "circle", "radius": 0.9535486885675039}, "placements": [ {"x": -0.48390173508543094, "y": -0.09165750515220272, "rotation_radians": 2.1788614979094425}, {"x": 0.3742168507072296, "y": 0.03886972736029847, "rotation_radians": 2.1788160455636896}, {"x": -0.23841900077460812, "y": 0.43093650446493803, "rotation_radians": 3.2260428170876376} ] }""" CIRCLE_SQUARE_JSON = """{ "schema_version": "packing-benchmark/v1", "case": "cirinsqu@4", "item": {"type": "circle", "radius": 0.5}, "container": {"type": "rectangle", "width": 2.0, "height": 2.0}, "placements": [ {"x": -0.5, "y": -0.5, "rotation_radians": 0.0}, {"x": 0.5, "y": -0.5, "rotation_radians": 0.0}, {"x": -0.5, "y": 0.5, "rotation_radians": 0.0}, {"x": 0.5, "y": 0.5, "rotation_radians": 0.0} ] }""" RECTANGLE_JSON = """{ "schema_version": "packing-benchmark/v1", "case": "rectinrect@2", "item": {"type": "rectangle", "width": 2.0, "height": 1.0}, "container": {"type": "rectangle", "width": 2.0, "height": 2.0}, "placements": [ {"x": 0.0, "y": -0.5, "rotation_radians": 0.0}, {"x": 0.0, "y": 0.5, "rotation_radians": 0.0} ] }""" PYTHON_GENERATOR_SNIPPET = """import json def placement(x, y, rotation=0.0): return {"x": float(x), "y": float(y), "rotation_radians": float(rotation)} solution = { "schema_version": "packing-benchmark/v1", "case": "cirinsqu@4", "item": {"type": "circle", "radius": 0.5}, "container": {"type": "rectangle", "width": 2.0, "height": 2.0}, "placements": [ placement(-0.5, -0.5), placement(0.5, -0.5), placement(-0.5, 0.5), placement(0.5, 0.5), ], } print(json.dumps(solution, indent=2))""" JAVASCRIPT_GENERATOR_SNIPPET = """const placement = (x, y, rotation = 0) => ({ x, y, rotation_radians: rotation, }); const solution = { schema_version: "packing-benchmark/v1", case: "rectinrect@2", item: {type: "rectangle", width: 2.0, height: 1.0}, container: {type: "rectangle", width: 2.0, height: 2.0}, placements: [ placement(0, -0.5), placement(0, 0.5), ], }; console.log(JSON.stringify(solution, null, 2));""" SCHEMA_TEXT = """Canonical submission JSON: { "schema_version": "packing-benchmark/v1", "case": "triintri@1", "item": { "type": "regular_polygon", "sides": 3, "side_length": 1 }, "container": { "type": "regular_polygon", "sides": 3, "side_length": 1, "orientation_radians": 0 }, "placements": [ {"x": 0, "y": 0, "rotation_radians": 0} ] } Supported shapes: - regular_polygon: sides plus side_length or circumradius - circle: radius or diameter - rectangle: width and height If redundant dimensions are included, they must agree. For example, side_length and circumradius must describe the same regular polygon. The metric is computed from the geometry that is actually verified. Coordinate convention: - origin at the container center - item placements are item centers - rotations are radians counterclockwise - touching is legal; overlap and protrusion are rejected """ EXAMPLES_MD = f"""### How Submission Works Paste one canonical coordinate JSON object, click **Verify**, then click **Submit Entry** if it passes. The geometry tolerance is fixed by the evaluator and is not user-selectable. For an existing case, a submission must improve the current top metric by at least `0.0001` to be accepted as a new record. Cases with no current record can be submitted through `n = {SUBMISSION_MAX_NEW_CASE_N}`. In these tables, smaller metric values are better. ### Test Locally With The Open Verifier The verifier code is public at [{VERIFIER_REPO_URL}]({VERIFIER_REPO_URL}). It is dependency-free Python and exposes the same geometry check used by this Space. ```bash python -m pip install git+{VERIFIER_REPO_URL}.git packing-verifier verify solution.json packing-verifier verify solution.json --json ``` The local verifier checks geometry and reports the leaderboard metric. The Space still applies the live record gate when you submit: existing cases must improve the current top metric by at least `0.0001`. ### Three Triangles In A Circle Example This prefilled example is a verified `triincir@3` coordinate layout and a good shape for checking the schema: ```json {SAMPLE_JSON} ``` ### Submission Checklist - The `case` suffix must match the number of placements, for example `triincir@3` has three placements. - Use container-centered coordinates. - Use radians for `rotation_radians`. - Click **Verify** before submitting; the preview is rendered from the same canonical JSON that is archived. - Existing cases must beat the current top metric by at least `0.0001`. - Cases with no current record can be submitted when `n <= {SUBMISSION_MAX_NEW_CASE_N}`. """ SCHEMA_DOCS_MD = """### Canonical Fields Required top-level fields: ```json { "case": "triintri@1", "item": {"type": "regular_polygon", "sides": 3, "side_length": 1}, "container": {"type": "regular_polygon", "sides": 3, "side_length": 1}, "placements": [{"x": 0, "y": 0, "rotation_radians": 0}] } ``` Supported shape specs: - `regular_polygon`: `sides` plus `side_length` or `circumradius` - `circle`: `radius` or `diameter` - `rectangle`: `width` and `height` The verifier uses a fixed geometry tolerance. Existing cases must improve the current top metric by at least `0.0001` before they can be submitted as records. Cases with no current record can be submitted through `n = 100`. """ + f""" ### Four Circles In A Square ```json {CIRCLE_SQUARE_JSON} ``` ### Two Rectangles In A Rectangle ```json {RECTANGLE_JSON} ``` """ MONTHS = ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ) def esc(value: Any) -> str: return html.escape("" if value is None else str(value), quote=True) def code_block(code: str, language: str = "json") -> str: return f'
{esc(code)}'
def submission_guide_html() -> str:
return f"""
A submission is one JSON object. The container is centered at the origin, every placement is an item center,
rotations are counterclockwise radians, and the number after @ in case must match
the number of placements.
sides plus side_length or circumradius.radius or diameter.width and height. Use this for square containers too.
Redundant dimensions must agree. If both side_length and circumradius are present,
the verifier rejects the JSON unless they describe the same polygon.
This is a compact sanity check for circle placements and square containers.
{code_block(CIRCLE_SQUARE_JSON)}Rectangles use the same center and rotation convention as polygons.
{code_block(RECTANGLE_JSON)}Use this pattern when exporting coordinates from a solver or notebook.
{code_block(PYTHON_GENERATOR_SNIPPET, "python")}This produces the same canonical shape from a browser, Node script, or visualization tool.
{code_block(JAVASCRIPT_GENERATOR_SNIPPET, "javascript")}| Author | Date | Metric | Source |
|---|
{family_description(summary)}
verified shape packing records, heavily inspired by Erich Friedman's Packing Center.
Choose a family to view its verified packing records.
Loading records...
| # | Author | Total top | {class_headers}
|---|
Paste one canonical coordinate JSON object. Existing cases must beat the current top metric by at least 0.0001; new no-record cases are accepted through n={SUBMISSION_MAX_NEW_CASE_N}. The open-source local verifier is available at github.com/Nathan-Roll1/packing-verifier.
Paste one canonical coordinate JSON object. The evaluator uses a fixed tolerance, requires a 0.0001 metric improvement for existing cases, and accepts new no-record cases through n={SUBMISSION_MAX_NEW_CASE_N}.
') json_code = gr.Textbox( **supported_gradio_kwargs( gr.Textbox, value=SAMPLE_JSON, label="Coordinate JSON", lines=18, max_lines=30, show_copy_button=True, ) ) with gr.Column(scale=5, elem_classes=["submit-meta"]): with gr.Group(elem_classes=["submit-panel"]): gr.HTML('Choose an existing credited author or type a new name.
') submitter = gr.Dropdown( **supported_gradio_kwargs( gr.Dropdown, choices=existing_author_choices(), label="Author", value=None, allow_custom_value=True, filterable=True, info="Start typing to search existing authors. New names are accepted.", ) ) source_url = gr.Textbox(label="Source URL", placeholder="Optional") notes = gr.Textbox(label="Notes", lines=3, placeholder="Optional method or provenance note") with gr.Row(elem_classes=["submit-actions"]): verify_btn = gr.Button("Verify", variant="secondary") submit_btn = gr.Button("Submit Entry", variant="primary") with gr.Row(elem_classes=["submit-layout"]): with gr.Column(scale=5, elem_classes=["submit-results"]): with gr.Group(elem_classes=["submit-results-card"]): gr.HTML('