MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / panel_layout_generation

Function panel_layout_generation

PosterAgent/tree_split_layout.py:507–550  ·  view source on GitHub ↗
(panels, x, y, w, h)

Source from the content-addressed store, hash-verified

505
506
507def panel_layout_generation(panels, x, y, w, h):
508 # If only 1 panel, place it entirely
509 if len(panels) == 1:
510 p = panels[0]
511 cur_rp = (w/h) if h>1e-9 else p["rp"]
512 loss = abs(p["rp"] - cur_rp)
513 arrangement = [{
514 "panel_name": p["section_name"],
515 "panel_id": p["panel_id"],
516 "x": x, "y": y,
517 "width": w, "height": h
518 }]
519 return loss, arrangement
520
521 best_loss = float('inf')
522 best_arr = []
523 total_sp = sum(pp["sp"] for pp in panels)
524 n = len(panels)
525
526 for i in range(1, n):
527 subset1 = panels[:i]
528 subset2 = panels[i:]
529 sp1 = sum(pp["sp"] for pp in subset1)
530 ratio = sp1 / total_sp
531
532 # horizontal
533 h_top = ratio * h
534 if 0 < h_top < h:
535 l1, a1 = panel_layout_generation(subset1, x, y, w, h_top)
536 l2, a2 = panel_layout_generation(subset2, x, y + h_top, w, h - h_top)
537 if (l1 + l2) < best_loss:
538 best_loss = l1 + l2
539 best_arr = a1 + a2
540
541 # vertical
542 w_left = ratio * w
543 if 0 < w_left < w:
544 l1, a1 = panel_layout_generation(subset1, x, y, w_left, h)
545 l2, a2 = panel_layout_generation(subset2, x + w_left, y, w - w_left, h)
546 if (l1 + l2) < best_loss:
547 best_loss = l1 + l2
548 best_arr = a1 + a2
549
550 return best_loss, best_arr
551
552def split_textbox(textbox, ratio):
553 """

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected