planscript 1.0.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,754 @@
1
+ # PlanScript Language Reference
2
+
3
+ This document provides a complete specification of the PlanScript language for defining floor plans. It is intended as both a reference for developers and as context for LLMs (ChatGPT, Claude, etc.) to generate valid PlanScript code.
4
+
5
+ > **For LLM users:** Provide this document as context when asking an LLM to generate PlanScript floor plans.
6
+
7
+ ## Table of Contents
8
+
9
+ - [File Structure](#file-structure)
10
+ - [Units](#units)
11
+ - [Origin](#origin)
12
+ - [Defaults](#defaults)
13
+ - [Plan Block](#plan-block)
14
+ - [Footprint](#footprint)
15
+ - [Rooms](#rooms)
16
+ - [Rectangle with Two Corners](#rectangle-with-two-corners)
17
+ - [Rectangle with Position and Size](#rectangle-with-position-and-size)
18
+ - [Rectangle with Size and Attachment](#rectangle-with-size-and-attachment)
19
+ - [Rectangle with Span](#rectangle-with-span)
20
+ - [Polygon Rooms](#polygon-rooms)
21
+ - [Room Labels](#room-labels)
22
+ - [Room References](#room-references)
23
+ - [Openings](#openings)
24
+ - [Doors](#doors)
25
+ - [Windows](#windows)
26
+ - [Position Syntax](#position-syntax)
27
+ - [Assertions](#assertions)
28
+ - [Comments](#comments)
29
+ - [Complete Examples](#complete-examples)
30
+
31
+ ---
32
+
33
+ ## File Structure
34
+
35
+ A PlanScript file (`.psc`) has the following structure. All top-level declarations are optional except for `plan`.
36
+
37
+ ```planscript
38
+ units <unit> # Optional: set measurement units
39
+ origin (<x>, <y>) # Optional: set coordinate origin
40
+ defaults { ... } # Optional: default values for openings
41
+
42
+ plan "<name>" { # Required: the floor plan definition
43
+ footprint ... # Required: building boundary
44
+ room ... { ... } # One or more rooms
45
+ opening ... { ... } # Zero or more openings (doors/windows)
46
+ assert ... # Zero or more validation assertions
47
+ }
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Units
53
+
54
+ Sets the measurement unit for all coordinates and dimensions.
55
+
56
+ ```planscript
57
+ units <unit>
58
+ ```
59
+
60
+ **Valid units:**
61
+ | Unit | Description |
62
+ |------|-------------|
63
+ | `m` | Meters (default) |
64
+ | `cm` | Centimeters |
65
+ | `mm` | Millimeters |
66
+ | `ft` | Feet |
67
+ | `in` | Inches |
68
+
69
+ **Example:**
70
+ ```planscript
71
+ units m
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Origin
77
+
78
+ Sets the coordinate origin point. Default is `(0, 0)`.
79
+
80
+ ```planscript
81
+ origin (<x>, <y>)
82
+ ```
83
+
84
+ **Example:**
85
+ ```planscript
86
+ origin (0, 0)
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Defaults
92
+
93
+ Sets default values for door and window widths. When set, the `width` property becomes optional in opening definitions.
94
+
95
+ ```planscript
96
+ defaults {
97
+ door_width <value>
98
+ window_width <value>
99
+ }
100
+ ```
101
+
102
+ **Example:**
103
+ ```planscript
104
+ defaults {
105
+ door_width 0.9
106
+ window_width 1.2
107
+ }
108
+ ```
109
+
110
+ ---
111
+
112
+ ## Plan Block
113
+
114
+ The main container for the floor plan. A file must have exactly one plan block.
115
+
116
+ ```planscript
117
+ plan "<name>" {
118
+ # footprint, rooms, openings, assertions
119
+ }
120
+ ```
121
+
122
+ The name is optional:
123
+ ```planscript
124
+ plan {
125
+ # ...
126
+ }
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Footprint
132
+
133
+ Defines the building boundary. Required inside the plan block.
134
+
135
+ ### Rectangle Footprint
136
+
137
+ ```planscript
138
+ footprint rect (<x1>, <y1>) (<x2>, <y2>)
139
+ ```
140
+
141
+ **Example:**
142
+ ```planscript
143
+ footprint rect (0, 0) (20, 15)
144
+ ```
145
+
146
+ ### Polygon Footprint
147
+
148
+ For non-rectangular buildings (L-shaped, etc.):
149
+
150
+ ```planscript
151
+ footprint polygon [
152
+ (<x1>, <y1>),
153
+ (<x2>, <y2>),
154
+ (<x3>, <y3>),
155
+ ...
156
+ ]
157
+ ```
158
+
159
+ **Example (L-shaped building):**
160
+ ```planscript
161
+ footprint polygon [
162
+ (0, 0),
163
+ (20, 0),
164
+ (20, 10),
165
+ (12, 10),
166
+ (12, 15),
167
+ (0, 15)
168
+ ]
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Rooms
174
+
175
+ Rooms define the interior spaces. Each room has a unique identifier and a shape.
176
+
177
+ ### Rectangle with Two Corners
178
+
179
+ ```planscript
180
+ room <id> {
181
+ rect (<x1>, <y1>) (<x2>, <y2>)
182
+ }
183
+ ```
184
+
185
+ **Example:**
186
+ ```planscript
187
+ room living {
188
+ rect (1, 1) (9, 7)
189
+ }
190
+ ```
191
+
192
+ ### Rectangle with Position and Size
193
+
194
+ ```planscript
195
+ room <id> {
196
+ rect at (<x>, <y>) size (<width>, <height>)
197
+ }
198
+ ```
199
+
200
+ **Example:**
201
+ ```planscript
202
+ room bedroom {
203
+ rect at (1, 9) size (4, 5)
204
+ }
205
+ ```
206
+
207
+ ### Rectangle with Size and Attachment
208
+
209
+ Positions a room relative to another room.
210
+
211
+ ```planscript
212
+ room <id> {
213
+ rect size (<width>, <height>)
214
+ attach <direction> <room_ref>
215
+ align <alignment>
216
+ gap <distance>
217
+ }
218
+ ```
219
+
220
+ **Directions:**
221
+ | Direction | Description |
222
+ |-----------|-------------|
223
+ | `north_of` | Above the reference room |
224
+ | `south_of` | Below the reference room |
225
+ | `east_of` | To the right of the reference room |
226
+ | `west_of` | To the left of the reference room |
227
+
228
+ **Alignments:**
229
+ | Alignment | Description |
230
+ |-----------|-------------|
231
+ | `top` | Align top edges (for east_of/west_of) |
232
+ | `bottom` | Align bottom edges (for east_of/west_of) |
233
+ | `left` | Align left edges (for north_of/south_of) |
234
+ | `right` | Align right edges (for north_of/south_of) |
235
+ | `center` | Center alignment |
236
+
237
+ **Example:**
238
+ ```planscript
239
+ room kitchen {
240
+ rect size (4, 6)
241
+ attach east_of living
242
+ align top
243
+ gap 0
244
+ }
245
+ ```
246
+
247
+ ### Rectangle with Span
248
+
249
+ Creates a room that spans between reference points from other rooms.
250
+
251
+ ```planscript
252
+ room <id> {
253
+ rect span x from <room>.<edge> to <room>.<edge> y (<y1>, <y2>)
254
+ }
255
+ ```
256
+
257
+ Or spanning on Y axis:
258
+ ```planscript
259
+ room <id> {
260
+ rect span y from <room>.<edge> to <room>.<edge> x (<x1>, <x2>)
261
+ }
262
+ ```
263
+
264
+ **Example:**
265
+ ```planscript
266
+ room hallway {
267
+ rect span x from living.left to kitchen.right y (7, 9)
268
+ }
269
+ ```
270
+
271
+ ### Polygon Rooms
272
+
273
+ For non-rectangular rooms:
274
+
275
+ ```planscript
276
+ room <id> {
277
+ polygon [
278
+ (<x1>, <y1>),
279
+ (<x2>, <y2>),
280
+ (<x3>, <y3>),
281
+ ...
282
+ ]
283
+ }
284
+ ```
285
+
286
+ ### Room Labels
287
+
288
+ Optional display label for the room:
289
+
290
+ ```planscript
291
+ room <id> {
292
+ rect (1, 1) (9, 7)
293
+ label "<display name>"
294
+ }
295
+ ```
296
+
297
+ **Example:**
298
+ ```planscript
299
+ room living {
300
+ rect (1, 1) (9, 7)
301
+ label "Living Room"
302
+ }
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Room References
308
+
309
+ Reference points and edges of rooms for positioning and spanning.
310
+
311
+ ### Edge References
312
+
313
+ | Reference | Description |
314
+ |-----------|-------------|
315
+ | `<room>.left` | X coordinate of left edge |
316
+ | `<room>.right` | X coordinate of right edge |
317
+ | `<room>.top` | Y coordinate of top edge |
318
+ | `<room>.bottom` | Y coordinate of bottom edge |
319
+
320
+ **Example:**
321
+ ```planscript
322
+ rect span x from living.left to kitchen.right y (7, 9)
323
+ ```
324
+
325
+ ### Edge Selectors
326
+
327
+ For placing openings on specific walls:
328
+
329
+ | Selector | Description |
330
+ |----------|-------------|
331
+ | `<room>.edge north` | Top wall |
332
+ | `<room>.edge south` | Bottom wall |
333
+ | `<room>.edge east` | Right wall |
334
+ | `<room>.edge west` | Left wall |
335
+
336
+ **Example:**
337
+ ```planscript
338
+ opening window w1 {
339
+ on living.edge south
340
+ at 2.0
341
+ }
342
+ ```
343
+
344
+ ---
345
+
346
+ ## Openings
347
+
348
+ Openings define doors and windows in walls.
349
+
350
+ ### Doors
351
+
352
+ #### Interior Door (between two rooms)
353
+
354
+ ```planscript
355
+ opening door <id> {
356
+ between <room1> and <room2>
357
+ on shared_edge
358
+ at <position>
359
+ width <value> # Optional if defaults set
360
+ }
361
+ ```
362
+
363
+ **Example:**
364
+ ```planscript
365
+ opening door d1 {
366
+ between living and kitchen
367
+ on shared_edge
368
+ at 50%
369
+ width 0.9
370
+ }
371
+ ```
372
+
373
+ #### Exterior Door (on a room's edge)
374
+
375
+ For front doors, back doors, or any door on an exterior wall:
376
+
377
+ ```planscript
378
+ opening door <id> {
379
+ on <room>.edge <direction>
380
+ at <position>
381
+ width <value> # Optional if defaults set
382
+ }
383
+ ```
384
+
385
+ **Example (front door):**
386
+ ```planscript
387
+ opening door d_front {
388
+ on foyer.edge south
389
+ at 50%
390
+ width 1.0
391
+ }
392
+ ```
393
+
394
+ ### Windows
395
+
396
+ Windows are placed on exterior walls:
397
+
398
+ ```planscript
399
+ opening window <id> {
400
+ on <room>.edge <direction>
401
+ at <position>
402
+ width <value> # Optional if defaults set
403
+ sill <height> # Optional: sill height from floor
404
+ }
405
+ ```
406
+
407
+ **Example:**
408
+ ```planscript
409
+ opening window w1 {
410
+ on living.edge south
411
+ at 2.0
412
+ width 2.4
413
+ sill 0.9
414
+ }
415
+ ```
416
+
417
+ ### Position Syntax
418
+
419
+ Opening positions can be specified two ways:
420
+
421
+ | Syntax | Description |
422
+ |--------|-------------|
423
+ | `at <number>%` | Percentage along the wall (0-100%) |
424
+ | `at <number>` | Absolute distance from wall start (in current units) |
425
+
426
+ **Examples:**
427
+ ```planscript
428
+ at 50% # Centered on the wall
429
+ at 25% # 25% from the start of the wall
430
+ at 2.0 # 2 meters from the start of the wall
431
+ at 0.5 # 0.5 meters from the start of the wall
432
+ ```
433
+
434
+ ---
435
+
436
+ ## Assertions
437
+
438
+ Assertions validate the floor plan. They cause compilation errors if not satisfied.
439
+
440
+ ### No Overlap
441
+
442
+ Ensures rooms don't overlap:
443
+
444
+ ```planscript
445
+ assert no_overlap rooms
446
+ ```
447
+
448
+ ### Inside Footprint
449
+
450
+ Ensures all rooms are within the building footprint:
451
+
452
+ ```planscript
453
+ assert inside footprint all_rooms
454
+ ```
455
+
456
+ Or for a specific room:
457
+
458
+ ```planscript
459
+ assert inside footprint <room_id>
460
+ ```
461
+
462
+ ### Minimum Room Area
463
+
464
+ Ensures a room meets minimum area requirements:
465
+
466
+ ```planscript
467
+ assert min_room_area <room_id> >= <value>
468
+ ```
469
+
470
+ **Example:**
471
+ ```planscript
472
+ assert min_room_area bedroom >= 12.0
473
+ ```
474
+
475
+ ---
476
+
477
+ ## Comments
478
+
479
+ Single-line comments start with `#`:
480
+
481
+ ```planscript
482
+ # This is a comment
483
+ room living {
484
+ rect (1, 1) (9, 7) # Inline comment
485
+ }
486
+ ```
487
+
488
+ ---
489
+
490
+ ## Complete Examples
491
+
492
+ ### Simple: Two Rooms with Door
493
+
494
+ ```planscript
495
+ units m
496
+
497
+ plan "Simple Apartment" {
498
+ footprint rect (0, 0) (10, 8)
499
+
500
+ room living {
501
+ rect (0, 0) (6, 8)
502
+ label "Living Room"
503
+ }
504
+
505
+ room bedroom {
506
+ rect (6, 0) (10, 8)
507
+ label "Bedroom"
508
+ }
509
+
510
+ opening door d1 {
511
+ between living and bedroom
512
+ on shared_edge
513
+ at 50%
514
+ width 0.9
515
+ }
516
+ }
517
+ ```
518
+
519
+ ### Medium: House with Multiple Rooms
520
+
521
+ ```planscript
522
+ units m
523
+
524
+ defaults {
525
+ door_width 0.9
526
+ window_width 1.5
527
+ }
528
+
529
+ plan "Family House" {
530
+ footprint rect (0, 0) (15, 12)
531
+
532
+ # Main living area
533
+ room living {
534
+ rect (1, 1) (8, 7)
535
+ label "Living Room"
536
+ }
537
+
538
+ # Kitchen attached to living room
539
+ room kitchen {
540
+ rect size (5, 6)
541
+ attach east_of living
542
+ align top
543
+ gap 0
544
+ label "Kitchen"
545
+ }
546
+
547
+ # Hallway spanning across
548
+ room hall {
549
+ rect span x from living.left to kitchen.right y (7, 9)
550
+ label "Hallway"
551
+ }
552
+
553
+ # Bedrooms
554
+ room master {
555
+ rect at (1, 9) size (5, 3)
556
+ label "Master Bedroom"
557
+ }
558
+
559
+ room bedroom2 {
560
+ rect at (6, 9) size (4, 3)
561
+ label "Bedroom 2"
562
+ }
563
+
564
+ # Bathroom
565
+ room bath {
566
+ rect at (10, 9) size (3, 3)
567
+ label "Bathroom"
568
+ }
569
+
570
+ # Doors
571
+ opening door d1 { between living and hall on shared_edge at 50% }
572
+ opening door d2 { between kitchen and hall on shared_edge at 50% }
573
+ opening door d3 { between hall and master on shared_edge at 50% }
574
+ opening door d4 { between hall and bedroom2 on shared_edge at 50% }
575
+ opening door d5 { between hall and bath on shared_edge at 50% }
576
+
577
+ # Windows
578
+ opening window w1 { on living.edge south at 3.0 }
579
+ opening window w2 { on master.edge north at 2.0 }
580
+ opening window w3 { on bedroom2.edge north at 1.5 }
581
+
582
+ # Validation
583
+ assert no_overlap rooms
584
+ assert inside footprint all_rooms
585
+ assert min_room_area master >= 12.0
586
+ }
587
+ ```
588
+
589
+ ### Complex: L-Shaped Building
590
+
591
+ ```planscript
592
+ units m
593
+
594
+ defaults {
595
+ door_width 0.9
596
+ window_width 1.2
597
+ }
598
+
599
+ plan "L-Shaped House" {
600
+ # L-shaped footprint
601
+ footprint polygon [
602
+ (0, 0),
603
+ (12, 0),
604
+ (12, 8),
605
+ (7, 8),
606
+ (7, 14),
607
+ (0, 14)
608
+ ]
609
+
610
+ # Ground floor rooms
611
+ room living {
612
+ rect (1, 1) (6, 7)
613
+ label "Living Room"
614
+ }
615
+
616
+ room kitchen {
617
+ rect (7, 1) (11, 7)
618
+ label "Kitchen"
619
+ }
620
+
621
+ room dining {
622
+ rect (1, 8) (6, 13)
623
+ label "Dining Room"
624
+ }
625
+
626
+ # Doors
627
+ opening door d1 {
628
+ between living and kitchen
629
+ on shared_edge
630
+ at 50%
631
+ }
632
+
633
+ opening door d2 {
634
+ between living and dining
635
+ on shared_edge
636
+ at 50%
637
+ }
638
+
639
+ # Windows on exterior walls
640
+ opening window w1 { on living.edge south at 2.0 }
641
+ opening window w2 { on living.edge west at 3.0 }
642
+ opening window w3 { on kitchen.edge south at 2.0 }
643
+ opening window w4 { on kitchen.edge east at 3.0 }
644
+ opening window w5 { on dining.edge west at 2.5 }
645
+ opening window w6 { on dining.edge north at 2.0 }
646
+
647
+ assert no_overlap rooms
648
+ assert inside footprint all_rooms
649
+ }
650
+ ```
651
+
652
+ ### Studio Apartment with Bathroom
653
+
654
+ ```planscript
655
+ units m
656
+
657
+ defaults {
658
+ door_width 0.8
659
+ window_width 1.0
660
+ }
661
+
662
+ plan "Studio Apartment" {
663
+ footprint rect (0, 0) (8, 6)
664
+
665
+ room main {
666
+ rect (0, 0) (8, 4.5)
667
+ label "Living/Bedroom"
668
+ }
669
+
670
+ room bath {
671
+ rect (5, 4.5) (8, 6)
672
+ label "Bathroom"
673
+ }
674
+
675
+ room kitchen {
676
+ rect (0, 4.5) (5, 6)
677
+ label "Kitchenette"
678
+ }
679
+
680
+ opening door d1 { between main and bath on shared_edge at 50% }
681
+ opening door d2 { between main and kitchen on shared_edge at 60% }
682
+
683
+ opening window w1 { on main.edge south at 4.0 width 2.0 }
684
+
685
+ assert no_overlap rooms
686
+ }
687
+ ```
688
+
689
+ ---
690
+
691
+ ## Syntax Summary
692
+
693
+ ### Keywords
694
+
695
+ ```
696
+ units, origin, defaults, plan, footprint, room, opening, assert,
697
+ rect, polygon, at, size, attach, align, gap, span, from, to, label,
698
+ door, window, between, and, on, shared_edge, width, sill,
699
+ north_of, south_of, east_of, west_of,
700
+ north, south, east, west,
701
+ top, bottom, left, right, center,
702
+ no_overlap, inside, all_rooms, min_room_area,
703
+ m, cm, mm, ft, in
704
+ ```
705
+
706
+ ### Coordinate Format
707
+
708
+ ```
709
+ (<x>, <y>) # Point
710
+ (<x1>, <y1>) (<x2>, <y2>) # Two corners
711
+ ```
712
+
713
+ ### Point List Syntax
714
+
715
+ Polygons support two syntaxes:
716
+
717
+ **Bracketed (recommended for multiline):**
718
+ ```planscript
719
+ polygon [
720
+ (0, 0),
721
+ (10, 0),
722
+ (10, 10),
723
+ (0, 10)
724
+ ]
725
+ ```
726
+
727
+ **Space-separated (compact):**
728
+ ```planscript
729
+ polygon (0, 0) (10, 0) (10, 10) (0, 10)
730
+ ```
731
+
732
+ Both syntaxes are equivalent. Bracketed syntax allows trailing commas.
733
+
734
+ ### Numeric Values
735
+
736
+ ```
737
+ 10 # Integer
738
+ 10.5 # Decimal
739
+ 50% # Percentage (for positions)
740
+ ```
741
+
742
+ ### Identifiers
743
+
744
+ Room and opening IDs must:
745
+ - Start with a letter or underscore
746
+ - Contain only letters, numbers, and underscores
747
+ - Be unique within their category
748
+
749
+ ```
750
+ room living { ... } # Valid
751
+ room my_room { ... } # Valid
752
+ room room1 { ... } # Valid
753
+ room 1room { ... } # Invalid - starts with number
754
+ ```