@seatmap-fyi/map-domain 0.1.0-alpha.48 → 0.1.0-alpha.50

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.
@@ -1,12 +1,16 @@
1
- import { ArcFanRebuildIssue, type ArcFanInput, type ArcFanPart, type ArcFanPlan, type ArcFanRows, type ArcFanRebuildSource, type ArcFanRebuildPlacement } from "./arc-fan.interface.js";
2
- import type { PhysicalDocumentV1, RowSlot } from "./physical-document.interface.js";
1
+ import { ArcFanRebuildIssue, type ArcFanInput, type ArcFanPart, type ArcFanPlan, type ArcFanRows, type ArcFanRebuildSource, type ArcFanRebuildSettings, type ArcFanRebuildPlacement } from "./arc-fan.interface.js";
2
+ import type { PhysicalDocumentV1, PointM, RowSlot, UUID } from "./physical-document.interface.js";
3
3
  export declare const arcFanRebuildMessages: Record<ArcFanRebuildIssue, string>;
4
4
  export declare const arcFanGeometryEntryMessage = "This fan has manually edited geometry. Edit its rows individually to keep those changes.";
5
5
  export declare function arcFanParts(plan: ArcFanPlan): ArcFanPart[];
6
- /** Compare current physical rows with generation provenance; seat customizations remain independent. */
7
- export declare function arcFanRebuildSource(group: ArcFanRows): ArcFanRebuildSource | null;
6
+ /** Capture the phase of the source grid relative to the bank, so a copy can move the whole outline. */
7
+ export declare function arcFanOutlineGridOrigin(center: PointM): PointM;
8
+ /** A generated section and its rows share provenance; authored boundary changes stop regeneration. */
9
+ export declare function arcFanRebuildSource(document: PhysicalDocumentV1, group: ArcFanRows): ArcFanRebuildSource | null;
8
10
  export declare function arcFanSequenceCustomized(row: RowSlot, part: ArcFanPart): boolean;
9
- export declare function reviewArcFanRebuild(group: ArcFanRows, plan: ArcFanPlan): ArcFanRebuildIssue | null;
11
+ /** The first physical row owns the generator's category default; seat overrides remain individual. */
12
+ export declare function arcFanRebuildCategory(group: ArcFanRows): UUID | null;
13
+ export declare function reviewArcFanRebuild(document: PhysicalDocumentV1, group: ArcFanRows, plan: ArcFanPlan, { categoryId, positionM, editorState }: ArcFanRebuildSettings): ArcFanRebuildIssue | null;
10
14
  /** Show the same authored fan in world coordinates, including inherited rotation and reflection. */
11
15
  export declare function arcFanWorldInput(document: PhysicalDocumentV1, group: ArcFanRows): ArcFanInput;
12
16
  /** Convert the form's world draft back into the bank's single local geometry owner. */
@@ -1,12 +1,18 @@
1
- import { planArcFan } from "./arc-fan.js";
2
- import { ArcFanRebuildIssue, } from "./arc-fan.interface.js";
1
+ import { arcFanSeats, planArcFan } from "./arc-fan.js";
2
+ import { ArcFanRebuildIssue, ArcFanSectionOrigin, } from "./arc-fan.interface.js";
3
3
  import { NumberingScheme, LabelDirection, RowEnds } from "./physical-document.interface.js";
4
4
  import { worldMatrices, inverse, project, normalizeAngle } from "./geometry/geometry.js";
5
5
  import { resolveRowLayout, rowPlacementOffset } from "./geometry/seating-layout.js";
6
+ import { matchesPaddedSectionOutline } from "./geometry/inventory-outline.js";
7
+ import { LayoutUnitM } from "./geometry/units.js";
6
8
  import { seatHasOwnSettings } from "./selling.js";
9
+ import { mapEditorPolicy } from "./editor-state.js";
7
10
  const coordinateToleranceM = 1e-7;
8
11
  const angleToleranceDeg = 1e-7;
12
+ const outlineSeatGridM = LayoutUnitM / 1_000_000;
13
+ const outlineRoundoffM = outlineSeatGridM / 1_000;
9
14
  const degrees = 180 / Math.PI;
15
+ const rowSources = new WeakMap();
10
16
  const sources = new WeakMap();
11
17
  const generatedRowFields = new Set([
12
18
  "zIndex",
@@ -59,9 +65,9 @@ function sameLayout(a, b) {
59
65
  sameAngle(a.seatRotationOffsetDeg ?? 0, b.seatRotationOffsetDeg ?? 0));
60
66
  }
61
67
  /** Compare current physical rows with generation provenance; seat customizations remain independent. */
62
- export function arcFanRebuildSource(group) {
63
- if (sources.has(group))
64
- return sources.get(group);
68
+ function rowSource(group) {
69
+ if (rowSources.has(group))
70
+ return rowSources.get(group);
65
71
  const generation = group.arcFan;
66
72
  const plan = generation ? planArcFan({ ...generation.recipe, center: { x: 0, y: 0 } }) : null;
67
73
  let source = null;
@@ -82,7 +88,53 @@ export function arcFanRebuildSource(group) {
82
88
  source = { parts, members: generation.members, rows: group.rows };
83
89
  }
84
90
  }
85
- sources.set(group, source);
91
+ rowSources.set(group, source);
92
+ return source;
93
+ }
94
+ function snapOutlineCoordinate(coordinate, gridOrigin = 0) {
95
+ return gridOrigin + Math.round((coordinate - gridOrigin) / outlineSeatGridM) * outlineSeatGridM;
96
+ }
97
+ /** Capture the phase of the source grid relative to the bank, so a copy can move the whole outline. */
98
+ export function arcFanOutlineGridOrigin(center) {
99
+ return {
100
+ x: snapOutlineCoordinate(center.x) - center.x,
101
+ y: snapOutlineCoordinate(center.y) - center.y,
102
+ };
103
+ }
104
+ /** A generated section and its rows share provenance; authored boundary changes stop regeneration. */
105
+ export function arcFanRebuildSource(document, group) {
106
+ let cached = sources.get(document);
107
+ if (!cached) {
108
+ cached = new WeakMap();
109
+ sources.set(document, cached);
110
+ }
111
+ if (cached.has(group))
112
+ return cached.get(group);
113
+ let source = rowSource(group);
114
+ const generation = group.arcFan;
115
+ if (source && generation?.sectionOrigin === ArcFanSectionOrigin.Generated && generation.sectionId) {
116
+ const section = document.sections.find((section) => section.id === generation.sectionId);
117
+ const gridOrigin = generation.sectionOutlineGridOriginM;
118
+ if (gridOrigin) {
119
+ const plan = planArcFan({ ...generation.recipe, center: { x: 0, y: 0 } });
120
+ const seats = arcFanSeats(plan).map(({ x, y }) => ({
121
+ x: snapOutlineCoordinate(x, gridOrigin.x),
122
+ y: snapOutlineCoordinate(y, gridOrigin.y),
123
+ }));
124
+ const matrix = worldMatrices(document).get(group.id);
125
+ if (!matchesPaddedSectionOutline(seats, section?.outline, {
126
+ toWorld: (point) => project(matrix, point),
127
+ toleranceM: outlineRoundoffM,
128
+ }))
129
+ source = null;
130
+ }
131
+ else {
132
+ const plan = planArcFan(arcFanWorldInput(document, group));
133
+ if (!matchesPaddedSectionOutline(arcFanSeats(plan), section?.outline))
134
+ source = null;
135
+ }
136
+ }
137
+ cached.set(group, source);
86
138
  return source;
87
139
  }
88
140
  export function arcFanSequenceCustomized(row, part) {
@@ -106,24 +158,35 @@ function rowCustomized(source, index) {
106
158
  function retainsSeatLayout(before, after) {
107
159
  return sameLayout(before.layout, after.layout);
108
160
  }
109
- export function reviewArcFanRebuild(group, plan) {
110
- const source = arcFanRebuildSource(group);
161
+ /** The first physical row owns the generator's category default; seat overrides remain individual. */
162
+ export function arcFanRebuildCategory(group) {
163
+ const category = group.rows[0]?.categoryId;
164
+ return category === undefined ? (group.categoryId ?? null) : category;
165
+ }
166
+ export function reviewArcFanRebuild(document, group, plan, { categoryId, positionM, editorState }) {
167
+ const source = arcFanRebuildSource(document, group);
111
168
  if (!source)
112
169
  return ArcFanRebuildIssue.Geometry;
170
+ const categoryChanged = categoryId !== arcFanRebuildCategory(group);
171
+ const moved = positionM.x !== group.transform.positionM.x || positionM.y !== group.transform.positionM.y;
172
+ const policy = mapEditorPolicy(document, editorState);
113
173
  const nextParts = arcFanParts(plan);
114
174
  const next = new Map(nextParts.map((part) => [part.rowIndex + ":" + part.partIndex, part]));
115
175
  for (let index = 0; index < source.rows.length; index++) {
116
176
  const row = source.rows[index], part = source.parts[index];
117
177
  const after = next.get(part.rowIndex + ":" + part.partIndex);
118
- const custom = rowCustomized(source, index) || row.seats.some(seatHasOwnSettings);
178
+ const locked = policy.lockOwner(row.id);
179
+ const custom = locked || rowCustomized(source, index) || row.seats.some(seatHasOwnSettings);
119
180
  if (!after) {
120
181
  if (custom)
121
182
  return ArcFanRebuildIssue.RemoveCustomizedRow;
122
183
  continue;
123
184
  }
185
+ if (locked && (moved || after.seats !== row.seats.length))
186
+ return ArcFanRebuildIssue.CustomizedShape;
124
187
  if (row.seats.slice(after.seats).some(seatHasOwnSettings))
125
188
  return ArcFanRebuildIssue.CustomizedShape;
126
- if (custom && !retainsSeatLayout(part, after))
189
+ if (custom && (categoryChanged || !retainsSeatLayout(part, after)))
127
190
  return ArcFanRebuildIssue.CustomizedShape;
128
191
  }
129
192
  return null;
@@ -147,6 +210,10 @@ export function arcFanRebuildPlacement(document, group, input) {
147
210
  const matrices = worldMatrices(document), matrix = matrices.get(group.id);
148
211
  const direction = matrix.a * matrix.d - matrix.b * matrix.c < 0 ? -1 : 1;
149
212
  const angle = Math.atan2(matrix.c, matrix.d) * degrees;
213
+ let positionM = group.transform.positionM;
214
+ if (input.center.x !== matrix.tx || input.center.y !== matrix.ty) {
215
+ positionM = group.parentId ? project(inverse(matrices.get(group.parentId)), input.center) : input.center;
216
+ }
150
217
  return {
151
218
  input: {
152
219
  ...input,
@@ -155,9 +222,6 @@ export function arcFanRebuildPlacement(document, group, input) {
155
222
  endAngleDeg: direction * (input.endAngleDeg - angle),
156
223
  skewDeg: direction * input.skewDeg,
157
224
  },
158
- transform: {
159
- ...group.transform,
160
- positionM: group.parentId ? project(inverse(matrices.get(group.parentId)), input.center) : input.center,
161
- },
225
+ transform: { ...group.transform, positionM },
162
226
  };
163
227
  }
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ import type { MapEditorState } from "./editor-state.js";
3
+ import { type ArcFanSectionLayout } from "./arc-fan.interface.js";
4
+ import type { PhysicalDocumentV1, UUID } from "./physical-document.interface.js";
5
+ export declare const arcFanSectionRebuildInputSchema: z.ZodObject<{
6
+ arcFanGroupId: z.ZodString;
7
+ }, z.core.$strict>;
8
+ /** Prove the generated section transition independently of the submitted outline or protection metadata. */
9
+ export declare function rebuiltArcFanSection(before: PhysicalDocumentV1, after: PhysicalDocumentV1, groupId: UUID, editorState: MapEditorState): ArcFanSectionLayout | null;
10
+ /** Normalize only the proved generated section before checking all remaining position locks. */
11
+ export declare function projectArcFanSectionLayout(document: PhysicalDocumentV1, layout: ArcFanSectionLayout): PhysicalDocumentV1;
@@ -0,0 +1,54 @@
1
+ import { z } from "zod";
2
+ import { uuidSchema } from "./schema.js";
3
+ import { documentCatalog } from "./catalog.js";
4
+ import { arcFanSeats, planArcFan } from "./arc-fan.js";
5
+ import { arcFanRebuildCategory, arcFanRebuildSource, arcFanWorldInput, reviewArcFanRebuild, } from "./arc-fan-rebuild.js";
6
+ import { ArcFanSectionOrigin } from "./arc-fan.interface.js";
7
+ import { paddedSectionOutline } from "./geometry/inventory-outline.js";
8
+ export const arcFanSectionRebuildInputSchema = z.strictObject({ arcFanGroupId: uuidSchema });
9
+ /** Prove the generated section transition independently of the submitted outline or protection metadata. */
10
+ export function rebuiltArcFanSection(before, after, groupId, editorState) {
11
+ const previous = documentCatalog(before).groups.get(groupId);
12
+ const next = documentCatalog(after).groups.get(groupId);
13
+ if (!previous || !("rows" in previous) || !next || !("rows" in next))
14
+ return null;
15
+ const original = previous.arcFan;
16
+ const generation = next.arcFan;
17
+ if (original?.sectionOrigin !== ArcFanSectionOrigin.Generated ||
18
+ !original.sectionId ||
19
+ generation?.sectionOrigin !== ArcFanSectionOrigin.Generated ||
20
+ !arcFanRebuildSource(before, previous))
21
+ return null;
22
+ const index = before.sections.findIndex((section) => section.id === original.sectionId);
23
+ const section = before.sections[index];
24
+ const local = planArcFan({ ...generation.recipe, center: { x: 0, y: 0 } });
25
+ if (!local ||
26
+ reviewArcFanRebuild(before, previous, local, {
27
+ categoryId: arcFanRebuildCategory(next),
28
+ positionM: next.transform.positionM,
29
+ editorState,
30
+ }) ||
31
+ !arcFanRebuildSource(after, next))
32
+ return null;
33
+ const outline = paddedSectionOutline(arcFanSeats(planArcFan(arcFanWorldInput(after, next))));
34
+ if (outline) {
35
+ const verifiedOutline = after.sections.find((item) => item.id === section.id)?.outline;
36
+ if (generation.sectionId !== section.id || !verifiedOutline)
37
+ return null;
38
+ // Rebuild provenance already proved this outline. Retain its exact coordinates across JS runtimes.
39
+ return { before: section, after: { ...section, outline: verifiedOutline }, index };
40
+ }
41
+ if (generation.sectionId !== null ||
42
+ after.sections.some((item) => item.id === section.id) ||
43
+ next.sectionId === section.id ||
44
+ next.rows.some((row) => row.fillOrigin?.sectionId === section.id))
45
+ return null;
46
+ return { before: section, after: null, index };
47
+ }
48
+ /** Normalize only the proved generated section before checking all remaining position locks. */
49
+ export function projectArcFanSectionLayout(document, layout) {
50
+ const sections = document.sections.filter((section) => section.id !== layout.before.id);
51
+ if (layout.after)
52
+ sections.splice(layout.index, 0, layout.after);
53
+ return { ...document, sections };
54
+ }
@@ -1,4 +1,7 @@
1
- import type { PointM, UUID, RowLayout, RowSlot, StraightRows, CurvedRows, LabelSequence, RowEnds, Transform } from "./physical-document.interface.js";
1
+ import type { z } from "zod";
2
+ import type { MapEditorState } from "./editor-state.js";
3
+ import type { arcFanSectionRebuildInputSchema } from "./arc-fan-section-layout.js";
4
+ import type { PointM, UUID, RowLayout, RowSlot, StraightRows, CurvedRows, LabelSequence, RowEnds, Transform, Section } from "./physical-document.interface.js";
2
5
  import type { SectionFillPlan } from "./section-fill.interface.js";
3
6
  export declare enum ArcFanFit {
4
7
  Spacing = "spacing",
@@ -32,6 +35,11 @@ export type ArcFanMember = {
32
35
  labelOverride?: string;
33
36
  };
34
37
  export type ArcFanRows = StraightRows | CurvedRows;
38
+ export type ArcFanRebuildSettings = {
39
+ categoryId: UUID | null;
40
+ positionM: PointM;
41
+ editorState: MapEditorState;
42
+ };
35
43
  export type ArcFanPart = {
36
44
  rowIndex: number;
37
45
  partIndex: number;
@@ -72,6 +80,8 @@ export type ArcFanGeneration = {
72
80
  recipe: ArcFanRecipe;
73
81
  sectionId: UUID | null;
74
82
  sectionOrigin: ArcFanSectionOrigin;
83
+ /** Local origin of the layout-microunit grid used to generate an imported section outline. */
84
+ sectionOutlineGridOriginM?: PointM;
75
85
  members: ArcFanMember[];
76
86
  };
77
87
  export type ArcFanPlan = Pick<SectionFillPlan, "rows" | "recipe"> & {
@@ -81,3 +91,10 @@ export type ArcFanPlan = Pick<SectionFillPlan, "rows" | "recipe"> & {
81
91
  maximumPitchM: number;
82
92
  aisles: number;
83
93
  };
94
+ export type ArcFanSectionRebuildInput = z.infer<typeof arcFanSectionRebuildInputSchema>;
95
+ /** Canonically derived section geometry, including removal when no polygon can be outlined. */
96
+ export interface ArcFanSectionLayout {
97
+ before: Section;
98
+ after: Section | null;
99
+ index: number;
100
+ }
@@ -1,5 +1,5 @@
1
- import type { MapCategory, PhysicalDocumentV1, RowSlot, SeatingGroup, SeatSlot, UUID } from "./physical-document.interface.js";
2
- import { SeatShape } from "./physical-document.interface.js";
1
+ import type { InventoryArea, MapCategory, PhysicalDocumentV1, RowSlot, SeatingGroup, SeatSlot, UUID } from "./physical-document.interface.js";
2
+ import { SeatShape, SeatingKind } from "./physical-document.interface.js";
3
3
  import { type DomainIssue } from "./issues.js";
4
4
  export declare function categoryCatalog(document: PhysicalDocumentV1): ReadonlyMap<UUID, MapCategory>;
5
5
  /** Absence inherits; explicit null records an unassigned child. */
@@ -13,7 +13,16 @@ export declare function missingCategoryLabel(places: number): string;
13
13
  export declare function categoryIssues(document: PhysicalDocumentV1): readonly DomainIssue[];
14
14
  /** Fragment paste reuses catalogue identity; whole-map copy remaps it with the map. */
15
15
  export declare function remapGroupCategories(group: SeatingGroup, ids: ReadonlyMap<UUID, UUID>): SeatingGroup;
16
+ export declare enum InventoryKind {
17
+ Rows = "rows",
18
+ Tables = "tables",
19
+ Standing = "standing",
20
+ Booths = "booths"
21
+ }
22
+ export declare function groupInventoryKind(kind: SeatingKind): InventoryKind;
23
+ export declare function areaInventoryKind(kind: InventoryArea["kind"]): InventoryKind;
16
24
  export declare function categoryUsage(document: PhysicalDocumentV1): ReadonlyMap<UUID, number>;
25
+ export declare function categoryInventoryKinds(document: PhysicalDocumentV1, categoryId: UUID): ReadonlySet<InventoryKind>;
17
26
  export declare function ticketOptionNameKey(name: string): string;
18
27
  export type CategoryPricing = {
19
28
  onSale: boolean;
@@ -125,6 +125,10 @@ export function categoryIssues(document) {
125
125
  }
126
126
  const uses = categoryUsage(document);
127
127
  for (const category of document.categories ?? []) {
128
+ if (categoryInventoryKinds(document, category.id).size > 1) {
129
+ const message = `Category “${category.name}” spans incompatible inventory types`;
130
+ findings.push(issue(IssueCode.MixedCategoryInventory, message, [category.id]));
131
+ }
128
132
  if (!uses.get(category.id) || !categoryPricing(category).missing)
129
133
  continue;
130
134
  const message = `Category "${category.name}" has no default price. Each event sets its price before it goes on sale`;
@@ -164,34 +168,62 @@ export function remapGroupCategories(group, ids) {
164
168
  },
165
169
  };
166
170
  }
171
+ export var InventoryKind;
172
+ (function (InventoryKind) {
173
+ InventoryKind["Rows"] = "rows";
174
+ InventoryKind["Tables"] = "tables";
175
+ InventoryKind["Standing"] = "standing";
176
+ InventoryKind["Booths"] = "booths";
177
+ })(InventoryKind || (InventoryKind = {}));
178
+ export function groupInventoryKind(kind) {
179
+ return kind === SeatingKind.Straight || kind === SeatingKind.Curved ? InventoryKind.Rows : InventoryKind.Tables;
180
+ }
181
+ export function areaInventoryKind(kind) {
182
+ return kind === AreaKind.Booth ? InventoryKind.Booths : InventoryKind.Standing;
183
+ }
167
184
  const usage = new WeakMap();
168
- export function categoryUsage(document) {
185
+ const noInventoryKinds = new Set();
186
+ function categoryInventory(document) {
169
187
  const cached = usage.get(document);
170
188
  if (cached)
171
189
  return cached;
172
190
  const counts = new Map();
173
- const count = (id, quantity = 1) => {
174
- if (id)
175
- counts.set(id, (counts.get(id) ?? 0) + quantity);
191
+ const kinds = new Map();
192
+ const count = (id, kind, quantity) => {
193
+ if (!id)
194
+ return;
195
+ counts.set(id, (counts.get(id) ?? 0) + quantity);
196
+ const used = kinds.get(id) ?? new Set();
197
+ used.add(kind);
198
+ kinds.set(id, used);
176
199
  };
177
200
  for (const group of document.seatingGroups) {
201
+ const kind = groupInventoryKind(group.kind);
178
202
  if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
179
203
  for (const row of group.rows)
180
204
  for (const slot of row.seats)
181
205
  if (!slot.gap)
182
- count(seatCategoryId(group, slot, row));
206
+ count(seatCategoryId(group, slot, row), kind, 1);
183
207
  }
184
208
  else {
185
209
  const slots = group.kind === SeatingKind.Round ? group.chairs : Object.values(group.chairsBySide).flat();
186
210
  for (const slot of slots)
187
211
  if (!slot.gap)
188
- count(seatCategoryId(group, slot));
212
+ count(seatCategoryId(group, slot), kind, 1);
189
213
  }
190
214
  }
191
- for (const area of document.areas)
192
- count(area.categoryId ?? null, area.kind === AreaKind.Booth ? 1 : area.capacity);
193
- usage.set(document, counts);
194
- return counts;
215
+ for (const area of document.areas) {
216
+ count(area.categoryId ?? null, areaInventoryKind(area.kind), area.kind === AreaKind.Booth ? 1 : area.capacity);
217
+ }
218
+ const result = { counts, kinds };
219
+ usage.set(document, result);
220
+ return result;
221
+ }
222
+ export function categoryUsage(document) {
223
+ return categoryInventory(document).counts;
224
+ }
225
+ export function categoryInventoryKinds(document, categoryId) {
226
+ return categoryInventory(document).kinds.get(categoryId) ?? noInventoryKinds;
195
227
  }
196
228
  export function ticketOptionNameKey(name) {
197
229
  return name.trim().toLowerCase();
package/dist/floors.d.ts CHANGED
@@ -6,7 +6,7 @@ export type FloorInventory = {
6
6
  physicalSeats: number;
7
7
  gaQuantity: number;
8
8
  };
9
- gapCount: number;
9
+ rowGapCount: number;
10
10
  };
11
11
  export type FloorCatalog = {
12
12
  entries: ReadonlyMap<UUID | null, FloorInventory>;
package/dist/floors.js CHANGED
@@ -11,9 +11,9 @@ export function floorCatalog(document) {
11
11
  const entries = new Map();
12
12
  const owners = new Map();
13
13
  for (const floor of document.floors ?? [])
14
- entries.set(floor.id, { floor, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, gapCount: 0 });
14
+ entries.set(floor.id, { floor, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, rowGapCount: 0 });
15
15
  if (!document.floors)
16
- entries.set(null, { floor: null, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, gapCount: 0 });
16
+ entries.set(null, { floor: null, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, rowGapCount: 0 });
17
17
  for (const member of [
18
18
  ...document.sections,
19
19
  ...document.collections,
@@ -29,20 +29,15 @@ export function floorCatalog(document) {
29
29
  const id = group.floorId ?? null;
30
30
  const entry = entries.get(id);
31
31
  const inventoryCount = groupInventoryCount(group);
32
- let slotCount = 0;
33
32
  if ("rows" in group) {
33
+ let slotCount = 0;
34
34
  for (const row of group.rows) {
35
35
  owners.set(row.id, id);
36
36
  slotCount += row.seats.length;
37
37
  }
38
+ entry.rowGapCount += slotCount - inventoryCount;
38
39
  }
39
- else if ("chairs" in group)
40
- slotCount = group.chairs.length;
41
- else
42
- for (const side of Object.values(group.chairsBySide))
43
- slotCount += side.length;
44
40
  entry.capacity.physicalSeats += inventoryCount;
45
- entry.gapCount += slotCount - inventoryCount;
46
41
  }
47
42
  for (const area of document.areas) {
48
43
  const count = entries.get(area.floorId ?? null).capacity;
@@ -16,6 +16,9 @@ export type GeneratedSeat = {
16
16
  label: string;
17
17
  /** Canonical sequence label, independent of an authored display override. */
18
18
  bookingLabel: string;
19
+ /** A table chair’s display number without its optional table name. */
20
+ chairNumber?: string;
21
+ buyerNoun?: string;
19
22
  ownerLabel: string;
20
23
  addressRowLabel?: string;
21
24
  logicalRowLabel?: string;
@@ -1,6 +1,6 @@
1
1
  import { polygonContour } from "./polygon-curves.js";
2
- import { rowPlacementOffset, rowSeatGeometry, roundChairGeometry, rectangularChairGeometry, TableSide, } from "./seating-layout.js";
3
- import { SeatingKind, TableChairDistribution, RowEnds, } from "../physical-document.interface.js";
2
+ import { rowPlacementOffset, rowSeatGeometry, roundChairGeometry, rectangularChairGeometry, rectangularChairOrder, } from "./seating-layout.js";
3
+ import { NumberingScheme, TableChairNumberFormat, SeatingKind, RowEnds, } from "../physical-document.interface.js";
4
4
  import { inventoryName, sequenceLabel, rowDisplayLabel } from "../labels.js";
5
5
  import { seatCategoryId } from "../categories.js";
6
6
  import { containsPoint, intersects, pointsBounds } from "./primitives.js";
@@ -119,33 +119,59 @@ export function* generateGroup(group) {
119
119
  const row = group.rows[r];
120
120
  const owner = rowDisplayLabel(group, r);
121
121
  const offset = rowPlacementOffset(group, r, row.offsetM);
122
+ const firstAisleIndex = row.aisleSeats === RowEnds.Start || row.aisleSeats === RowEnds.Both
123
+ ? row.seats.findIndex((seat) => !seat.gap)
124
+ : -1;
125
+ let lastAisleIndex = -1;
126
+ if (row.aisleSeats === RowEnds.End || row.aisleSeats === RowEnds.Both) {
127
+ lastAisleIndex = row.seats.length - 1;
128
+ while (lastAisleIndex >= 0 && row.seats[lastAisleIndex].gap)
129
+ lastAisleIndex--;
130
+ }
122
131
  for (let i = 0; i < row.seats.length; i++) {
123
132
  const geometry = rowSeatGeometry(group, r, i, row.seats.length, longestRow, row.layout);
124
133
  const p = { x: geometry.position.x + offset.x, y: geometry.position.y + offset.y };
125
134
  const rotation = geometry.rotationDeg;
126
- const seat = emit(row.seats[i], p, rotation, sequenceLabel(row.seatSequenceOverride ?? group.labels.seats, i, row.seats.length), owner, row.id, (i === 0 && (row.aisleSeats === RowEnds.Start || row.aisleSeats === RowEnds.Both)) ||
127
- (i === row.seats.length - 1 && (row.aisleSeats === RowEnds.End || row.aisleSeats === RowEnds.Both)), seatCategoryId(group, row.seats[i], row));
135
+ const seat = emit(row.seats[i], p, rotation, sequenceLabel(row.seatSequenceOverride ?? group.labels.seats, i, row.seats.length), owner, row.id, i === firstAisleIndex || i === lastAisleIndex, seatCategoryId(group, row.seats[i], row));
128
136
  yield seat;
129
137
  }
130
138
  }
139
+ return;
131
140
  }
132
- else if (group.kind === SeatingKind.Round) {
141
+ const { labels } = group;
142
+ const ownerLabel = inventoryName(labels);
143
+ const numbering = labels.chairNumbering;
144
+ const letters = numbering?.format === TableChairNumberFormat.Letter;
145
+ const displaySequence = numbering && {
146
+ scheme: letters ? NumberingScheme.Alphabetic : NumberingScheme.Numeric,
147
+ startAt: letters ? Math.max(1, numbering.startAt) : numbering.startAt,
148
+ direction: numbering.direction,
149
+ };
150
+ const emitChair = (slot, position, rotation, index, count) => {
151
+ const seat = emit(slot, position, rotation, sequenceLabel(labels.chairs, index, count), ownerLabel, null);
152
+ if (labels.buyerNoun !== undefined)
153
+ seat.buyerNoun = labels.buyerNoun;
154
+ if (!numbering || !displaySequence)
155
+ return seat;
156
+ const chairNumber = sequenceLabel(displaySequence, index, count);
157
+ const label = numbering.format === TableChairNumberFormat.Prefixed ? `${ownerLabel}-${chairNumber}` : chairNumber;
158
+ return { ...seat, label: slot.labelOverride ?? label, chairNumber };
159
+ };
160
+ if (group.kind === SeatingKind.Round) {
133
161
  for (let i = 0; i < group.chairs.length; i++) {
134
162
  const geometry = roundChairGeometry(group.recipe, group.seatSizeM.height, i, group.chairs.length);
135
- yield emit(group.chairs[i], geometry.position, geometry.rotationDeg, sequenceLabel(group.labels.chairs, i, group.chairs.length), inventoryName(group.labels), null);
163
+ yield emitChair(group.chairs[i], geometry.position, geometry.rotationDeg, i, group.chairs.length);
136
164
  }
137
165
  }
138
166
  else {
139
- const sides = group.recipe.chairDistribution === TableChairDistribution.EqualSegments
140
- ? [TableSide.Top, TableSide.Bottom, TableSide.Left, TableSide.Right]
141
- : Object.values(TableSide);
167
+ const sides = rectangularChairOrder(group.recipe);
142
168
  const total = sides.reduce((n, s) => n + group.chairsBySide[s].length, 0);
143
169
  let ordinal = 0;
144
170
  for (const side of sides) {
145
171
  const list = group.chairsBySide[side];
146
172
  for (let i = 0; i < list.length; i++) {
147
173
  const geometry = rectangularChairGeometry(group.recipe, group.seatSizeM.height, side, i, list.length);
148
- yield emit(list[i], geometry.position, geometry.rotationDeg, sequenceLabel(group.labels.chairs, ordinal++, total), inventoryName(group.labels), null);
174
+ yield emitChair(list[i], geometry.position, geometry.rotationDeg, ordinal++, total);
149
175
  }
150
176
  }
151
177
  }
@@ -0,0 +1,8 @@
1
+ import type { PointM, PolygonM } from "../physical-document.interface.js";
2
+ /** The editable inventory envelope uses 22 layout units of radial padding. */
3
+ export declare function paddedSectionOutline(points: readonly PointM[]): PolygonM | null;
4
+ /** Confirm an exact generated envelope and retain its authored coordinates for history. */
5
+ export declare function matchesPaddedSectionOutline(points: readonly PointM[], actual: PolygonM | undefined, { toWorld, toleranceM }?: {
6
+ toWorld?: (point: PointM) => PointM;
7
+ toleranceM?: number;
8
+ }): boolean;
@@ -0,0 +1,46 @@
1
+ import { memberEnvelope } from "./venue-outline.js";
2
+ import { LayoutUnitM } from "./units.js";
3
+ const paddingM = 22 * LayoutUnitM;
4
+ const coordinateToleranceM = 1e-7;
5
+ function vertexMean(points) {
6
+ return points.reduce((sum, point) => ({ x: sum.x + point.x / points.length, y: sum.y + point.y / points.length }), {
7
+ x: 0,
8
+ y: 0,
9
+ });
10
+ }
11
+ function padInventoryHull(hull) {
12
+ if (hull.length < 3)
13
+ return null;
14
+ const center = vertexMean(hull);
15
+ return {
16
+ outer: hull.map((point) => {
17
+ const dx = point.x - center.x;
18
+ const dy = point.y - center.y;
19
+ const factor = paddingM / Math.hypot(dx, dy);
20
+ return { x: point.x + dx * factor, y: point.y + dy * factor };
21
+ }),
22
+ holes: [],
23
+ };
24
+ }
25
+ /** The editable inventory envelope uses 22 layout units of radial padding. */
26
+ export function paddedSectionOutline(points) {
27
+ return padInventoryHull(memberEnvelope(points, 0).outer);
28
+ }
29
+ function sameRing(actual, expected, toleranceM) {
30
+ const count = actual.length;
31
+ const samePoint = (a, b) => Math.hypot(a.x - b.x, a.y - b.y) <= toleranceM;
32
+ return (count === expected.length &&
33
+ actual.some((point, start) => samePoint(point, expected[0]) &&
34
+ [1, -1].some((direction) => expected.every((expectedPoint, index) => samePoint(expectedPoint, actual[(start + direction * index + count) % count])))));
35
+ }
36
+ /** Confirm an exact generated envelope and retain its authored coordinates for history. */
37
+ export function matchesPaddedSectionOutline(points, actual, { toWorld, toleranceM = coordinateToleranceM } = {}) {
38
+ if (!actual ||
39
+ actual.holes.length ||
40
+ actual.edgeCurvature?.some(Boolean) ||
41
+ actual.cornerRounding ||
42
+ actual.cornerRadiusM)
43
+ return false;
44
+ const expected = paddedSectionOutline(points);
45
+ return (expected !== null && sameRing(actual.outer, toWorld ? expected.outer.map(toWorld) : expected.outer, toleranceM));
46
+ }
@@ -32,10 +32,10 @@ const furniture = {
32
32
  polygon(0.08, 0.08, 0.19, 0.08, 0.3, 0.42, 0.19, 0.42),
33
33
  ],
34
34
  [SeatShape.Folding]: [
35
- polygon(-0.3, -0.42, 0.3, -0.42, 0.25, -0.2, -0.25, -0.2),
36
- polygon(-0.315, -0.14, 0.315, -0.14, 0.26, 0.02, -0.26, 0.02),
37
- polygon(-0.2, 0.0, -0.1, -0.02, 0.2, 0.42, 0.08, 0.42),
38
- polygon(0.1, -0.02, 0.2, 0.0, -0.08, 0.42, -0.2, 0.42),
35
+ polygon(-0.3, -0.44, 0.3, -0.44, 0.25, -0.2, -0.25, -0.2),
36
+ rectangle(-0.32, -0.15, 0.64, 0.18, 0.04),
37
+ polygon(-0.24, 0.02, -0.12, 0.02, -0.15, 0.44, -0.265, 0.44),
38
+ polygon(0.12, 0.02, 0.24, 0.02, 0.265, 0.44, 0.15, 0.44),
39
39
  ],
40
40
  [SeatShape.Armchair]: [
41
41
  rectangle(-0.34, -0.4, 0.68, 0.46, 0.08),
@@ -6,6 +6,7 @@ export declare enum TableSide {
6
6
  Bottom = "bottom",
7
7
  Left = "left"
8
8
  }
9
+ export declare function rectangularChairOrder(recipe: RectangularTable["recipe"]): readonly TableSide[];
9
10
  export declare function rowStaggerOffset(recipe: StraightRows["recipe"], index: number): number;
10
11
  /** A lane shift is derived from the recipe. The row offset remains an independent edit. */
11
12
  export declare function rowPlacementOffset(group: RowsGeometry, index: number, offset?: PointM): PointM;
@@ -7,6 +7,13 @@ export var TableSide;
7
7
  TableSide["Bottom"] = "bottom";
8
8
  TableSide["Left"] = "left";
9
9
  })(TableSide || (TableSide = {}));
10
+ const clockwiseTableSides = Object.values(TableSide);
11
+ const sideOrderedTableSides = [TableSide.Top, TableSide.Bottom, TableSide.Left, TableSide.Right];
12
+ export function rectangularChairOrder(recipe) {
13
+ return recipe.chairDistribution === TableChairDistribution.EqualSegments
14
+ ? sideOrderedTableSides
15
+ : clockwiseTableSides;
16
+ }
10
17
  export function rowStaggerOffset(recipe, index) {
11
18
  const lane = index % 2 === 0 ? RowStagger.First : RowStagger.Second;
12
19
  return recipe.stagger === lane ? recipe.seatPitchM / 2 : 0;