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

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 (107) hide show
  1. package/dist/arc-fan-rebuild.d.ts +13 -0
  2. package/dist/arc-fan-rebuild.js +163 -0
  3. package/dist/arc-fan.d.ts +27 -0
  4. package/dist/arc-fan.interface.d.ts +83 -0
  5. package/dist/arc-fan.interface.js +30 -0
  6. package/dist/arc-fan.js +182 -0
  7. package/dist/catalog.d.ts +6 -4
  8. package/dist/catalog.js +31 -17
  9. package/dist/categories.d.ts +5 -3
  10. package/dist/categories.js +104 -25
  11. package/dist/editor-state.d.ts +4 -1
  12. package/dist/editor-state.js +53 -30
  13. package/dist/floors.d.ts +22 -0
  14. package/dist/floors.js +77 -0
  15. package/dist/geometry/boundary.d.ts +1 -1
  16. package/dist/geometry/boundary.js +16 -12
  17. package/dist/geometry/curve-warnings.d.ts +1 -1
  18. package/dist/geometry/curve-warnings.js +3 -5
  19. package/dist/geometry/decoration-bounds.d.ts +4 -0
  20. package/dist/geometry/decoration-bounds.js +42 -0
  21. package/dist/geometry/ellipse.js +4 -12
  22. package/dist/geometry/geometry.d.ts +6 -3
  23. package/dist/geometry/geometry.js +28 -30
  24. package/dist/geometry/layout-transform.d.ts +10 -0
  25. package/dist/geometry/layout-transform.interface.d.ts +6 -0
  26. package/dist/geometry/layout-transform.interface.js +1 -0
  27. package/dist/geometry/layout-transform.js +206 -0
  28. package/dist/geometry/polygon-curves.d.ts +17 -0
  29. package/dist/geometry/polygon-curves.interface.d.ts +21 -0
  30. package/dist/geometry/polygon-curves.interface.js +5 -0
  31. package/dist/geometry/polygon-curves.js +169 -0
  32. package/dist/geometry/primitives.d.ts +1 -1
  33. package/dist/geometry/primitives.js +2 -3
  34. package/dist/geometry/seat-shape.d.ts +1 -1
  35. package/dist/geometry/seat-shape.js +1 -1
  36. package/dist/geometry/seating-layout.d.ts +9 -1
  37. package/dist/geometry/seating-layout.js +66 -57
  38. package/dist/geometry/units.d.ts +8 -0
  39. package/dist/geometry/units.js +13 -0
  40. package/dist/geometry/venue-outline.d.ts +4 -18
  41. package/dist/geometry/venue-outline.interface.d.ts +23 -0
  42. package/dist/geometry/venue-outline.interface.js +7 -0
  43. package/dist/geometry/venue-outline.js +107 -49
  44. package/dist/identity.d.ts +3 -1
  45. package/dist/identity.js +32 -17
  46. package/dist/issues.d.ts +15 -2
  47. package/dist/issues.js +16 -6
  48. package/dist/labels.d.ts +6 -1
  49. package/dist/labels.js +20 -18
  50. package/dist/layers.d.ts +26 -0
  51. package/dist/layers.js +86 -0
  52. package/dist/media.d.ts +27 -0
  53. package/dist/media.js +89 -0
  54. package/dist/{types.d.ts → physical-document.interface.d.ts} +117 -4
  55. package/dist/{types.js → physical-document.interface.js} +17 -0
  56. package/dist/preview.d.ts +1 -1
  57. package/dist/preview.js +39 -29
  58. package/dist/reference.js +1 -1
  59. package/dist/row-segments.d.ts +5 -1
  60. package/dist/row-segments.js +10 -9
  61. package/dist/schema.d.ts +591 -14
  62. package/dist/schema.js +238 -102
  63. package/dist/seat-proximity.d.ts +4 -0
  64. package/dist/seat-proximity.js +119 -0
  65. package/dist/section-elevation.d.ts +5 -0
  66. package/dist/section-elevation.interface.d.ts +26 -0
  67. package/dist/section-elevation.interface.js +8 -0
  68. package/dist/section-elevation.js +53 -0
  69. package/dist/section-fill-rebuild.d.ts +10 -0
  70. package/dist/section-fill-rebuild.js +64 -0
  71. package/dist/section-fill.d.ts +84 -0
  72. package/dist/section-fill.interface.d.ts +94 -0
  73. package/dist/section-fill.interface.js +22 -0
  74. package/dist/section-fill.js +306 -0
  75. package/dist/section-growth.d.ts +11 -0
  76. package/dist/section-growth.interface.d.ts +12 -0
  77. package/dist/section-growth.interface.js +1 -0
  78. package/dist/section-growth.js +198 -0
  79. package/dist/section-layout.d.ts +95 -0
  80. package/dist/section-layout.interface.d.ts +8 -0
  81. package/dist/section-layout.interface.js +5 -0
  82. package/dist/section-layout.js +70 -0
  83. package/dist/section-outline-refit.d.ts +8 -0
  84. package/dist/section-outline-refit.js +246 -0
  85. package/dist/section-refit.d.ts +22 -0
  86. package/dist/section-refit.interface.d.ts +49 -0
  87. package/dist/section-refit.interface.js +6 -0
  88. package/dist/section-refit.js +179 -0
  89. package/dist/section-scale.d.ts +2 -0
  90. package/dist/section-scale.js +128 -0
  91. package/dist/sections.d.ts +23 -0
  92. package/dist/sections.js +144 -0
  93. package/dist/selling.d.ts +1 -1
  94. package/dist/selling.js +11 -26
  95. package/dist/spacing-repairs.d.ts +31 -0
  96. package/dist/spacing-repairs.js +168 -0
  97. package/dist/table-layout.d.ts +1 -2
  98. package/dist/table-layout.js +14 -22
  99. package/dist/validation.d.ts +7 -2
  100. package/dist/validation.interface.d.ts +20 -0
  101. package/dist/validation.interface.js +9 -0
  102. package/dist/validation.js +221 -85
  103. package/dist/wayfinding.d.ts +10 -0
  104. package/dist/wayfinding.interface.d.ts +52 -0
  105. package/dist/wayfinding.interface.js +28 -0
  106. package/dist/wayfinding.js +63 -0
  107. package/package.json +89 -4
@@ -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,16 @@ 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;
18
19
  ownerLabel: string;
20
+ addressRowLabel?: string;
19
21
  logicalRowLabel?: string;
20
22
  logicalRowId?: UUID;
21
23
  logicalPartIndex?: number;
@@ -37,6 +39,7 @@ export declare function project(m: Matrix, p: PointM): PointM;
37
39
  /** Table bodies remain part of drawable bounds even with chairs on one side. */
38
40
  export declare function tableBodyBounds(group: SeatingGroup, matrix: Matrix): Bounds | null;
39
41
  export declare function worldMatrices(document: PhysicalDocumentV1): Map<UUID, Matrix>;
42
+ export declare function generatedSeats(group: SeatingGroup): readonly GeneratedSeat[];
40
43
  export declare function generateGroup(group: SeatingGroup): Generator<GeneratedSeat>;
41
44
  export declare function footprint(seat: GeneratedSeat, world?: Matrix): PointM[];
42
45
  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, TableSide, } from "./seating-layout.js";
3
+ import { SeatingKind, TableChairDistribution, 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,24 +113,18 @@ 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);
117
122
  for (let i = 0; i < row.seats.length; i++) {
118
123
  const geometry = rowSeatGeometry(group, r, i, row.seats.length, longestRow, row.layout);
119
- let p = geometry.position;
124
+ const p = { x: geometry.position.x + offset.x, y: geometry.position.y + offset.y };
120
125
  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));
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));
128
128
  yield seat;
129
129
  }
130
130
  }
@@ -132,7 +132,7 @@ export function* generateGroup(group) {
132
132
  else if (group.kind === SeatingKind.Round) {
133
133
  for (let i = 0; i < group.chairs.length; i++) {
134
134
  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);
135
+ yield emit(group.chairs[i], geometry.position, geometry.rotationDeg, sequenceLabel(group.labels.chairs, i, group.chairs.length), inventoryName(group.labels), null);
136
136
  }
137
137
  }
138
138
  else {
@@ -145,7 +145,7 @@ export function* generateGroup(group) {
145
145
  const list = group.chairsBySide[side];
146
146
  for (let i = 0; i < list.length; i++) {
147
147
  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);
148
+ yield emit(list[i], geometry.position, geometry.rotationDeg, sequenceLabel(group.labels.chairs, ordinal++, total), inventoryName(group.labels), null);
149
149
  }
150
150
  }
151
151
  }
@@ -164,8 +164,7 @@ export function footprint(seat, world = identityMatrix) {
164
164
  }
165
165
  function crosses(a, b, c, d) {
166
166
  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);
167
+ return side(a, b, c) * side(a, b, d) < -1e-12 && side(c, d, a) * side(c, d, b) < -1e-12;
169
168
  }
170
169
  export function footprintInside(points, polygon) {
171
170
  return footprintInBoundary(prepareBoundary(polygon), points);
@@ -175,7 +174,7 @@ export function invalidPolygon(polygon) {
175
174
  const cached = polygonValidity.get(polygon);
176
175
  if (cached !== undefined)
177
176
  return cached;
178
- const result = calculateInvalidPolygon(polygon);
177
+ const result = calculateInvalidPolygon(polygonContour(polygon));
179
178
  polygonValidity.set(polygon, result);
180
179
  return result;
181
180
  }
@@ -202,8 +201,7 @@ function calculateInvalidPolygon(polygon) {
202
201
  for (let i = 0; i < edges.length; i++)
203
202
  for (let j = i + 1; j < edges.length && edges[j].bounds.minX <= edges[i].bounds.maxX; j++) {
204
203
  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)
204
+ if (Math.abs(a.index - b.index) === 1 || Math.abs(a.index - b.index) === ring.length - 1)
207
205
  continue;
208
206
  if (intersects(a.bounds, b.bounds) &&
209
207
  (crosses(a.a, a.b, b.a, b.b) ||
@@ -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 {};
@@ -0,0 +1,206 @@
1
+ import { rowPlacementOffset } from "./seating-layout.js";
2
+ import { documentCatalog } from "../catalog.js";
3
+ import { SeatingKind, } from "../physical-document.interface.js";
4
+ import { identityMatrix, inverse, multiply, normalizeAngle, project, radians, worldMatrices, } from "./geometry.js";
5
+ /** Ordinary complete row banks share a transform; generated rows retain manual geometry edits. */
6
+ export function compactRowTargets(doc, ids) {
7
+ const targets = new Set(ids);
8
+ const catalog = documentCatalog(doc);
9
+ const rowsByGroup = new Map();
10
+ for (const id of targets) {
11
+ const group = catalog.rows.get(id);
12
+ if (!group)
13
+ continue;
14
+ const rows = rowsByGroup.get(group.id) ?? [];
15
+ rows.push(id);
16
+ rowsByGroup.set(group.id, rows);
17
+ }
18
+ for (const [groupId, rows] of rowsByGroup) {
19
+ const group = catalog.groups.get(groupId);
20
+ if (!("rows" in group) || group.arcFan || rows.length !== group.rows.length)
21
+ continue;
22
+ for (const id of rows)
23
+ targets.delete(id);
24
+ targets.add(groupId);
25
+ }
26
+ return targets;
27
+ }
28
+ export function transformFromMatrix(m) {
29
+ const flipped = m.a * m.d - m.b * m.c < 0;
30
+ return {
31
+ positionM: { x: m.tx, y: m.ty },
32
+ rotationDeg: normalizeAngle((Math.atan2(m.b, m.a) * 180) / Math.PI),
33
+ flipX: false,
34
+ flipY: flipped,
35
+ };
36
+ }
37
+ export function sectionOutlinePivot(outline) {
38
+ const points = outline.outer;
39
+ return {
40
+ x: points.reduce((sum, point) => sum + point.x, 0) / points.length,
41
+ y: points.reduce((sum, point) => sum + point.y, 0) / points.length,
42
+ };
43
+ }
44
+ /** Apply the prepared scope to the same world geometry used by the editor preview. */
45
+ export function transformLayout(doc, scope, delta, angle) {
46
+ const sectionIds = new Set(scope.sections);
47
+ const targets = new Set(scope.objects);
48
+ const matrices = worldMatrices(doc);
49
+ const center = scope.pivot;
50
+ const cos = Math.cos(radians(angle));
51
+ const sin = Math.sin(radians(angle));
52
+ const rotation = {
53
+ a: cos,
54
+ b: sin,
55
+ c: -sin,
56
+ d: cos,
57
+ tx: center.x + delta.x - cos * center.x + sin * center.y,
58
+ ty: center.y + delta.y - sin * center.x - cos * center.y,
59
+ };
60
+ const moveDrawable = (entity) => {
61
+ if (!targets.has(entity.id))
62
+ return entity;
63
+ const world = matrices.get(entity.id);
64
+ return {
65
+ ...entity,
66
+ transform: transformFromMatrix(multiply(entity.parentId ? inverse(matrices.get(entity.parentId)) : identityMatrix, multiply(rotation, world))),
67
+ };
68
+ };
69
+ const movePoint = (p) => ({
70
+ x: center.x + delta.x + cos * (p.x - center.x) - sin * (p.y - center.y),
71
+ y: center.y + delta.y + sin * (p.x - center.x) + cos * (p.y - center.y),
72
+ });
73
+ const result = {
74
+ ...doc,
75
+ collections: doc.collections.map(moveDrawable),
76
+ seatingGroups: doc.seatingGroups.map(moveDrawable),
77
+ areas: doc.areas.map(moveDrawable),
78
+ decorations: doc.decorations.map(moveDrawable),
79
+ sections: doc.sections.map((s) => sectionIds.has(s.id)
80
+ ? {
81
+ ...s,
82
+ ...(s.outline
83
+ ? {
84
+ outline: {
85
+ ...s.outline,
86
+ outer: s.outline.outer.map(movePoint),
87
+ holes: s.outline.holes.map((h) => h.map(movePoint)),
88
+ },
89
+ }
90
+ : {}),
91
+ ...(s.labelPlacement
92
+ ? {
93
+ labelPlacement: {
94
+ ...s.labelPlacement,
95
+ positionM: movePoint(s.labelPlacement.positionM),
96
+ rotationDeg: normalizeAngle(s.labelPlacement.rotationDeg + angle),
97
+ },
98
+ }
99
+ : {}),
100
+ }
101
+ : s),
102
+ };
103
+ const catalog = documentCatalog(doc);
104
+ const physical = new Set([...targets].flatMap((id) => {
105
+ if (catalog.seats.has(id))
106
+ return [id];
107
+ const group = catalog.rows.get(id);
108
+ return group && (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved)
109
+ ? (group.rows.find((row) => row.id === id)?.seats.map((seat) => seat.id) ?? [])
110
+ : [];
111
+ })), affectedGroups = new Set([...physical].map((id) => catalog.seats.get(id).group.id));
112
+ if (!physical.size)
113
+ return result;
114
+ return {
115
+ ...result,
116
+ seatingGroups: result.seatingGroups.map((group) => {
117
+ if (!affectedGroups.has(group.id))
118
+ return group;
119
+ const m = matrices.get(group.id);
120
+ const movedRowSeats = new Set();
121
+ const movedRows = new Map();
122
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
123
+ for (const [index, row] of group.rows.entries()) {
124
+ if (!targets.has(row.id) || (angle !== 0 && !row.layout))
125
+ continue;
126
+ for (const slot of row.seats)
127
+ movedRowSeats.add(slot.id);
128
+ if (angle === 0) {
129
+ const offset = row.offsetM ?? { x: 0, y: 0 };
130
+ const origin = project(inverse(m), project(rotation, project(m, offset)));
131
+ movedRows.set(row.id, { ...row, offsetM: origin });
132
+ continue;
133
+ }
134
+ const offset = rowPlacementOffset(group, index, row.offsetM);
135
+ const layout = row.layout;
136
+ const origin = project(inverse(m), project(rotation, project(m, {
137
+ x: layout.originM.x + offset.x,
138
+ y: layout.originM.y + offset.y,
139
+ })));
140
+ const localRotation = multiply(inverse(m), multiply(rotation, m));
141
+ const rotateOffset = (point) => ({
142
+ x: localRotation.a * point.x + localRotation.c * point.y,
143
+ y: localRotation.b * point.x + localRotation.d * point.y,
144
+ });
145
+ movedRows.set(row.id, {
146
+ ...row,
147
+ layout: {
148
+ ...layout,
149
+ originM: { x: origin.x - offset.x, y: origin.y - offset.y },
150
+ rotationDeg: normalizeAngle(layout.rotationDeg + angle * (m.a * m.d - m.b * m.c < 0 ? -1 : 1)),
151
+ },
152
+ seats: row.seats.map((slot) => slot.override?.offsetM
153
+ ? {
154
+ ...slot,
155
+ override: {
156
+ ...slot.override,
157
+ offsetM: rotateOffset(slot.override.offsetM),
158
+ },
159
+ }
160
+ : slot),
161
+ });
162
+ }
163
+ }
164
+ const movedSeats = mapSeats(group, (slot) => {
165
+ if (!physical.has(slot.id) || movedRowSeats.has(slot.id))
166
+ return slot;
167
+ const seat = catalog.seats.get(slot.id).seat, world = project(m, seat.position), local = project(inverse(m), project(rotation, world));
168
+ return {
169
+ ...slot,
170
+ override: {
171
+ ...slot.override,
172
+ offsetM: {
173
+ x: (slot.override?.offsetM?.x ?? 0) + local.x - seat.position.x,
174
+ y: (slot.override?.offsetM?.y ?? 0) + local.y - seat.position.y,
175
+ },
176
+ rotationDeltaDeg: normalizeAngle((slot.override?.rotationDeltaDeg ?? 0) + angle * (m.a * m.d - m.b * m.c < 0 ? -1 : 1)),
177
+ },
178
+ };
179
+ });
180
+ if (!movedRows.size || (movedSeats.kind !== SeatingKind.Straight && movedSeats.kind !== SeatingKind.Curved))
181
+ return movedSeats;
182
+ return {
183
+ ...movedSeats,
184
+ rows: movedSeats.rows.map((row) => movedRows.get(row.id) ?? row),
185
+ };
186
+ }),
187
+ };
188
+ }
189
+ export function mapSeats(group, change) {
190
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved)
191
+ return {
192
+ ...group,
193
+ rows: group.rows.map((r) => ({ ...r, seats: r.seats.map(change) })),
194
+ };
195
+ if (group.kind === SeatingKind.Round)
196
+ return { ...group, chairs: group.chairs.map(change) };
197
+ return {
198
+ ...group,
199
+ chairsBySide: {
200
+ top: group.chairsBySide.top.map(change),
201
+ right: group.chairsBySide.right.map(change),
202
+ bottom: group.chairsBySide.bottom.map(change),
203
+ left: group.chairsBySide.left.map(change),
204
+ },
205
+ };
206
+ }
@@ -0,0 +1,17 @@
1
+ import type { PointM, PolygonM } from "../physical-document.interface.js";
2
+ import { type PolygonCornerFillet } from "./polygon-curves.interface.js";
3
+ export type { PolygonCornerFillet } from "./polygon-curves.interface.js";
4
+ export declare const PolygonVertexLimit = 10000;
5
+ export declare const PolygonCornerRadiusMaxM = 2.75;
6
+ /** Quadratic control lies at the chord midpoint plus its signed, dimensionless normal offset. */
7
+ export declare function sideCurvePoint(start: PointM, end: PointM, curvature: number, fraction: number): PointM;
8
+ /** Uniform quadratic subdivision bounds the chord deviation by the existing 1mm curve tolerance. */
9
+ export declare function sideCurveSegments(start: PointM, end: PointM, curvature: number): number;
10
+ /** Tangent fillets on the authored outer ring, shared by rendering and section fitting. */
11
+ export declare function polygonCornerFillets(polygon: PolygonM): readonly (PolygonCornerFillet | null)[];
12
+ /** A rounding input takes effect when at least one authored corner can use it. */
13
+ export declare function effectiveCornerRounding(polygon: PolygonM): number;
14
+ export declare function polygonContourVertexCount(polygon: PolygonM): number;
15
+ export declare function polygonCornerSamples(corner: PolygonCornerFillet, segments?: number): PointM[];
16
+ /** Authored corners remain stable; all geometric consumers share one derived, immutable contour. */
17
+ export declare function polygonContour(polygon: PolygonM): PolygonM;
@@ -0,0 +1,21 @@
1
+ import type { PointM } from "../physical-document.interface.js";
2
+ export declare enum PolygonCornerKind {
3
+ Circular = "circular",
4
+ Cubic = "cubic"
5
+ }
6
+ type PolygonCornerSpan = {
7
+ before: PointM;
8
+ after: PointM;
9
+ segments: number;
10
+ };
11
+ export type PolygonCornerFillet = PolygonCornerSpan & ({
12
+ kind: PolygonCornerKind.Circular;
13
+ center: PointM;
14
+ radius: number;
15
+ sweep: number;
16
+ } | {
17
+ kind: PolygonCornerKind.Cubic;
18
+ control1: PointM;
19
+ control2: PointM;
20
+ });
21
+ export {};
@@ -0,0 +1,5 @@
1
+ export var PolygonCornerKind;
2
+ (function (PolygonCornerKind) {
3
+ PolygonCornerKind["Circular"] = "circular";
4
+ PolygonCornerKind["Cubic"] = "cubic";
5
+ })(PolygonCornerKind || (PolygonCornerKind = {}));
@@ -0,0 +1,169 @@
1
+ import { CurveToleranceM } from "./ellipse.js";
2
+ import { PolygonCornerKind } from "./polygon-curves.interface.js";
3
+ export const PolygonVertexLimit = 10_000;
4
+ export const PolygonCornerRadiusMaxM = 2.75;
5
+ const RoundingTravelDeg = 180;
6
+ const RoundingStartDeg = 48;
7
+ const CornerTurnWeight = 1.1;
8
+ const CornerTangentWeight = 0.5523;
9
+ const fillets = new WeakMap();
10
+ const contours = new WeakMap();
11
+ /** Quadratic control lies at the chord midpoint plus its signed, dimensionless normal offset. */
12
+ export function sideCurvePoint(start, end, curvature, fraction) {
13
+ const x = end.x - start.x, y = end.y - start.y;
14
+ const bow = (2 * fraction * (1 - fraction) * curvature) / 100;
15
+ return { x: start.x + fraction * x - bow * y, y: start.y + fraction * y + bow * x };
16
+ }
17
+ /** Uniform quadratic subdivision bounds the chord deviation by the existing 1mm curve tolerance. */
18
+ export function sideCurveSegments(start, end, curvature) {
19
+ const sagitta = (Math.abs(curvature) * Math.hypot(end.x - start.x, end.y - start.y)) / 200;
20
+ return Math.max(1, Math.ceil(Math.sqrt(sagitta / CurveToleranceM)));
21
+ }
22
+ function cornerFillet(previous, point, next, strength, radiusM) {
23
+ const incomingX = point.x - previous.x;
24
+ const incomingY = point.y - previous.y;
25
+ const outgoingX = next.x - point.x;
26
+ const outgoingY = next.y - point.y;
27
+ const incomingLength = Math.hypot(incomingX, incomingY);
28
+ const outgoingLength = Math.hypot(outgoingX, outgoingY);
29
+ const sweep = Math.atan2(incomingX * outgoingY - incomingY * outgoingX, incomingX * outgoingX + incomingY * outgoingY);
30
+ if (!incomingLength || !outgoingLength || Math.abs(sweep) < 1e-9)
31
+ return null;
32
+ const halfTurn = Math.tan(Math.abs(sweep) / 2);
33
+ const halfSide = Math.min(incomingLength, outgoingLength) / 2;
34
+ const turnDeg = (Math.abs(sweep) * 180) / Math.PI;
35
+ const limitDeg = (RoundingTravelDeg * strength - RoundingStartDeg) / CornerTurnWeight;
36
+ const weight = limitDeg > turnDeg ? 1 - turnDeg / limitDeg : 0;
37
+ const trim = radiusM ? Math.min(halfSide, radiusM * halfTurn) : halfSide * strength * weight ** 2 * (3 - 2 * weight);
38
+ if (!trim)
39
+ return null;
40
+ const before = { x: point.x - (incomingX * trim) / incomingLength, y: point.y - (incomingY * trim) / incomingLength };
41
+ const after = { x: point.x + (outgoingX * trim) / outgoingLength, y: point.y + (outgoingY * trim) / outgoingLength };
42
+ if (!radiusM) {
43
+ const control1 = {
44
+ x: before.x + (point.x - before.x) * CornerTangentWeight,
45
+ y: before.y + (point.y - before.y) * CornerTangentWeight,
46
+ };
47
+ const control2 = {
48
+ x: after.x + (point.x - after.x) * CornerTangentWeight,
49
+ y: after.y + (point.y - after.y) * CornerTangentWeight,
50
+ };
51
+ // The second derivative bounds the deviation from each straight interpolation segment.
52
+ const curvature = Math.max(Math.hypot(before.x - 2 * control1.x + control2.x, before.y - 2 * control1.y + control2.y), Math.hypot(control1.x - 2 * control2.x + after.x, control1.y - 2 * control2.y + after.y));
53
+ const segments = Math.max(1, Math.ceil(Math.sqrt((3 * curvature) / (4 * CurveToleranceM))));
54
+ return { kind: PolygonCornerKind.Cubic, before, after, control1, control2, segments };
55
+ }
56
+ const radius = trim / halfTurn;
57
+ const signedRadius = Math.sign(sweep) * radius;
58
+ const center = {
59
+ x: before.x - (incomingY * signedRadius) / incomingLength,
60
+ y: before.y + (incomingX * signedRadius) / incomingLength,
61
+ };
62
+ const maxStep = 4 * Math.asin(Math.sqrt(Math.min(1, CurveToleranceM / (2 * radius))));
63
+ return {
64
+ kind: PolygonCornerKind.Circular,
65
+ before,
66
+ after,
67
+ center,
68
+ radius,
69
+ sweep,
70
+ segments: Math.max(1, Math.ceil(Math.abs(sweep) / maxStep)),
71
+ };
72
+ }
73
+ /** Tangent fillets on the authored outer ring, shared by rendering and section fitting. */
74
+ export function polygonCornerFillets(polygon) {
75
+ const cached = fillets.get(polygon);
76
+ if (cached)
77
+ return cached;
78
+ const strength = (polygon.cornerRounding ?? 0) / 100;
79
+ const radiusM = polygon.cornerRadiusM ?? 0;
80
+ const { outer } = polygon;
81
+ const corners = strength || radiusM
82
+ ? outer.map((point, index) => cornerFillet(outer[(index + outer.length - 1) % outer.length], point, outer[(index + 1) % outer.length], strength, radiusM))
83
+ : [];
84
+ fillets.set(polygon, corners);
85
+ return corners;
86
+ }
87
+ /** A rounding input takes effect when at least one authored corner can use it. */
88
+ export function effectiveCornerRounding(polygon) {
89
+ return polygon.cornerRounding && polygonCornerFillets(polygon).some(Boolean) ? polygon.cornerRounding : 0;
90
+ }
91
+ function contourSpanSegments(polygon, corners, side) {
92
+ const next = (side + 1) % polygon.outer.length;
93
+ const start = polygon.outer[side];
94
+ const end = polygon.outer[next];
95
+ const curvature = polygon.edgeCurvature?.[side] ?? 0;
96
+ const from = corners[side]?.after;
97
+ const to = corners[next]?.before;
98
+ if (!curvature && from && to && Math.hypot(to.x - from.x, to.y - from.y) < 1e-9)
99
+ return 0;
100
+ return sideCurveSegments(start, end, curvature);
101
+ }
102
+ export function polygonContourVertexCount(polygon) {
103
+ const { outer, edgeCurvature } = polygon;
104
+ if (!polygon.cornerRounding && !polygon.cornerRadiusM && !edgeCurvature)
105
+ return outer.length;
106
+ const corners = polygonCornerFillets(polygon);
107
+ return outer.reduce((total, _, side) => total + (corners[side]?.segments ?? 0) + contourSpanSegments(polygon, corners, side), 0);
108
+ }
109
+ export function polygonCornerSamples(corner, segments = corner.segments) {
110
+ const { before, after } = corner;
111
+ if (corner.kind === PolygonCornerKind.Circular) {
112
+ const { center, radius, sweep } = corner;
113
+ const startAngle = Math.atan2(before.y - center.y, before.x - center.x);
114
+ return Array.from({ length: segments }, (_, index) => {
115
+ if (index === 0)
116
+ return before;
117
+ const angle = startAngle + (sweep * index) / segments;
118
+ return { x: center.x + radius * Math.cos(angle), y: center.y + radius * Math.sin(angle) };
119
+ });
120
+ }
121
+ const { control1, control2 } = corner;
122
+ return Array.from({ length: segments }, (_, index) => {
123
+ const t = index / segments;
124
+ const u = 1 - t;
125
+ const first = 3 * u ** 2 * t;
126
+ const second = 3 * u * t ** 2;
127
+ return {
128
+ x: u ** 3 * before.x + first * control1.x + second * control2.x + t ** 3 * after.x,
129
+ y: u ** 3 * before.y + first * control1.y + second * control2.y + t ** 3 * after.y,
130
+ };
131
+ });
132
+ }
133
+ /** Authored corners remain stable; all geometric consumers share one derived, immutable contour. */
134
+ export function polygonContour(polygon) {
135
+ const curved = polygon.edgeCurvature?.some((value) => value !== 0);
136
+ if (!polygon.cornerRounding && !polygon.cornerRadiusM && !curved)
137
+ return polygon;
138
+ const cached = contours.get(polygon);
139
+ if (cached)
140
+ return cached;
141
+ const corners = polygonCornerFillets(polygon);
142
+ if (!curved && !corners.some(Boolean))
143
+ return polygon;
144
+ if (polygonContourVertexCount(polygon) > PolygonVertexLimit)
145
+ throw new RangeError("The boundary exceeds the 1mm / 10,000-vertex curve limit.");
146
+ const outer = polygon.outer.flatMap((start, side) => {
147
+ const next = (side + 1) % polygon.outer.length;
148
+ const end = polygon.outer[next];
149
+ const corner = corners[side];
150
+ const trimmedStart = corner?.after ?? start;
151
+ const trimmedEnd = corners[next]?.before ?? end;
152
+ const arc = corner ? polygonCornerSamples(corner) : [];
153
+ const curvature = polygon.edgeCurvature?.[side] ?? 0;
154
+ const segments = contourSpanSegments(polygon, corners, side);
155
+ const span = Array.from({ length: segments }, (_, index) => {
156
+ const t = index / segments;
157
+ const point = sideCurvePoint(start, end, curvature, t);
158
+ // Trim the span without changing the authored side's bow vector.
159
+ return {
160
+ x: point.x + (1 - t) * (trimmedStart.x - start.x) + t * (trimmedEnd.x - end.x),
161
+ y: point.y + (1 - t) * (trimmedStart.y - start.y) + t * (trimmedEnd.y - end.y),
162
+ };
163
+ });
164
+ return [...arc, ...span];
165
+ });
166
+ const contour = { outer, holes: polygon.holes };
167
+ contours.set(polygon, contour);
168
+ return contour;
169
+ }
@@ -1,4 +1,4 @@
1
- import type { PointM } from "../types.js";
1
+ import type { PointM } from "../physical-document.interface.js";
2
2
  export type Bounds = {
3
3
  minX: number;
4
4
  minY: number;