@seatmap-fyi/map-domain 0.1.0-alpha.4 → 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.
Files changed (111) hide show
  1. package/dist/arc-fan-rebuild.d.ts +17 -0
  2. package/dist/arc-fan-rebuild.js +227 -0
  3. package/dist/arc-fan-section-layout.d.ts +11 -0
  4. package/dist/arc-fan-section-layout.js +54 -0
  5. package/dist/arc-fan.d.ts +27 -0
  6. package/dist/arc-fan.interface.d.ts +100 -0
  7. package/dist/arc-fan.interface.js +30 -0
  8. package/dist/arc-fan.js +182 -0
  9. package/dist/catalog.d.ts +6 -4
  10. package/dist/catalog.js +31 -17
  11. package/dist/categories.d.ts +14 -3
  12. package/dist/categories.js +146 -35
  13. package/dist/editor-state.d.ts +4 -1
  14. package/dist/editor-state.js +53 -30
  15. package/dist/floors.d.ts +22 -0
  16. package/dist/floors.js +72 -0
  17. package/dist/geometry/boundary.d.ts +1 -1
  18. package/dist/geometry/boundary.js +16 -12
  19. package/dist/geometry/curve-warnings.d.ts +1 -1
  20. package/dist/geometry/curve-warnings.js +3 -5
  21. package/dist/geometry/decoration-bounds.d.ts +4 -0
  22. package/dist/geometry/decoration-bounds.js +42 -0
  23. package/dist/geometry/ellipse.js +4 -12
  24. package/dist/geometry/geometry.d.ts +9 -3
  25. package/dist/geometry/geometry.js +58 -34
  26. package/dist/geometry/inventory-outline.d.ts +8 -0
  27. package/dist/geometry/inventory-outline.js +46 -0
  28. package/dist/geometry/layout-transform.d.ts +10 -0
  29. package/dist/geometry/layout-transform.interface.d.ts +6 -0
  30. package/dist/geometry/layout-transform.interface.js +1 -0
  31. package/dist/geometry/layout-transform.js +206 -0
  32. package/dist/geometry/polygon-curves.d.ts +17 -0
  33. package/dist/geometry/polygon-curves.interface.d.ts +21 -0
  34. package/dist/geometry/polygon-curves.interface.js +5 -0
  35. package/dist/geometry/polygon-curves.js +169 -0
  36. package/dist/geometry/primitives.d.ts +1 -1
  37. package/dist/geometry/primitives.js +2 -3
  38. package/dist/geometry/seat-shape.d.ts +1 -1
  39. package/dist/geometry/seat-shape.js +5 -5
  40. package/dist/geometry/seating-layout.d.ts +10 -1
  41. package/dist/geometry/seating-layout.js +73 -57
  42. package/dist/geometry/units.d.ts +8 -0
  43. package/dist/geometry/units.js +13 -0
  44. package/dist/geometry/venue-outline.d.ts +4 -18
  45. package/dist/geometry/venue-outline.interface.d.ts +23 -0
  46. package/dist/geometry/venue-outline.interface.js +7 -0
  47. package/dist/geometry/venue-outline.js +142 -49
  48. package/dist/identity.d.ts +3 -1
  49. package/dist/identity.js +32 -17
  50. package/dist/issues.d.ts +16 -2
  51. package/dist/issues.js +17 -6
  52. package/dist/labels.d.ts +6 -1
  53. package/dist/labels.js +20 -18
  54. package/dist/layers.d.ts +26 -0
  55. package/dist/layers.js +86 -0
  56. package/dist/media.d.ts +27 -0
  57. package/dist/media.js +89 -0
  58. package/dist/{types.d.ts → physical-document.interface.d.ts} +142 -10
  59. package/dist/{types.js → physical-document.interface.js} +23 -0
  60. package/dist/preview.d.ts +1 -1
  61. package/dist/preview.js +39 -29
  62. package/dist/reference.js +1 -1
  63. package/dist/row-segments.d.ts +5 -1
  64. package/dist/row-segments.js +10 -9
  65. package/dist/schema.d.ts +680 -18
  66. package/dist/schema.js +269 -111
  67. package/dist/seat-proximity.d.ts +4 -0
  68. package/dist/seat-proximity.js +119 -0
  69. package/dist/section-elevation.d.ts +5 -0
  70. package/dist/section-elevation.interface.d.ts +26 -0
  71. package/dist/section-elevation.interface.js +8 -0
  72. package/dist/section-elevation.js +53 -0
  73. package/dist/section-fill-rebuild.d.ts +10 -0
  74. package/dist/section-fill-rebuild.js +64 -0
  75. package/dist/section-fill.d.ts +84 -0
  76. package/dist/section-fill.interface.d.ts +94 -0
  77. package/dist/section-fill.interface.js +22 -0
  78. package/dist/section-fill.js +306 -0
  79. package/dist/section-growth.d.ts +11 -0
  80. package/dist/section-growth.interface.d.ts +20 -0
  81. package/dist/section-growth.interface.js +1 -0
  82. package/dist/section-growth.js +245 -0
  83. package/dist/section-layout.d.ts +101 -0
  84. package/dist/section-layout.interface.d.ts +8 -0
  85. package/dist/section-layout.interface.js +5 -0
  86. package/dist/section-layout.js +72 -0
  87. package/dist/section-outline-refit.d.ts +8 -0
  88. package/dist/section-outline-refit.js +246 -0
  89. package/dist/section-refit.d.ts +22 -0
  90. package/dist/section-refit.interface.d.ts +49 -0
  91. package/dist/section-refit.interface.js +6 -0
  92. package/dist/section-refit.js +179 -0
  93. package/dist/section-scale.d.ts +2 -0
  94. package/dist/section-scale.js +128 -0
  95. package/dist/sections.d.ts +23 -0
  96. package/dist/sections.js +144 -0
  97. package/dist/selling.d.ts +1 -1
  98. package/dist/selling.js +11 -26
  99. package/dist/spacing-repairs.d.ts +31 -0
  100. package/dist/spacing-repairs.js +168 -0
  101. package/dist/table-layout.d.ts +3 -3
  102. package/dist/table-layout.js +35 -35
  103. package/dist/validation.d.ts +7 -2
  104. package/dist/validation.interface.d.ts +20 -0
  105. package/dist/validation.interface.js +9 -0
  106. package/dist/validation.js +221 -85
  107. package/dist/wayfinding.d.ts +10 -0
  108. package/dist/wayfinding.interface.d.ts +52 -0
  109. package/dist/wayfinding.interface.js +28 -0
  110. package/dist/wayfinding.js +63 -0
  111. package/package.json +97 -4
@@ -0,0 +1,17 @@
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
+ export declare const arcFanRebuildMessages: Record<ArcFanRebuildIssue, string>;
4
+ export declare const arcFanGeometryEntryMessage = "This fan has manually edited geometry. Edit its rows individually to keep those changes.";
5
+ export declare function arcFanParts(plan: ArcFanPlan): ArcFanPart[];
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;
10
+ export declare function arcFanSequenceCustomized(row: RowSlot, part: ArcFanPart): boolean;
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;
14
+ /** Show the same authored fan in world coordinates, including inherited rotation and reflection. */
15
+ export declare function arcFanWorldInput(document: PhysicalDocumentV1, group: ArcFanRows): ArcFanInput;
16
+ /** Convert the form's world draft back into the bank's single local geometry owner. */
17
+ export declare function arcFanRebuildPlacement(document: PhysicalDocumentV1, group: ArcFanRows, input: ArcFanInput): ArcFanRebuildPlacement;
@@ -0,0 +1,227 @@
1
+ import { arcFanSeats, planArcFan } from "./arc-fan.js";
2
+ import { ArcFanRebuildIssue, ArcFanSectionOrigin, } from "./arc-fan.interface.js";
3
+ import { NumberingScheme, LabelDirection, RowEnds } from "./physical-document.interface.js";
4
+ import { worldMatrices, inverse, project, normalizeAngle } from "./geometry/geometry.js";
5
+ import { resolveRowLayout, rowPlacementOffset } from "./geometry/seating-layout.js";
6
+ import { matchesPaddedSectionOutline } from "./geometry/inventory-outline.js";
7
+ import { LayoutUnitM } from "./geometry/units.js";
8
+ import { seatHasOwnSettings } from "./selling.js";
9
+ import { mapEditorPolicy } from "./editor-state.js";
10
+ const coordinateToleranceM = 1e-7;
11
+ const angleToleranceDeg = 1e-7;
12
+ const outlineSeatGridM = LayoutUnitM / 1_000_000;
13
+ const outlineRoundoffM = outlineSeatGridM / 1_000;
14
+ const degrees = 180 / Math.PI;
15
+ const rowSources = new WeakMap();
16
+ const sources = new WeakMap();
17
+ const generatedRowFields = new Set([
18
+ "zIndex",
19
+ "id",
20
+ "seats",
21
+ "layout",
22
+ "fillOrigin",
23
+ "bookingLabel",
24
+ "seatSequenceOverride",
25
+ "aisleSeats",
26
+ "offsetM",
27
+ "labelOverride",
28
+ ]);
29
+ export const arcFanRebuildMessages = {
30
+ [ArcFanRebuildIssue.Geometry]: "This fan can no longer be rebuilt safely. Edit its rows individually.",
31
+ [ArcFanRebuildIssue.CustomizedShape]: "Keep the existing seat layout when resizing a customized fan. Changes to its shape, spacing or aisles need individual row edits.",
32
+ [ArcFanRebuildIssue.RemoveCustomizedRow]: "This would remove a customized row. Keep that row or clear its custom settings first.",
33
+ };
34
+ export const arcFanGeometryEntryMessage = "This fan has manually edited geometry. Edit its rows individually to keep those changes.";
35
+ export function arcFanParts(plan) {
36
+ return plan.rows.flatMap((row, rowIndex) => {
37
+ let startAt = 1;
38
+ return row.parts.map((part, partIndex) => {
39
+ const sequence = { scheme: NumberingScheme.Numeric, startAt, direction: LabelDirection.Forward };
40
+ startAt += part.seats;
41
+ let aisleSeats = RowEnds.None;
42
+ if (row.parts.length > 1) {
43
+ if (partIndex === 0)
44
+ aisleSeats = RowEnds.End;
45
+ else if (partIndex === row.parts.length - 1)
46
+ aisleSeats = RowEnds.Start;
47
+ else
48
+ aisleSeats = RowEnds.Both;
49
+ }
50
+ return { ...part, rowIndex, partIndex, sequence, aisleSeats };
51
+ });
52
+ });
53
+ }
54
+ function sameAngle(a, b) {
55
+ return Math.abs(normalizeAngle(a - b)) <= angleToleranceDeg;
56
+ }
57
+ function samePoint(a, b) {
58
+ return Math.hypot(a.x - b.x, a.y - b.y) <= coordinateToleranceM;
59
+ }
60
+ function sameLayout(a, b) {
61
+ return (samePoint(a.originM, b.originM) &&
62
+ Math.abs(a.seatPitchM - b.seatPitchM) <= coordinateToleranceM &&
63
+ Math.abs(a.curveDeg - b.curveDeg) <= angleToleranceDeg &&
64
+ sameAngle(a.rotationDeg, b.rotationDeg) &&
65
+ sameAngle(a.seatRotationOffsetDeg ?? 0, b.seatRotationOffsetDeg ?? 0));
66
+ }
67
+ /** Compare current physical rows with generation provenance; seat customizations remain independent. */
68
+ function rowSource(group) {
69
+ if (rowSources.has(group))
70
+ return rowSources.get(group);
71
+ const generation = group.arcFan;
72
+ const plan = generation ? planArcFan({ ...generation.recipe, center: { x: 0, y: 0 } }) : null;
73
+ let source = null;
74
+ if (plan && generation) {
75
+ const parts = arcFanParts(plan);
76
+ if (parts.length === group.rows.length && generation.members.length === parts.length) {
77
+ const current = group.rows.every((row, index) => {
78
+ const part = parts[index];
79
+ if (row.id !== generation.members[index].rowId || row.seats.length !== part.seats)
80
+ return false;
81
+ const layout = resolveRowLayout(group, index);
82
+ if (!layout)
83
+ return false;
84
+ const offset = rowPlacementOffset(group, index, row.offsetM);
85
+ return sameLayout({ ...layout, originM: { x: layout.originM.x + offset.x, y: layout.originM.y + offset.y } }, part.layout);
86
+ });
87
+ if (current)
88
+ source = { parts, members: generation.members, rows: group.rows };
89
+ }
90
+ }
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);
138
+ return source;
139
+ }
140
+ export function arcFanSequenceCustomized(row, part) {
141
+ const sequence = row.seatSequenceOverride;
142
+ return (!!sequence &&
143
+ (sequence.scheme !== part.sequence.scheme ||
144
+ sequence.startAt !== part.sequence.startAt ||
145
+ sequence.direction !== part.sequence.direction ||
146
+ !!sequence.prefix ||
147
+ !!sequence.suffix));
148
+ }
149
+ function rowCustomized(source, index) {
150
+ const row = source.rows[index], part = source.parts[index];
151
+ return (row.labelOverride !== source.members[index].labelOverride ||
152
+ row.bookingLabel !== source.members[index].bookingLabel ||
153
+ arcFanSequenceCustomized(row, part) ||
154
+ (row.aisleSeats !== undefined && row.aisleSeats !== part.aisleSeats) ||
155
+ Object.entries(row).some(([key, value]) => !generatedRowFields.has(key) && value !== undefined));
156
+ }
157
+ /** Customized fans keep the measured row layout; equivalent truncated arcs are still shape changes in the reference. */
158
+ function retainsSeatLayout(before, after) {
159
+ return sameLayout(before.layout, after.layout);
160
+ }
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);
168
+ if (!source)
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);
173
+ const nextParts = arcFanParts(plan);
174
+ const next = new Map(nextParts.map((part) => [part.rowIndex + ":" + part.partIndex, part]));
175
+ for (let index = 0; index < source.rows.length; index++) {
176
+ const row = source.rows[index], part = source.parts[index];
177
+ const after = next.get(part.rowIndex + ":" + part.partIndex);
178
+ const locked = policy.lockOwner(row.id);
179
+ const custom = locked || rowCustomized(source, index) || row.seats.some(seatHasOwnSettings);
180
+ if (!after) {
181
+ if (custom)
182
+ return ArcFanRebuildIssue.RemoveCustomizedRow;
183
+ continue;
184
+ }
185
+ if (locked && (moved || after.seats !== row.seats.length))
186
+ return ArcFanRebuildIssue.CustomizedShape;
187
+ if (row.seats.slice(after.seats).some(seatHasOwnSettings))
188
+ return ArcFanRebuildIssue.CustomizedShape;
189
+ if (custom && (categoryChanged || !retainsSeatLayout(part, after)))
190
+ return ArcFanRebuildIssue.CustomizedShape;
191
+ }
192
+ return null;
193
+ }
194
+ /** Show the same authored fan in world coordinates, including inherited rotation and reflection. */
195
+ export function arcFanWorldInput(document, group) {
196
+ const matrix = worldMatrices(document).get(group.id);
197
+ const direction = matrix.a * matrix.d - matrix.b * matrix.c < 0 ? -1 : 1;
198
+ const angle = Math.atan2(matrix.c, matrix.d) * degrees;
199
+ const recipe = group.arcFan.recipe;
200
+ return {
201
+ ...recipe,
202
+ center: { x: matrix.tx, y: matrix.ty },
203
+ startAngleDeg: direction * recipe.startAngleDeg + angle,
204
+ endAngleDeg: direction * recipe.endAngleDeg + angle,
205
+ skewDeg: direction * recipe.skewDeg,
206
+ };
207
+ }
208
+ /** Convert the form's world draft back into the bank's single local geometry owner. */
209
+ export function arcFanRebuildPlacement(document, group, input) {
210
+ const matrices = worldMatrices(document), matrix = matrices.get(group.id);
211
+ const direction = matrix.a * matrix.d - matrix.b * matrix.c < 0 ? -1 : 1;
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
+ }
217
+ return {
218
+ input: {
219
+ ...input,
220
+ center: { x: 0, y: 0 },
221
+ startAngleDeg: direction * (input.startAngleDeg - angle),
222
+ endAngleDeg: direction * (input.endAngleDeg - angle),
223
+ skewDeg: direction * input.skewDeg,
224
+ },
225
+ transform: { ...group.transform, positionM },
226
+ };
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
+ }
@@ -0,0 +1,27 @@
1
+ import { type PointM } from "./physical-document.interface.js";
2
+ import { ArcFanFacing, ArcFanFit, type ArcFanInput, type ArcFanPlan } from "./arc-fan.interface.js";
3
+ export declare const arcFanLimits: {
4
+ readonly rows: 100;
5
+ };
6
+ export declare const arcFanDefaults: {
7
+ readonly rowCount: 8;
8
+ readonly innerRadiusM: number;
9
+ readonly rowPitchM: number;
10
+ readonly seatPitchM: number;
11
+ readonly startAngleDeg: -50;
12
+ readonly endAngleDeg: 50;
13
+ readonly taperDeg: 0;
14
+ readonly skewDeg: 0;
15
+ readonly fit: ArcFanFit.Spacing;
16
+ readonly facing: ArcFanFacing.Inward;
17
+ readonly aisles: {
18
+ readonly left: 0;
19
+ readonly center: number;
20
+ readonly right: 0;
21
+ };
22
+ };
23
+ export declare function arcFanPoint(center: PointM, radiusM: number, angleDeg: number): PointM;
24
+ /** Emit current RowLayout geometry; preview, command creation and both renderers share these rows. */
25
+ export declare function planArcFan(input: ArcFanInput): ArcFanPlan | null;
26
+ /** Sample flattened physical seat order without calculating skipped geometry; stride1 retains every seat. */
27
+ export declare function arcFanSeats(plan: ArcFanPlan, stride?: number): PointM[];
@@ -0,0 +1,100 @@
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";
5
+ import type { SectionFillPlan } from "./section-fill.interface.js";
6
+ export declare enum ArcFanFit {
7
+ Spacing = "spacing",
8
+ SameCount = "sameCount"
9
+ }
10
+ export declare enum ArcFanFacing {
11
+ Inward = "inward",
12
+ Outward = "outward"
13
+ }
14
+ export declare enum ArcFanAisle {
15
+ Left = "left",
16
+ Center = "center",
17
+ Right = "right"
18
+ }
19
+ export declare const ArcFanMaximumRows = 100;
20
+ export declare const ArcFanMaximumSpanDeg = 320;
21
+ export declare const ArcFanMaximumPartsPerRow = 4;
22
+ export declare enum ArcFanSectionOrigin {
23
+ Generated = "generated",
24
+ Existing = "existing"
25
+ }
26
+ export declare enum ArcFanRebuildIssue {
27
+ Geometry = "geometry",
28
+ CustomizedShape = "customizedShape",
29
+ RemoveCustomizedRow = "removeCustomizedRow"
30
+ }
31
+ /** Generation membership is provenance, not a second editable row model. Missing members disable rebuilding. */
32
+ export type ArcFanMember = {
33
+ rowId: UUID;
34
+ bookingLabel: string;
35
+ labelOverride?: string;
36
+ };
37
+ export type ArcFanRows = StraightRows | CurvedRows;
38
+ export type ArcFanRebuildSettings = {
39
+ categoryId: UUID | null;
40
+ positionM: PointM;
41
+ editorState: MapEditorState;
42
+ };
43
+ export type ArcFanPart = {
44
+ rowIndex: number;
45
+ partIndex: number;
46
+ seats: number;
47
+ layout: RowLayout;
48
+ sequence: LabelSequence;
49
+ aisleSeats: RowEnds;
50
+ };
51
+ export type ArcFanRebuildSource = {
52
+ parts: ArcFanPart[];
53
+ members: ArcFanMember[];
54
+ rows: RowSlot[];
55
+ };
56
+ export type ArcFanRebuildPlacement = {
57
+ input: ArcFanInput;
58
+ transform: Transform;
59
+ };
60
+ /** Geometry is local to the current row bank; its transform owns the centre and orientation. */
61
+ export type ArcFanRecipe = {
62
+ rowCount: number;
63
+ innerRadiusM: number;
64
+ rowPitchM: number;
65
+ seatPitchM: number;
66
+ startAngleDeg: number;
67
+ endAngleDeg: number;
68
+ taperDeg: number;
69
+ skewDeg: number;
70
+ fit: ArcFanFit;
71
+ facing: ArcFanFacing;
72
+ seatsPerRow?: number;
73
+ aisles: Record<ArcFanAisle, number>;
74
+ };
75
+ export type ArcFanInput = ArcFanRecipe & {
76
+ center: PointM;
77
+ };
78
+ /** One recipe per generated bank; physical rows remain independent, without connected-row joins. */
79
+ export type ArcFanGeneration = {
80
+ recipe: ArcFanRecipe;
81
+ sectionId: UUID | null;
82
+ sectionOrigin: ArcFanSectionOrigin;
83
+ /** Local origin of the layout-microunit grid used to generate an imported section outline. */
84
+ sectionOutlineGridOriginM?: PointM;
85
+ members: ArcFanMember[];
86
+ };
87
+ export type ArcFanPlan = Pick<SectionFillPlan, "rows" | "recipe"> & {
88
+ seats: number;
89
+ segments: number;
90
+ minimumPitchM: number;
91
+ maximumPitchM: number;
92
+ aisles: number;
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
+ }
@@ -0,0 +1,30 @@
1
+ export var ArcFanFit;
2
+ (function (ArcFanFit) {
3
+ ArcFanFit["Spacing"] = "spacing";
4
+ ArcFanFit["SameCount"] = "sameCount";
5
+ })(ArcFanFit || (ArcFanFit = {}));
6
+ export var ArcFanFacing;
7
+ (function (ArcFanFacing) {
8
+ ArcFanFacing["Inward"] = "inward";
9
+ ArcFanFacing["Outward"] = "outward";
10
+ })(ArcFanFacing || (ArcFanFacing = {}));
11
+ export var ArcFanAisle;
12
+ (function (ArcFanAisle) {
13
+ ArcFanAisle["Left"] = "left";
14
+ ArcFanAisle["Center"] = "center";
15
+ ArcFanAisle["Right"] = "right";
16
+ })(ArcFanAisle || (ArcFanAisle = {}));
17
+ export const ArcFanMaximumRows = 100;
18
+ export const ArcFanMaximumSpanDeg = 320;
19
+ export const ArcFanMaximumPartsPerRow = 4;
20
+ export var ArcFanSectionOrigin;
21
+ (function (ArcFanSectionOrigin) {
22
+ ArcFanSectionOrigin["Generated"] = "generated";
23
+ ArcFanSectionOrigin["Existing"] = "existing";
24
+ })(ArcFanSectionOrigin || (ArcFanSectionOrigin = {}));
25
+ export var ArcFanRebuildIssue;
26
+ (function (ArcFanRebuildIssue) {
27
+ ArcFanRebuildIssue["Geometry"] = "geometry";
28
+ ArcFanRebuildIssue["CustomizedShape"] = "customizedShape";
29
+ ArcFanRebuildIssue["RemoveCustomizedRow"] = "removeCustomizedRow";
30
+ })(ArcFanRebuildIssue || (ArcFanRebuildIssue = {}));
@@ -0,0 +1,182 @@
1
+ import { LayoutUnitM, toLayoutUnits } from "./geometry/units.js";
2
+ import { rowSeatGeometry } from "./geometry/seating-layout.js";
3
+ import { DocumentLimits, LabelDirection, SeatingKind } from "./physical-document.interface.js";
4
+ import { ArcFanMaximumRows, ArcFanMaximumSpanDeg, ArcFanAisle, ArcFanFacing, ArcFanFit, } from "./arc-fan.interface.js";
5
+ import { normalizeAngle } from "./geometry/geometry.js";
6
+ const radians = Math.PI / 180;
7
+ const aislePositions = [
8
+ { aisle: ArcFanAisle.Left, fraction: 0.25 },
9
+ { aisle: ArcFanAisle.Center, fraction: 0.5 },
10
+ { aisle: ArcFanAisle.Right, fraction: 0.75 },
11
+ ];
12
+ export const arcFanLimits = { rows: ArcFanMaximumRows };
13
+ export const arcFanDefaults = {
14
+ rowCount: 8,
15
+ innerRadiusM: 240 * LayoutUnitM,
16
+ rowPitchM: 28 * LayoutUnitM,
17
+ seatPitchM: 24 * LayoutUnitM,
18
+ startAngleDeg: -50,
19
+ endAngleDeg: 50,
20
+ taperDeg: 0,
21
+ skewDeg: 0,
22
+ fit: ArcFanFit.Spacing,
23
+ facing: ArcFanFacing.Inward,
24
+ aisles: { left: 0, center: 32 * LayoutUnitM, right: 0 },
25
+ };
26
+ export function arcFanPoint(center, radiusM, angleDeg) {
27
+ return { x: center.x + radiusM * Math.sin(angleDeg * radians), y: center.y + radiusM * Math.cos(angleDeg * radians) };
28
+ }
29
+ const minimumSeatsPerPart = 2;
30
+ const minimumPartPitchRatio = 0.75;
31
+ /** Reserve each segment’s minimum, then distribute the largest fractional remainders in segment order. */
32
+ function distributeSeats(total, spans) {
33
+ const remaining = total - spans.length * minimumSeatsPerPart;
34
+ if (remaining < 0)
35
+ return null;
36
+ const length = spans.reduce((sum, span) => sum + span, 0);
37
+ const quotas = spans.map((span) => (remaining * span) / length);
38
+ const counts = quotas.map((quota) => minimumSeatsPerPart + Math.floor(quota));
39
+ const order = quotas
40
+ .map((quota, index) => ({ index, remainder: quota - Math.floor(quota) }))
41
+ .sort((a, b) => b.remainder - a.remainder || a.index - b.index);
42
+ let left = total - counts.reduce((sum, count) => sum + count, 0);
43
+ for (const { index } of order) {
44
+ if (!left)
45
+ break;
46
+ counts[index]++;
47
+ left--;
48
+ }
49
+ return counts;
50
+ }
51
+ /** Emit current RowLayout geometry; preview, command creation and both renderers share these rows. */
52
+ export function planArcFan(input) {
53
+ const { rowCount, innerRadiusM, rowPitchM, seatPitchM, startAngleDeg, endAngleDeg, taperDeg, skewDeg } = input;
54
+ if (!Number.isInteger(rowCount) ||
55
+ rowCount < 1 ||
56
+ rowCount > arcFanLimits.rows ||
57
+ innerRadiusM <= 0 ||
58
+ rowPitchM <= 0 ||
59
+ seatPitchM <= 0)
60
+ return null;
61
+ if (![
62
+ innerRadiusM,
63
+ rowPitchM,
64
+ seatPitchM,
65
+ startAngleDeg,
66
+ endAngleDeg,
67
+ taperDeg,
68
+ skewDeg,
69
+ input.center.x,
70
+ input.center.y,
71
+ ...Object.values(input.aisles),
72
+ ].every(Number.isFinite))
73
+ return null;
74
+ if (input.fit === ArcFanFit.SameCount && (!Number.isInteger(input.seatsPerRow) || input.seatsPerRow < 1))
75
+ return null;
76
+ const direction = Math.sign(endAngleDeg - startAngleDeg);
77
+ const outward = input.facing === ArcFanFacing.Outward;
78
+ const partDirection = outward ? -direction : direction;
79
+ if (!direction || Math.abs(endAngleDeg - startAngleDeg) > ArcFanMaximumSpanDeg)
80
+ return null;
81
+ const plan = {
82
+ rows: [],
83
+ recipe: { seatPitchM, rowPitchM },
84
+ seats: 0,
85
+ segments: 0,
86
+ minimumPitchM: Infinity,
87
+ maximumPitchM: 0,
88
+ aisles: aislePositions.filter(({ aisle }) => input.aisles[aisle] > 0).length,
89
+ };
90
+ const innerRadiusUnits = toLayoutUnits(innerRadiusM);
91
+ const rowPitchUnits = toLayoutUnits(rowPitchM);
92
+ const seatPitchUnits = toLayoutUnits(seatPitchM);
93
+ for (let index = 0; index < rowCount; index++) {
94
+ const fraction = rowCount === 1 ? 0 : index / (rowCount - 1);
95
+ const start = startAngleDeg + (direction * taperDeg + skewDeg) * fraction;
96
+ const end = endAngleDeg + (-direction * taperDeg + skewDeg) * fraction;
97
+ if (!Number.isFinite(end - start) || (end - start) * direction <= 0)
98
+ return null;
99
+ const radiusM = innerRadiusM + index * rowPitchM;
100
+ const radiusUnits = innerRadiusUnits + index * rowPitchUnits;
101
+ const sweepDeg = end - start;
102
+ const sweepRadians = Math.abs(sweepDeg) * radians;
103
+ const arcLengthUnits = radiusUnits * sweepRadians;
104
+ const aisleSpans = [];
105
+ for (const { aisle, fraction: position } of aislePositions) {
106
+ const widthM = input.aisles[aisle];
107
+ if (widthM < 0)
108
+ return null;
109
+ if (!widthM)
110
+ continue;
111
+ const half = toLayoutUnits(widthM) / radiusUnits / sweepRadians / 2;
112
+ aisleSpans.push({ start: position - half, end: position + half });
113
+ }
114
+ aisleSpans.sort((a, b) => a.start - b.start);
115
+ const intervals = [];
116
+ let previous = 0;
117
+ for (const span of aisleSpans) {
118
+ if (input.fit === ArcFanFit.SameCount && (span.start <= previous || span.end >= 1))
119
+ return null;
120
+ if (span.start > previous)
121
+ intervals.push({ start: previous, end: span.start });
122
+ previous = Math.max(previous, span.end);
123
+ }
124
+ if (previous < 1)
125
+ intervals.push({ start: previous, end: 1 });
126
+ if (!intervals.length)
127
+ return null;
128
+ const nominalPitchUnits = input.fit === ArcFanFit.SameCount ? arcLengthUnits / input.seatsPerRow : seatPitchUnits;
129
+ const minimumPartLength = nominalPitchUnits * minimumPartPitchRatio;
130
+ const usable = intervals.filter((part) => (part.end - part.start) * arcLengthUnits >= minimumPartLength);
131
+ if (!usable.length || (input.fit === ArcFanFit.SameCount && usable.length !== intervals.length))
132
+ return null;
133
+ const lengthsUnits = usable.map((part) => (part.end - part.start) * arcLengthUnits);
134
+ const counts = input.fit === ArcFanFit.SameCount
135
+ ? distributeSeats(input.seatsPerRow, lengthsUnits)
136
+ : lengthsUnits.map((length) => Math.round(length / seatPitchUnits) + 1);
137
+ if (!counts || counts.some((count) => count < minimumSeatsPerPart))
138
+ return null;
139
+ const parts = usable.map((part, partIndex) => {
140
+ const seats = counts[partIndex];
141
+ const partStart = start + sweepDeg * (outward ? part.end : part.start);
142
+ const curveDeg = (part.end - part.start) * sweepDeg * (outward ? -1 : 1);
143
+ const pitch = 2 * radiusM * Math.sin((Math.abs(curveDeg) * radians) / (2 * (seats - 1)));
144
+ plan.minimumPitchM = Math.min(plan.minimumPitchM, pitch);
145
+ plan.maximumPitchM = Math.max(plan.maximumPitchM, pitch);
146
+ plan.seats += seats;
147
+ plan.segments++;
148
+ return {
149
+ seats,
150
+ layout: {
151
+ originM: arcFanPoint(input.center, radiusM, partStart),
152
+ seatPitchM: pitch,
153
+ curveDeg,
154
+ rotationDeg: normalizeAngle(-partStart + (partDirection < 0 ? 180 : 0)),
155
+ seatRotationOffsetDeg: (partDirection < 0 ? -180 : 0) + (outward ? 180 : 0),
156
+ },
157
+ };
158
+ });
159
+ if (plan.seats > DocumentLimits.PhysicalSeats)
160
+ return null;
161
+ plan.rows.push({ parts: outward ? parts.reverse() : parts, numbering: LabelDirection.Forward });
162
+ }
163
+ return plan;
164
+ }
165
+ /** Sample flattened physical seat order without calculating skipped geometry; stride1 retains every seat. */
166
+ export function arcFanSeats(plan, stride = 1) {
167
+ if (!Number.isInteger(stride) || stride < 1)
168
+ throw new RangeError("Seat stride must be a positive integer.");
169
+ const geometry = { kind: SeatingKind.Straight, recipe: plan.recipe };
170
+ const points = [];
171
+ let offset = 0;
172
+ for (const row of plan.rows) {
173
+ for (const part of row.parts) {
174
+ const first = (stride - (offset % stride)) % stride;
175
+ for (let seat = first; seat < part.seats; seat += stride) {
176
+ points.push(rowSeatGeometry(geometry, 0, seat, part.seats, part.seats, part.layout).position);
177
+ }
178
+ offset += part.seats;
179
+ }
180
+ }
181
+ return points;
182
+ }