@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
package/dist/floors.js ADDED
@@ -0,0 +1,72 @@
1
+ import { documentCatalog } from "./catalog.js";
2
+ import { groupInventoryCount } from "./schema.js";
3
+ import { LayoutUnitM } from "./geometry/units.js";
4
+ import { AreaKind, } from "./physical-document.interface.js";
5
+ const catalogs = new WeakMap();
6
+ /** Derive physical membership and counts once, without creating another editable document. */
7
+ export function floorCatalog(document) {
8
+ const cached = catalogs.get(document);
9
+ if (cached)
10
+ return cached;
11
+ const entries = new Map();
12
+ const owners = new Map();
13
+ for (const floor of document.floors ?? [])
14
+ entries.set(floor.id, { floor, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, rowGapCount: 0 });
15
+ if (!document.floors)
16
+ entries.set(null, { floor: null, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, rowGapCount: 0 });
17
+ for (const member of [
18
+ ...document.sections,
19
+ ...document.collections,
20
+ ...document.seatingGroups,
21
+ ...document.areas,
22
+ ...document.decorations,
23
+ ]) {
24
+ const id = member.floorId ?? null;
25
+ owners.set(member.id, id);
26
+ entries.get(id).members.push(member.id);
27
+ }
28
+ for (const group of document.seatingGroups) {
29
+ const id = group.floorId ?? null;
30
+ const entry = entries.get(id);
31
+ const inventoryCount = groupInventoryCount(group);
32
+ if ("rows" in group) {
33
+ let slotCount = 0;
34
+ for (const row of group.rows) {
35
+ owners.set(row.id, id);
36
+ slotCount += row.seats.length;
37
+ }
38
+ entry.rowGapCount += slotCount - inventoryCount;
39
+ }
40
+ entry.capacity.physicalSeats += inventoryCount;
41
+ }
42
+ for (const area of document.areas) {
43
+ const count = entries.get(area.floorId ?? null).capacity;
44
+ if (area.kind === AreaKind.Booth)
45
+ count.physicalSeats++;
46
+ else
47
+ count.gaQuantity += area.capacity;
48
+ }
49
+ for (const row of document.segmentedRows ?? [])
50
+ owners.set(row.id, owners.get(row.parts[0].rowId));
51
+ const catalog = { entries, owners };
52
+ catalogs.set(document, catalog);
53
+ return catalog;
54
+ }
55
+ /** Resolve seats through their physical owner; logical rows use their first physical part. */
56
+ export function objectFloorId(document, id) {
57
+ const owners = floorCatalog(document).owners;
58
+ if (owners.has(id))
59
+ return owners.get(id);
60
+ return documentCatalog(document).seats.get(id)?.group.floorId ?? null;
61
+ }
62
+ export function floorLabel(floor) {
63
+ return /^\d+$/u.test(floor.name) ? `Floor ${floor.name}` : floor.name;
64
+ }
65
+ const DefaultFocalOffset = 40 * LayoutUnitM;
66
+ export const DefaultFloorFocalPoint = Object.freeze({ x: 0, y: -DefaultFocalOffset });
67
+ export function authoredFloorFocalPoint(document, floorId) {
68
+ return document.floors?.find((floor) => floor.id === floorId)?.focalPoint;
69
+ }
70
+ export function sameFocalPoint(first, second) {
71
+ return first?.x === second?.x && first?.y === second?.y;
72
+ }
@@ -1,4 +1,4 @@
1
- import type { PointM, PolygonM } from "../types.js";
1
+ import type { PointM, PolygonM } from "../physical-document.interface.js";
2
2
  import { type Bounds } from "./primitives.js";
3
3
  export declare enum BoundaryLocation {
4
4
  Inside = "inside",
@@ -1,4 +1,5 @@
1
- import { containsPoint, pointsBounds, intersects, } from "./primitives.js";
1
+ import { polygonContour } from "./polygon-curves.js";
2
+ import { containsPoint, pointsBounds, intersects } from "./primitives.js";
2
3
  export var BoundaryLocation;
3
4
  (function (BoundaryLocation) {
4
5
  BoundaryLocation["Inside"] = "inside";
@@ -11,10 +12,11 @@ export function prepareBoundary(polygon) {
11
12
  const cached = prepared.get(polygon);
12
13
  if (cached)
13
14
  return cached;
15
+ const contour = polygonContour(polygon);
14
16
  const boundary = {
15
- polygon,
16
- bounds: pointsBounds(polygon.outer),
17
- edges: [polygon.outer, ...polygon.holes].flatMap((r) => r.map((a, i) => ({
17
+ polygon: contour,
18
+ bounds: pointsBounds(contour.outer),
19
+ edges: [contour.outer, ...contour.holes].flatMap((r) => r.map((a, i) => ({
18
20
  a,
19
21
  b: r[(i + 1) % r.length],
20
22
  bounds: pointsBounds([a, r[(i + 1) % r.length]]),
@@ -24,16 +26,19 @@ export function prepareBoundary(polygon) {
24
26
  return boundary;
25
27
  }
26
28
  function onEdge(edge, p) {
27
- const dx = edge.b.x - edge.a.x, dy = edge.b.y - edge.a.y, t = Math.max(0, Math.min(1, ((p.x - edge.a.x) * dx + (p.y - edge.a.y) * dy) /
28
- Math.max(1e-30, dx * dx + dy * dy)));
29
- return (Math.hypot(p.x - edge.a.x - t * dx, p.y - edge.a.y - t * dy) <=
30
- BoundaryToleranceM);
29
+ const dx = edge.b.x - edge.a.x, dy = edge.b.y - edge.a.y, t = Math.max(0, Math.min(1, ((p.x - edge.a.x) * dx + (p.y - edge.a.y) * dy) / Math.max(1e-30, dx * dx + dy * dy)));
30
+ return Math.hypot(p.x - edge.a.x - t * dx, p.y - edge.a.y - t * dy) <= BoundaryToleranceM;
31
31
  }
32
32
  export function classifyBoundary(boundary, p) {
33
+ const { minX, minY, maxX, maxY } = boundary.bounds;
34
+ if (p.x < minX - BoundaryToleranceM ||
35
+ p.x > maxX + BoundaryToleranceM ||
36
+ p.y < minY - BoundaryToleranceM ||
37
+ p.y > maxY + BoundaryToleranceM)
38
+ return BoundaryLocation.Outside;
33
39
  if (boundary.edges.some((e) => onEdge(e, p)))
34
40
  return BoundaryLocation.Boundary;
35
- if (!containsPoint(boundary.polygon.outer, p) ||
36
- boundary.polygon.holes.some((h) => containsPoint(h, p)))
41
+ if (!containsPoint(boundary.polygon.outer, p) || boundary.polygon.holes.some((h) => containsPoint(h, p)))
37
42
  return BoundaryLocation.Outside;
38
43
  return BoundaryLocation.Inside;
39
44
  }
@@ -55,8 +60,7 @@ export function footprintInBoundary(boundary, points) {
55
60
  cuts.sort((l, r) => l - r);
56
61
  for (let j = 1; j < cuts.length; j++) {
57
62
  const t = (cuts[j - 1] + cuts[j]) / 2;
58
- if (classifyBoundary(boundary, { x: a.x + t * dx, y: a.y + t * dy }) ===
59
- BoundaryLocation.Outside)
63
+ if (classifyBoundary(boundary, { x: a.x + t * dx, y: a.y + t * dy }) === BoundaryLocation.Outside)
60
64
  return false;
61
65
  }
62
66
  }
@@ -1,4 +1,4 @@
1
- import { type CurvedRows, type RowSlot } from "../types.js";
1
+ import { type CurvedRows, type RowSlot } from "../physical-document.interface.js";
2
2
  export declare enum CurveWarningKind {
3
3
  Overrun = "overrun",
4
4
  Clearance = "clearance"
@@ -1,4 +1,4 @@
1
- import { CurveMode, SeatingKind, } from "../types.js";
1
+ import { CurveMode, SeatingKind } from "../physical-document.interface.js";
2
2
  import { ellipsePerimeter } from "./ellipse.js";
3
3
  import { rowSeatGeometry } from "./seating-layout.js";
4
4
  export var CurveWarningKind;
@@ -13,8 +13,7 @@ export function curveWarnings(recipe, counts, size, slots) {
13
13
  for (let row = 0; row < counts.length; row++) {
14
14
  const count = counts[row], b = recipe.innerRadiusM + row * recipe.rowPitchM, a = recipe.innerRadiusM * (recipe.axisRatio ?? 1) + row * recipe.rowPitchM;
15
15
  if (recipe.placement.kind === CurveMode.Pitch &&
16
- (count - 1) * recipe.placement.seatPitchM + size.width >
17
- ellipsePerimeter(a, b)) {
16
+ (count - 1) * recipe.placement.seatPitchM + size.width > ellipsePerimeter(a, b)) {
18
17
  warnings.push({
19
18
  kind: CurveWarningKind.Overrun,
20
19
  row,
@@ -30,8 +29,7 @@ export function curveWarnings(recipe, counts, size, slots) {
30
29
  }, seatSize = slot?.override?.sizeM ?? size;
31
30
  if (previous &&
32
31
  Math.hypot(point.x - previous.point.x, point.y - previous.point.y) <
33
- Math.min(previous.size.width + seatSize.width, previous.size.height + seatSize.height) /
34
- 2) {
32
+ Math.min(previous.size.width + seatSize.width, previous.size.height + seatSize.height) / 2) {
35
33
  warnings.push({
36
34
  kind: CurveWarningKind.Clearance,
37
35
  row,
@@ -0,0 +1,4 @@
1
+ import { type Decoration } from "../physical-document.interface.js";
2
+ import { type Bounds, type Matrix } from "./geometry.js";
3
+ /** World bounds of the physical artwork, independent of editor selection and section ownership. */
4
+ export declare function decorationBounds(decoration: Decoration, matrix: Matrix): Bounds;
@@ -0,0 +1,42 @@
1
+ import { polygonContour } from "./polygon-curves.js";
2
+ import { DecorationKind, LabelAlignment } from "../physical-document.interface.js";
3
+ import { pointsBounds, project } from "./geometry.js";
4
+ /** World bounds of the physical artwork, independent of editor selection and section ownership. */
5
+ export function decorationBounds(decoration, matrix) {
6
+ let points;
7
+ switch (decoration.kind) {
8
+ case DecorationKind.Line:
9
+ points = decoration.pointsM;
10
+ break;
11
+ case DecorationKind.Polygon:
12
+ points = polygonContour(decoration.boundary).outer;
13
+ break;
14
+ case DecorationKind.Text: {
15
+ const width = Math.max(decoration.fontSizeM, Array.from(decoration.text).length * decoration.fontSizeM * 0.65);
16
+ let start = -width / 2;
17
+ if (decoration.align === LabelAlignment.Left)
18
+ start = 0;
19
+ else if (decoration.align === LabelAlignment.Right)
20
+ start = -width;
21
+ points = rectanglePoints(width, decoration.fontSizeM).map((point) => ({
22
+ x: point.x + start + width / 2,
23
+ y: point.y,
24
+ }));
25
+ break;
26
+ }
27
+ case DecorationKind.Circle:
28
+ points = rectanglePoints(decoration.radiusM * 2, decoration.radiusM * 2);
29
+ break;
30
+ default:
31
+ points = rectanglePoints(decoration.sizeM.width, decoration.sizeM.height);
32
+ }
33
+ return pointsBounds(points.map((point) => project(matrix, point)));
34
+ }
35
+ function rectanglePoints(width, height) {
36
+ return [
37
+ { x: -width / 2, y: -height / 2 },
38
+ { x: width / 2, y: -height / 2 },
39
+ { x: width / 2, y: height / 2 },
40
+ { x: -width / 2, y: height / 2 },
41
+ ];
42
+ }
@@ -21,11 +21,7 @@ function table(a, b) {
21
21
  for (let i = 1; i <= count; i++) {
22
22
  const start = (tau * (i - 1)) / count, end = (tau * i) / count;
23
23
  angles[i] = end;
24
- lengths[i] =
25
- lengths[i - 1] +
26
- ((end - start) *
27
- (speed(start) + 4 * speed((start + end) / 2) + speed(end))) /
28
- 6;
24
+ lengths[i] = lengths[i - 1] + ((end - start) * (speed(start) + 4 * speed((start + end) / 2) + speed(end))) / 6;
29
25
  }
30
26
  const result = { angles, lengths, perimeter: lengths[count] };
31
27
  if (cache.size >= 128)
@@ -46,23 +42,19 @@ function interval(keys, value) {
46
42
  }
47
43
  function partial(a, b, start, end) {
48
44
  const speed = (t) => Math.hypot(a * Math.sin(t), b * Math.cos(t));
49
- return (((end - start) *
50
- (speed(start) + 4 * speed((start + end) / 2) + speed(end))) /
51
- 6);
45
+ return ((end - start) * (speed(start) + 4 * speed((start + end) / 2) + speed(end))) / 6;
52
46
  }
53
47
  export function ellipseArcLength(a, b, angle) {
54
48
  if (a === b)
55
49
  return a * angle;
56
50
  const t = table(a, b), turns = Math.floor(angle / tau), within = angle - turns * tau, i = interval(t.angles, within);
57
- return (turns * t.perimeter + t.lengths[i] + partial(a, b, t.angles[i], within));
51
+ return turns * t.perimeter + t.lengths[i] + partial(a, b, t.angles[i], within);
58
52
  }
59
53
  export function ellipseAngleAtDistance(a, b, center, distance) {
60
54
  if (a === b)
61
55
  return center + distance / a;
62
56
  const t = table(a, b), length = ellipseArcLength(a, b, center) + distance, turns = Math.floor(length / t.perimeter), within = length - turns * t.perimeter, i = interval(t.lengths, within);
63
- let angle = t.angles[i] +
64
- ((within - t.lengths[i]) / (t.lengths[i + 1] - t.lengths[i])) *
65
- (t.angles[i + 1] - t.angles[i]);
57
+ let angle = t.angles[i] + ((within - t.lengths[i]) / (t.lengths[i + 1] - t.lengths[i])) * (t.angles[i + 1] - t.angles[i]);
66
58
  for (let n = 0; n < 5; n++) {
67
59
  const error = t.lengths[i] + partial(a, b, t.angles[i], angle) - within;
68
60
  angle = Math.max(t.angles[i], Math.min(t.angles[i + 1], angle - error / Math.hypot(a * Math.sin(angle), b * Math.cos(angle))));
@@ -1,4 +1,4 @@
1
- import { type PhysicalDocumentV1, type PointM, type PolygonM, type SeatingGroup, type SeatSlot, type SizeM, type Transform, type UUID, type LabelSequence } from "../types.js";
1
+ import { type PhysicalDocumentV1, type PointM, type PolygonM, type SeatingGroup, type SeatSlot, type SizeM, type Transform, type UUID, type LabelSequence } from "../physical-document.interface.js";
2
2
  export type Matrix = {
3
3
  a: number;
4
4
  b: number;
@@ -8,14 +8,19 @@ export type Matrix = {
8
8
  ty: number;
9
9
  };
10
10
  import { type Bounds } from "./primitives.js";
11
- export { containsPoint, emptyBounds, extend, intersects, pointsBounds, type Bounds, } from "./primitives.js";
11
+ export { containsPoint, emptyBounds, extend, intersects, pointsBounds, type Bounds } from "./primitives.js";
12
12
  export type GeneratedSeat = {
13
13
  id: UUID;
14
14
  groupId: UUID;
15
15
  rowId: UUID | null;
16
- sectionId: UUID | null;
17
16
  label: string;
17
+ /** Canonical sequence label, independent of an authored display override. */
18
+ bookingLabel: string;
19
+ /** A table chair’s display number without its optional table name. */
20
+ chairNumber?: string;
21
+ buyerNoun?: string;
18
22
  ownerLabel: string;
23
+ addressRowLabel?: string;
19
24
  logicalRowLabel?: string;
20
25
  logicalRowId?: UUID;
21
26
  logicalPartIndex?: number;
@@ -37,6 +42,7 @@ export declare function project(m: Matrix, p: PointM): PointM;
37
42
  /** Table bodies remain part of drawable bounds even with chairs on one side. */
38
43
  export declare function tableBodyBounds(group: SeatingGroup, matrix: Matrix): Bounds | null;
39
44
  export declare function worldMatrices(document: PhysicalDocumentV1): Map<UUID, Matrix>;
45
+ export declare function generatedSeats(group: SeatingGroup): readonly GeneratedSeat[];
40
46
  export declare function generateGroup(group: SeatingGroup): Generator<GeneratedSeat>;
41
47
  export declare function footprint(seat: GeneratedSeat, world?: Matrix): PointM[];
42
48
  export declare function footprintInside(points: PointM[], polygon: PolygonM): boolean;
@@ -1,9 +1,10 @@
1
- import { rowSeatGeometry, roundChairGeometry, rectangularChairGeometry, TableSide, } from "./seating-layout.js";
2
- import { SeatingKind, TableChairDistribution, RowEnds, } from "../types.js";
3
- import { sequenceLabel } from "../labels.js";
1
+ import { polygonContour } from "./polygon-curves.js";
2
+ import { rowPlacementOffset, rowSeatGeometry, roundChairGeometry, rectangularChairGeometry, rectangularChairOrder, } from "./seating-layout.js";
3
+ import { NumberingScheme, TableChairNumberFormat, SeatingKind, RowEnds, } from "../physical-document.interface.js";
4
+ import { inventoryName, sequenceLabel, rowDisplayLabel } from "../labels.js";
4
5
  import { seatCategoryId } from "../categories.js";
5
- import { containsPoint, intersects, pointsBounds, } from "./primitives.js";
6
- export { containsPoint, emptyBounds, extend, intersects, pointsBounds, } from "./primitives.js";
6
+ import { containsPoint, intersects, pointsBounds } from "./primitives.js";
7
+ export { containsPoint, emptyBounds, extend, intersects, pointsBounds } from "./primitives.js";
7
8
  import { prepareBoundary, footprintInBoundary } from "./boundary.js";
8
9
  export const identityMatrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
9
10
  export const radians = (value) => (value * Math.PI) / 180;
@@ -81,21 +82,26 @@ export function worldMatrices(document) {
81
82
  };
82
83
  for (const c of document.collections)
83
84
  resolve(c.id);
84
- for (const entity of [
85
- ...document.seatingGroups,
86
- ...document.areas,
87
- ...document.decorations,
88
- ])
85
+ for (const entity of [...document.seatingGroups, ...document.areas, ...document.decorations])
89
86
  result.set(entity.id, multiply(entity.parentId ? resolve(entity.parentId) : identityMatrix, transformMatrix(entity.transform)));
90
87
  return result;
91
88
  }
89
+ const generated = new WeakMap();
90
+ export function generatedSeats(group) {
91
+ let cached = generated.get(group);
92
+ if (!cached) {
93
+ cached = Object.freeze([...generateGroup(group)]);
94
+ generated.set(group, cached);
95
+ }
96
+ return cached;
97
+ }
92
98
  export function* generateGroup(group) {
93
99
  const emit = (slot, p, rotationDeg, label, ownerLabel, rowId, aisle = false, categoryId = seatCategoryId(group, slot)) => ({
94
100
  id: slot.id,
95
101
  groupId: group.id,
96
102
  rowId,
97
- sectionId: group.sectionId,
98
103
  label: slot.labelOverride ?? label,
104
+ bookingLabel: label,
99
105
  ownerLabel,
100
106
  position: {
101
107
  x: p.x + (slot.override?.offsetM?.x ?? 0),
@@ -107,45 +113,65 @@ export function* generateGroup(group) {
107
113
  aisle,
108
114
  categoryId,
109
115
  });
110
- if (group.kind === SeatingKind.Straight ||
111
- group.kind === SeatingKind.Curved) {
116
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
112
117
  const longestRow = group.rows.reduce((max, row) => Math.max(max, row.seats.length), 0);
113
118
  for (let r = 0; r < group.rows.length; r++) {
114
119
  const row = group.rows[r];
115
- const owner = row.labelOverride ??
116
- sequenceLabel(group.labels.rows, r, group.rows.length);
120
+ const owner = rowDisplayLabel(group, r);
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
+ }
117
131
  for (let i = 0; i < row.seats.length; i++) {
118
132
  const geometry = rowSeatGeometry(group, r, i, row.seats.length, longestRow, row.layout);
119
- let p = geometry.position;
133
+ const p = { x: geometry.position.x + offset.x, y: geometry.position.y + offset.y };
120
134
  const rotation = geometry.rotationDeg;
121
- p = { x: p.x + (row.offsetM?.x ?? 0), y: p.y + (row.offsetM?.y ?? 0) };
122
- const seat = emit(row.seats[i], p, rotation, sequenceLabel(row.seatSequenceOverride ?? group.labels.seats, i, row.seats.length), owner, row.id, (i === 0 &&
123
- (row.aisleSeats === RowEnds.Start ||
124
- row.aisleSeats === RowEnds.Both)) ||
125
- (i === row.seats.length - 1 &&
126
- (row.aisleSeats === RowEnds.End ||
127
- 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), group.labels.table, 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), group.labels.table, null);
174
+ yield emitChair(list[i], geometry.position, geometry.rotationDeg, ordinal++, total);
149
175
  }
150
176
  }
151
177
  }
@@ -164,8 +190,7 @@ export function footprint(seat, world = identityMatrix) {
164
190
  }
165
191
  function crosses(a, b, c, d) {
166
192
  const side = (p, q, r) => (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x);
167
- return (side(a, b, c) * side(a, b, d) < -1e-12 &&
168
- side(c, d, a) * side(c, d, b) < -1e-12);
193
+ return side(a, b, c) * side(a, b, d) < -1e-12 && side(c, d, a) * side(c, d, b) < -1e-12;
169
194
  }
170
195
  export function footprintInside(points, polygon) {
171
196
  return footprintInBoundary(prepareBoundary(polygon), points);
@@ -175,7 +200,7 @@ export function invalidPolygon(polygon) {
175
200
  const cached = polygonValidity.get(polygon);
176
201
  if (cached !== undefined)
177
202
  return cached;
178
- const result = calculateInvalidPolygon(polygon);
203
+ const result = calculateInvalidPolygon(polygonContour(polygon));
179
204
  polygonValidity.set(polygon, result);
180
205
  return result;
181
206
  }
@@ -202,8 +227,7 @@ function calculateInvalidPolygon(polygon) {
202
227
  for (let i = 0; i < edges.length; i++)
203
228
  for (let j = i + 1; j < edges.length && edges[j].bounds.minX <= edges[i].bounds.maxX; j++) {
204
229
  const a = edges[i], b = edges[j];
205
- if (Math.abs(a.index - b.index) === 1 ||
206
- Math.abs(a.index - b.index) === ring.length - 1)
230
+ if (Math.abs(a.index - b.index) === 1 || Math.abs(a.index - b.index) === ring.length - 1)
207
231
  continue;
208
232
  if (intersects(a.bounds, b.bounds) &&
209
233
  (crosses(a.a, a.b, b.a, b.b) ||
@@ -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
+ }
@@ -0,0 +1,10 @@
1
+ import { type PhysicalDocumentV1, type PointM, type PolygonM, type SeatSlot, type SeatingGroup, type Transform, type UUID } from "../physical-document.interface.js";
2
+ import { type Matrix } from "./geometry.js";
3
+ import type { LayoutTransformScope } from "./layout-transform.interface.js";
4
+ /** Ordinary complete row banks share a transform; generated rows retain manual geometry edits. */
5
+ export declare function compactRowTargets(doc: PhysicalDocumentV1, ids: Iterable<UUID>): Set<UUID>;
6
+ export declare function transformFromMatrix(m: Matrix): Transform;
7
+ export declare function sectionOutlinePivot(outline: PolygonM): PointM;
8
+ /** Apply the prepared scope to the same world geometry used by the editor preview. */
9
+ export declare function transformLayout(doc: PhysicalDocumentV1, scope: LayoutTransformScope, delta: PointM, angle: number): PhysicalDocumentV1;
10
+ export declare function mapSeats(group: SeatingGroup, change: (s: SeatSlot) => SeatSlot): SeatingGroup;
@@ -0,0 +1,6 @@
1
+ import type { PointM, UUID } from "../physical-document.interface.js";
2
+ export interface LayoutTransformScope {
3
+ objects: readonly UUID[];
4
+ sections: readonly UUID[];
5
+ pivot: PointM;
6
+ }
@@ -0,0 +1 @@
1
+ export {};