@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,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;
@@ -8,7 +8,7 @@ export function extend(bounds, p) {
8
8
  bounds.maxY = Math.max(bounds.maxY, p.y);
9
9
  }
10
10
  export function intersects(a, b) {
11
- return (a.minX <= b.maxX && a.maxX >= b.minX && a.minY <= b.maxY && a.maxY >= b.minY);
11
+ return a.minX <= b.maxX && a.maxX >= b.minX && a.minY <= b.maxY && a.maxY >= b.minY;
12
12
  }
13
13
  export function pointsBounds(points) {
14
14
  const b = emptyBounds();
@@ -27,8 +27,7 @@ export function containsPoint(ring, p) {
27
27
  p.y >= Math.min(a.y, b.y) - 1e-6 &&
28
28
  p.y <= Math.max(a.y, b.y) + 1e-6)
29
29
  return true;
30
- if (a.y > p.y !== b.y > p.y &&
31
- p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x)
30
+ if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x)
32
31
  inside = !inside;
33
32
  }
34
33
  return inside;
@@ -1,4 +1,4 @@
1
- import { SeatShape } from "../types.js";
1
+ import { SeatShape } from "../physical-document.interface.js";
2
2
  export declare enum SeatShapePartKind {
3
3
  Rectangle = "rectangle",
4
4
  Polygon = "polygon"
@@ -1,4 +1,4 @@
1
- import { SeatShape } from "../types.js";
1
+ import { SeatShape } from "../physical-document.interface.js";
2
2
  export var SeatShapePartKind;
3
3
  (function (SeatShapePartKind) {
4
4
  SeatShapePartKind["Rectangle"] = "rectangle";
@@ -32,10 +32,10 @@ const furniture = {
32
32
  polygon(0.08, 0.08, 0.19, 0.08, 0.3, 0.42, 0.19, 0.42),
33
33
  ],
34
34
  [SeatShape.Folding]: [
35
- polygon(-0.3, -0.42, 0.3, -0.42, 0.25, -0.2, -0.25, -0.2),
36
- polygon(-0.315, -0.14, 0.315, -0.14, 0.26, 0.02, -0.26, 0.02),
37
- polygon(-0.2, 0.0, -0.1, -0.02, 0.2, 0.42, 0.08, 0.42),
38
- polygon(0.1, -0.02, 0.2, 0.0, -0.08, 0.42, -0.2, 0.42),
35
+ polygon(-0.3, -0.44, 0.3, -0.44, 0.25, -0.2, -0.25, -0.2),
36
+ rectangle(-0.32, -0.15, 0.64, 0.18, 0.04),
37
+ polygon(-0.24, 0.02, -0.12, 0.02, -0.15, 0.44, -0.265, 0.44),
38
+ polygon(0.12, 0.02, 0.24, 0.02, 0.265, 0.44, 0.15, 0.44),
39
39
  ],
40
40
  [SeatShape.Armchair]: [
41
41
  rectangle(-0.34, -0.4, 0.68, 0.46, 0.08),
@@ -1,4 +1,4 @@
1
- import { SeatingKind, type StraightRows, type CurvedRows, type RoundTable, type RectangularTable, type PointM, type RowLayout, type LabelSequence } from "../types.js";
1
+ import { SeatingKind, type StraightRows, type CurvedRows, type RoundTable, type RectangularTable, type PointM, type RowLayout, type LabelSequence } from "../physical-document.interface.js";
2
2
  export type RowsGeometry = Pick<StraightRows, "kind" | "recipe"> | Pick<CurvedRows, "kind" | "recipe">;
3
3
  export declare enum TableSide {
4
4
  Top = "top",
@@ -6,11 +6,20 @@ export declare enum TableSide {
6
6
  Bottom = "bottom",
7
7
  Left = "left"
8
8
  }
9
+ export declare function rectangularChairOrder(recipe: RectangularTable["recipe"]): readonly TableSide[];
10
+ export declare function rowStaggerOffset(recipe: StraightRows["recipe"], index: number): number;
11
+ /** A lane shift is derived from the recipe. The row offset remains an independent edit. */
12
+ export declare function rowPlacementOffset(group: RowsGeometry, index: number, offset?: PointM): PointM;
9
13
  export type SeatGeometry = {
10
14
  position: PointM;
11
15
  rotationDeg: number;
12
16
  };
13
17
  export declare function rowSeatGeometry(group: RowsGeometry, row: number, seat: number, count: number, longestRow?: number, layout?: RowLayout): SeatGeometry;
18
+ /** The row axis is independent of its chair-facing offset. */
19
+ export declare function rowLayoutAxisRotation(layout: RowLayout): number;
20
+ export declare function setRowLayoutAxisRotation(layout: RowLayout, rotationDeg: number): RowLayout;
21
+ /** Curve edits preserve the row axis and its independent chair-facing offset. */
22
+ export declare function setRowLayoutCurve(layout: RowLayout, curveDeg: number): RowLayout;
14
23
  /** Resolves inherited geometry once when a row becomes independently editable. */
15
24
  export declare function resolveRowLayout(group: StraightRows | CurvedRows, rowIndex: number): RowLayout | null;
16
25
  export declare function roundChairGeometry(recipe: RoundTable["recipe"], chairHeightM: number, seat: number, count: number): SeatGeometry;