joker727 commited on
Commit
5896096
·
1 Parent(s): c909f5f

Add 4BHK generation and deployable downloads

Browse files
Files changed (3) hide show
  1. app.py +114 -7
  2. core/pdf_templates.py +8 -3
  3. core/pdf_templates_4bhk.py +186 -0
app.py CHANGED
@@ -13,6 +13,7 @@ from core.visualizer import draw_comparison, fig_to_bytes
13
  from core import pdf_templates
14
  from core import pdf_templates_2bhk
15
  from core import pdf_templates_3bhk
 
16
  from core.render_plan import fig_comparison
17
  from floorplan_editor import floor_plan_editor
18
 
@@ -130,7 +131,7 @@ def score_table(fp):
130
  return pd.DataFrame(
131
  {
132
  "Metric": ["Fitness", "Vastu", "Adjacency", "Cost",
133
- "Space Usage", "Area Deviation", "Layout Compactness"],
134
  "Score": [
135
  f"{score['Fitness']:.3f}",
136
  f"{score['VS'] * 100:.0f}%",
@@ -144,6 +145,85 @@ def score_table(fp):
144
  )
145
 
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  def clone_floorplan(fp):
148
  rooms = [Room(r.name, r.x, r.y, r.w, r.h) for r in fp.rooms]
149
  cloned = FloorPlan(rooms, fp.plot_w, fp.plot_h)
@@ -200,10 +280,10 @@ with st.sidebar:
200
  st.markdown("### Plan Type")
201
  plan_type = st.radio(
202
  "Configuration",
203
- options=["1BHK", "2BHK", "3BHK"],
204
  index=0,
205
  horizontal=True,
206
- help="1BHK/2BHK/3BHK use their respective PDF-style reference plans.",
207
  )
208
  # If the user switches plan type, drop the previously generated plans so the
209
  # screen never shows stale plans of the other type. They must click
@@ -296,7 +376,7 @@ if generate_btn:
296
 
297
  status.markdown("**Step 2/4** - Geometry predictor places rooms")
298
  progress_bar.progress(45, text="Geometry Predictor: producing raw plans...")
299
- plan_count = int(os.getenv("PLAN_COUNT", "6"))
300
  if plan_type == "3BHK":
301
  plan_pairs = pdf_templates_3bhk.generate_bhk3_pdf_population(
302
  plot_w=plot_w,
@@ -305,6 +385,14 @@ if generate_btn:
305
  road_side=road_side,
306
  n=plan_count,
307
  )
 
 
 
 
 
 
 
 
308
  elif plan_type == "2BHK":
309
  plan_pairs = pdf_templates_2bhk.generate_bhk2_pdf_population(
310
  plot_w=plot_w,
@@ -381,7 +469,23 @@ if top_plans:
381
  left_title="AI Generated",
382
  right_title="Optimised",
383
  )
384
- st.image(fig_to_bytes(comparison_fig), width="stretch")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
 
386
  left, right = st.columns(2)
387
  with left:
@@ -391,6 +495,9 @@ if top_plans:
391
  st.markdown("**Optimised plan objective scores**")
392
  st.dataframe(score_table(opt_fp), hide_index=True, width="stretch")
393
 
 
 
 
394
  st.markdown("**Interactive Room Editor — Optimised Plan**")
395
  st.caption(
396
  "Drag rooms to reposition · Drag corner handles to resize · "
@@ -424,7 +531,7 @@ if top_plans:
424
  st.markdown('<div class="section-header">Ranked Comparison</div>', unsafe_allow_html=True)
425
  rows = []
426
  for idx, pair in enumerate(top_plans):
427
- raw = pair["optimised"].scores
428
  peak = pair.get("peak", pair["optimised"]).scores
429
  rows.append(
430
  {
@@ -444,7 +551,7 @@ else:
444
  """
445
  <div style="text-align:center; padding: 3rem 2rem; color: #8B949E;">
446
  <h3 style="color: #4FC3F7;">Configure the plot and optional rooms in the sidebar</h3>
447
- <p>The demo will generate 3 raw plans, optimise them, and compare fitness scores.</p>
448
  </div>
449
  """,
450
  unsafe_allow_html=True,
 
13
  from core import pdf_templates
14
  from core import pdf_templates_2bhk
15
  from core import pdf_templates_3bhk
16
+ from core import pdf_templates_4bhk
17
  from core.render_plan import fig_comparison
18
  from floorplan_editor import floor_plan_editor
19
 
 
131
  return pd.DataFrame(
132
  {
133
  "Metric": ["Fitness", "Vastu", "Adjacency", "Cost",
134
+ "Space Usage", "Area Compliance", "Layout Compactness"],
135
  "Score": [
136
  f"{score['Fitness']:.3f}",
137
  f"{score['VS'] * 100:.0f}%",
 
145
  )
146
 
147
 
148
+ def score_formula_table(fp):
149
+ score = fp.scores
150
+ failed = score.get("hard_failed", 0)
151
+ return pd.DataFrame(
152
+ {
153
+ "UI metric": [
154
+ "Fitness",
155
+ "Vastu",
156
+ "Adjacency",
157
+ "Cost",
158
+ "Space Usage",
159
+ "Area Compliance",
160
+ "Layout Compactness",
161
+ ],
162
+ "Calculation used": [
163
+ "30% VS + 25% AQ + 15% CS + 15% SU + 10% AC + 5% LC - hard-constraint penalty",
164
+ "matched Vastu rule weight / total applicable Vastu rule weight x 100",
165
+ "earned adjacency weight / required adjacency weight, minus forbidden/avoid penalties x 100",
166
+ "1.0 when estimated cost/sqft <= 1.05 x base rate; 0.0 when >= 1.40 x base rate; linear between x 100",
167
+ "occupied buildable-area grid cells / total inner setback area x 100",
168
+ "average room-size compliance against min/max guide table x 100",
169
+ "0.4 x bounding-box compactness + 0.6 x room fill inside bounding box x 100",
170
+ ],
171
+ "Current value": [
172
+ f"{score['Fitness']:.3f} ({failed} hard checks failed)",
173
+ f"{score['VS'] * 100:.0f}%",
174
+ f"{score['AQ'] * 100:.0f}%",
175
+ f"{score['CS'] * 100:.0f}%",
176
+ f"{score['SU'] * 100:.0f}%",
177
+ f"{score['AC'] * 100:.0f}%",
178
+ f"{score['LC'] * 100:.0f}%",
179
+ ],
180
+ }
181
+ )
182
+
183
+
184
+ def floorplan_to_dxf(fp, road_side="S"):
185
+ def esc(text):
186
+ return str(text).replace("\n", " ").replace("\r", " ")
187
+
188
+ lines = [
189
+ "0", "SECTION", "2", "HEADER", "0", "ENDSEC",
190
+ "0", "SECTION", "2", "TABLES",
191
+ "0", "TABLE", "2", "LAYER", "70", "3",
192
+ "0", "LAYER", "2", "PLOT", "70", "0", "62", "7", "6", "CONTINUOUS",
193
+ "0", "LAYER", "2", "SETBACK", "70", "0", "62", "1", "6", "DASHED",
194
+ "0", "LAYER", "2", "ROOMS", "70", "0", "62", "5", "6", "CONTINUOUS",
195
+ "0", "ENDTAB", "0", "ENDSEC",
196
+ "0", "SECTION", "2", "ENTITIES",
197
+ ]
198
+
199
+ def rect(layer, x, y, w, h):
200
+ pts = [(x, y), (x + w, y), (x + w, y + h), (x, y + h), (x, y)]
201
+ lines.extend(["0", "LWPOLYLINE", "8", layer, "90", str(len(pts)), "70", "1"])
202
+ for px, py in pts:
203
+ lines.extend(["10", f"{px:.3f}", "20", f"{py:.3f}"])
204
+
205
+ def text(layer, x, y, height, value):
206
+ lines.extend([
207
+ "0", "TEXT", "8", layer, "10", f"{x:.3f}", "20", f"{y:.3f}",
208
+ "40", f"{height:.3f}", "1", esc(value), "50", "0", "72", "1",
209
+ "11", f"{x:.3f}", "21", f"{y:.3f}", "73", "2",
210
+ ])
211
+
212
+ rect("PLOT", 0, 0, fp.plot_w, fp.plot_h)
213
+ sb_road, sb_other = 6.56, 3.28
214
+ left = sb_road if road_side == "W" else sb_other
215
+ right = sb_road if road_side == "E" else sb_other
216
+ bottom = sb_road if road_side == "S" else sb_other
217
+ top = sb_road if road_side == "N" else sb_other
218
+ rect("SETBACK", left, bottom, fp.plot_w - left - right, fp.plot_h - bottom - top)
219
+ for room in fp.rooms:
220
+ rect("ROOMS", room.x, room.y, room.w, room.h)
221
+ label = f"{pretty_room(room.name)} {room.w:.1f} x {room.h:.1f} ft"
222
+ text("ROOMS", room.cx, room.cy, max(1.0, min(room.w, room.h) * 0.16), label)
223
+ lines.extend(["0", "ENDSEC", "0", "EOF"])
224
+ return "\n".join(lines).encode("ascii", errors="ignore")
225
+
226
+
227
  def clone_floorplan(fp):
228
  rooms = [Room(r.name, r.x, r.y, r.w, r.h) for r in fp.rooms]
229
  cloned = FloorPlan(rooms, fp.plot_w, fp.plot_h)
 
280
  st.markdown("### Plan Type")
281
  plan_type = st.radio(
282
  "Configuration",
283
+ options=["1BHK", "2BHK", "3BHK", "4BHK"],
284
  index=0,
285
  horizontal=True,
286
+ help="1BHK/2BHK/3BHK/4BHK use their respective PDF-style reference templates.",
287
  )
288
  # If the user switches plan type, drop the previously generated plans so the
289
  # screen never shows stale plans of the other type. They must click
 
376
 
377
  status.markdown("**Step 2/4** - Geometry predictor places rooms")
378
  progress_bar.progress(45, text="Geometry Predictor: producing raw plans...")
379
+ plan_count = int(os.getenv("PLAN_COUNT", "20"))
380
  if plan_type == "3BHK":
381
  plan_pairs = pdf_templates_3bhk.generate_bhk3_pdf_population(
382
  plot_w=plot_w,
 
385
  road_side=road_side,
386
  n=plan_count,
387
  )
388
+ elif plan_type == "4BHK":
389
+ plan_pairs = pdf_templates_4bhk.generate_bhk4_pdf_population(
390
+ plot_w=plot_w,
391
+ plot_h=plot_h,
392
+ selected_optional=optional_rooms,
393
+ road_side=road_side,
394
+ n=plan_count,
395
+ )
396
  elif plan_type == "2BHK":
397
  plan_pairs = pdf_templates_2bhk.generate_bhk2_pdf_population(
398
  plot_w=plot_w,
 
469
  left_title="AI Generated",
470
  right_title="Optimised",
471
  )
472
+ comparison_png = fig_to_bytes(comparison_fig).getvalue()
473
+ st.image(comparison_png, width="stretch")
474
+ dl_left, dl_right = st.columns(2)
475
+ dl_left.download_button(
476
+ "Download plan PNG",
477
+ data=comparison_png,
478
+ file_name=f"{plan_type.lower()}_plan_{idx + 1}.png",
479
+ mime="image/png",
480
+ key=f"png_download_{idx}",
481
+ )
482
+ dl_right.download_button(
483
+ "Download AutoCAD DXF",
484
+ data=floorplan_to_dxf(opt_fp, road_side),
485
+ file_name=f"{plan_type.lower()}_plan_{idx + 1}.dxf",
486
+ mime="application/dxf",
487
+ key=f"dxf_download_{idx}",
488
+ )
489
 
490
  left, right = st.columns(2)
491
  with left:
 
495
  st.markdown("**Optimised plan objective scores**")
496
  st.dataframe(score_table(opt_fp), hide_index=True, width="stretch")
497
 
498
+ with st.expander("Calculation details for UI percentages"):
499
+ st.dataframe(score_formula_table(opt_fp), hide_index=True, width="stretch")
500
+
501
  st.markdown("**Interactive Room Editor — Optimised Plan**")
502
  st.caption(
503
  "Drag rooms to reposition · Drag corner handles to resize · "
 
531
  st.markdown('<div class="section-header">Ranked Comparison</div>', unsafe_allow_html=True)
532
  rows = []
533
  for idx, pair in enumerate(top_plans):
534
+ raw = pair["raw"].scores
535
  peak = pair.get("peak", pair["optimised"]).scores
536
  rows.append(
537
  {
 
551
  """
552
  <div style="text-align:center; padding: 3rem 2rem; color: #8B949E;">
553
  <h3 style="color: #4FC3F7;">Configure the plot and optional rooms in the sidebar</h3>
554
+ <p>The demo will generate 20 raw plans, optimise them, and compare fitness scores.</p>
555
  </div>
556
  """,
557
  unsafe_allow_html=True,
core/pdf_templates.py CHANGED
@@ -1995,12 +1995,17 @@ def _enforce_size_hierarchy(boxes):
1995
  # POOJA must be the SMALLEST room — never bigger than any other room.
1996
  pooja = next((b for b in boxes if b["name"] == "pooja_room"), None)
1997
  if pooja is not None:
 
 
 
 
 
1998
  others = [b["w"] * b["h"] for b in boxes
1999
  if b is not pooja and b["name"] not in _FIXED]
2000
  if others:
2001
- # cap pooja strictly below the smallest other room (and keep it
2002
- # compact: a pooja niche is ~9-30 sqft).
2003
- cap = max(9.0, min(30.0, min(others) * 0.85))
2004
  if pooja["w"] * pooja["h"] > cap:
2005
  side = max(3.0, min(6.0, cap ** 0.5))
2006
  pooja["w"] = min(pooja["w"], side)
 
1995
  # POOJA must be the SMALLEST room — never bigger than any other room.
1996
  pooja = next((b for b in boxes if b["name"] == "pooja_room"), None)
1997
  if pooja is not None:
1998
+ if pooja["w"] * pooja["h"] < 15.0:
1999
+ if pooja["w"] <= pooja["h"]:
2000
+ pooja["w"] = max(pooja["w"], 15.0 / max(pooja["h"], 0.1))
2001
+ else:
2002
+ pooja["h"] = max(pooja["h"], 15.0 / max(pooja["w"], 0.1))
2003
  others = [b["w"] * b["h"] for b in boxes
2004
  if b is not pooja and b["name"] not in _FIXED]
2005
  if others:
2006
+ # cap pooja strictly below the smallest other room while respecting
2007
+ # the project's 15 sqft minimum for a usable pooja niche.
2008
+ cap = max(15.0, min(30.0, min(others) * 0.85))
2009
  if pooja["w"] * pooja["h"] > cap:
2010
  side = max(3.0, min(6.0, cap ** 0.5))
2011
  pooja["w"] = min(pooja["w"], side)
core/pdf_templates_4bhk.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ PDF-style 4BHK layout templates.
3
+
4
+ These templates use the shared PDF-template engine but start from layouts that
5
+ are actually shaped like a 4BHK: master bedroom plus three secondary bedrooms,
6
+ with public/service spaces grouped separately so bedrooms do not collapse into
7
+ thin strips.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import List, Optional, Tuple
13
+
14
+ from .constants import ROOM_MIN_AREA
15
+ from .pdf_templates import build_from_template, make_floorplan, _T
16
+
17
+
18
+ REF4_W = 40.0 - 2 * 3.92
19
+ REF60_H = 60.0 - 6.5 - 3.25
20
+ REF50_H = 50.0 - 6.5 - 3.25
21
+ REF45_H = 45.0 - 6.5 - 3.25
22
+
23
+
24
+ def _cols(ref_w, ref_h, columns):
25
+ rooms = []
26
+ wsum = sum(w for w, _ in columns) or 1.0
27
+ x = 0.0
28
+ for k, (wf, rows) in enumerate(columns):
29
+ cw = ref_w * (wf / wsum)
30
+ if k == len(columns) - 1:
31
+ cw = ref_w - x
32
+ hsum = sum(h for _, h in rows) or 1.0
33
+ y = 0.0
34
+ for m, (name, hf) in enumerate(rows):
35
+ ch = ref_h * (hf / hsum)
36
+ if m == len(rows) - 1:
37
+ ch = ref_h - y
38
+ rooms.append(_T(name, round(x, 2), round(y, 2),
39
+ round(cw, 2), round(ch, 2)))
40
+ y += ch
41
+ x += cw
42
+ return rooms
43
+
44
+
45
+ _TEMPLATES_4BHK: List[dict] = [
46
+ dict(name="4bhk_pdf_p1", entry="top", ref_w=REF4_W, ref_h=REF60_H,
47
+ rooms=_cols(REF4_W, REF60_H, [
48
+ (0.34, [("external_staircase", 0.14), ("foyer", 0.08),
49
+ ("bedroom_03", 0.26), ("attached_bathroom", 0.10),
50
+ ("master_bedroom", 0.42)]),
51
+ (0.33, [("living_room", 0.30), ("dining_room", 0.16),
52
+ ("kitchen", 0.22), ("internal_corridor", 0.10),
53
+ ("study", 0.22)]),
54
+ (0.33, [("balcony", 0.10), ("utility_area", 0.10),
55
+ ("common_bathroom", 0.10), ("bedroom_02", 0.32),
56
+ ("bedroom_01", 0.30), ("pooja_room", 0.08)]),
57
+ ])),
58
+ dict(name="4bhk_pdf_p2", entry="top", ref_w=REF4_W, ref_h=REF60_H,
59
+ rooms=_cols(REF4_W, REF60_H, [
60
+ (0.32, [("external_staircase", 0.16), ("foyer", 0.08),
61
+ ("living_room", 0.28), ("dining_room", 0.16),
62
+ ("kitchen", 0.20), ("internal_corridor", 0.12)]),
63
+ (0.34, [("utility_area", 0.08), ("bedroom_03", 0.28),
64
+ ("attached_bathroom", 0.10), ("internal_corridor", 0.08),
65
+ ("master_bedroom", 0.46)]),
66
+ (0.34, [("balcony", 0.12), ("common_bathroom", 0.10),
67
+ ("study", 0.12), ("bedroom_02", 0.30),
68
+ ("bedroom_01", 0.28), ("pooja_room", 0.08)]),
69
+ ])),
70
+ dict(name="4bhk_pdf_p3", entry="top", ref_w=REF4_W, ref_h=REF50_H,
71
+ rooms=_cols(REF4_W, REF50_H, [
72
+ (0.36, [("external_staircase", 0.15), ("foyer", 0.08),
73
+ ("utility_area", 0.08), ("bedroom_03", 0.27),
74
+ ("master_bedroom", 0.42)]),
75
+ (0.32, [("living_room", 0.32), ("dining_room", 0.18),
76
+ ("kitchen", 0.22), ("attached_bathroom", 0.08),
77
+ ("internal_corridor", 0.20)]),
78
+ (0.32, [("balcony", 0.12), ("common_bathroom", 0.10),
79
+ ("bedroom_02", 0.34), ("bedroom_01", 0.34),
80
+ ("pooja_room", 0.10)]),
81
+ ])),
82
+ dict(name="4bhk_pdf_p4", entry="top", ref_w=REF4_W, ref_h=REF45_H,
83
+ rooms=_cols(REF4_W, REF45_H, [
84
+ (0.35, [("external_staircase", 0.18), ("foyer", 0.08),
85
+ ("bedroom_03", 0.30), ("master_bedroom", 0.44)]),
86
+ (0.33, [("living_room", 0.30), ("dining_room", 0.18),
87
+ ("kitchen", 0.24), ("attached_bathroom", 0.12),
88
+ ("internal_corridor", 0.16)]),
89
+ (0.32, [("balcony", 0.12), ("utility_area", 0.10),
90
+ ("common_bathroom", 0.12),
91
+ ("internal_corridor", 0.08), ("bedroom_02", 0.32),
92
+ ("bedroom_01", 0.28), ("pooja_room", 0.06)]),
93
+ ])),
94
+ ]
95
+
96
+
97
+ _CORE_4BHK = {"external_staircase", "foyer", "living_room", "dining_room",
98
+ "kitchen", "utility_area", "master_bedroom",
99
+ "attached_bathroom", "bedroom_01", "bedroom_02",
100
+ "bedroom_03", "common_bathroom", "pooja_room", "balcony",
101
+ "internal_corridor"}
102
+ _OPTIONAL_4BHK = {"study", "lift"}
103
+
104
+
105
+ def _clean_4bhk_boxes(boxes: List[dict], selected_optional: Optional[List[str]]):
106
+ selected = set(selected_optional or [])
107
+ keep = []
108
+ by_name = {}
109
+ for box in boxes:
110
+ by_name.setdefault(box["name"], []).append(box)
111
+
112
+ singleton_names = {
113
+ "external_staircase", "foyer", "living_room", "dining_room",
114
+ "kitchen", "utility_area", "master_bedroom", "attached_bathroom",
115
+ "bedroom_01", "bedroom_02", "bedroom_03", "common_bathroom",
116
+ "pooja_room", "internal_corridor", "study", "balcony",
117
+ }
118
+ for name, group in by_name.items():
119
+ group = sorted(group, key=lambda b: b["w"] * b["h"], reverse=True)
120
+ if name == "study" and "study" not in selected:
121
+ continue
122
+ if name in singleton_names:
123
+ box = group[0]
124
+ if name == "pooja_room" and box["w"] * box["h"] < 15.0:
125
+ if box["w"] <= box["h"]:
126
+ box["w"] = max(box["w"], 15.0 / max(box["h"], 0.1))
127
+ else:
128
+ box["h"] = max(box["h"], 15.0 / max(box["w"], 0.1))
129
+ if name in {"balcony", "study", "internal_corridor"} \
130
+ and box["w"] * box["h"] < ROOM_MIN_AREA.get(name, 0):
131
+ continue
132
+ keep.append(box)
133
+ else:
134
+ keep.extend(group)
135
+ return keep
136
+
137
+
138
+ def list_templates() -> List[str]:
139
+ return [t["name"] for t in _TEMPLATES_4BHK]
140
+
141
+
142
+ def apply_template(index: int, plot_w: float, plot_h: float,
143
+ road_side: str = "S",
144
+ selected_optional: Optional[List[str]] = None,
145
+ jitter: float = 0.0, seed: Optional[int] = None,
146
+ fill_gaps: bool = True) -> List[dict]:
147
+ tpl = _TEMPLATES_4BHK[index % len(_TEMPLATES_4BHK)]
148
+ boxes = build_from_template(tpl, plot_w, plot_h, road_side,
149
+ selected_optional, jitter, seed, fill_gaps,
150
+ core=_CORE_4BHK, optional=_OPTIONAL_4BHK)
151
+ return _clean_4bhk_boxes(boxes, selected_optional)
152
+
153
+
154
+ def template_floorplan(index: int, plot_w: float, plot_h: float,
155
+ road_side: str = "S",
156
+ selected_optional: Optional[List[str]] = None,
157
+ jitter: float = 0.0, seed: Optional[int] = None,
158
+ fill_gaps: bool = True):
159
+ boxes = apply_template(index, plot_w, plot_h, road_side,
160
+ selected_optional, jitter, seed, fill_gaps)
161
+ return make_floorplan(boxes, plot_w, plot_h,
162
+ _TEMPLATES_4BHK[index % len(_TEMPLATES_4BHK)]["name"])
163
+
164
+
165
+ def generate_bhk4_pdf_population(plot_w: float, plot_h: float,
166
+ selected_optional: Optional[List[str]] = None,
167
+ road_side: str = "S", n: int = 10,
168
+ base_seed: int = 0,
169
+ raw_jitter: float = 1.3) -> List[Tuple]:
170
+ pairs = []
171
+ tall = (plot_h / max(plot_w, 1e-6)) >= 1.35 if road_side in ("S", "N") \
172
+ else (plot_w / max(plot_h, 1e-6)) >= 1.35
173
+ order = [0, 2] if tall else [2, 0]
174
+ n_tpl = len(order)
175
+ for i in range(n):
176
+ idx = order[i % n_tpl]
177
+ seed = base_seed + i * 109 + 11
178
+ raw = template_floorplan(idx, plot_w, plot_h, road_side,
179
+ selected_optional, jitter=raw_jitter,
180
+ seed=seed, fill_gaps=True)
181
+ opt = template_floorplan(idx, plot_w, plot_h, road_side,
182
+ selected_optional, jitter=0.0,
183
+ seed=seed, fill_gaps=True)
184
+ raw.template_name = opt.template_name
185
+ pairs.append((raw, opt))
186
+ return pairs