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

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.
@@ -0,0 +1,101 @@
1
+ import { SeatShape } from "../types.js";
2
+ export var SeatShapePartKind;
3
+ (function (SeatShapePartKind) {
4
+ SeatShapePartKind["Rectangle"] = "rectangle";
5
+ SeatShapePartKind["Polygon"] = "polygon";
6
+ })(SeatShapePartKind || (SeatShapePartKind = {}));
7
+ const rectangle = (x, y, width, height, radius = 0) => ({
8
+ kind: SeatShapePartKind.Rectangle,
9
+ x,
10
+ y,
11
+ width,
12
+ height,
13
+ radius,
14
+ });
15
+ const polygon = (...points) => ({
16
+ kind: SeatShapePartKind.Polygon,
17
+ points,
18
+ });
19
+ // Normalized to the existing physical seat footprint. Category appearance never
20
+ // changes positions, pitch, inventory identity or the personal geometry recipe.
21
+ const furniture = {
22
+ [SeatShape.Theatre]: [
23
+ rectangle(-0.3, -0.42, 0.6, 0.52, 0.06),
24
+ rectangle(-0.42, 0, 0.84, 0.22, 0.06),
25
+ rectangle(-0.42, 0.12, 0.12, 0.3, 0.04),
26
+ rectangle(0.3, 0.12, 0.12, 0.3, 0.04),
27
+ ],
28
+ [SeatShape.Dining]: [
29
+ polygon(-0.23, -0.42, 0.23, -0.42, 0.19, -0.055, -0.19, -0.055),
30
+ rectangle(-0.315, -0.055, 0.63, 0.18, 0.025),
31
+ polygon(-0.19, 0.08, -0.08, 0.08, -0.19, 0.42, -0.3, 0.42),
32
+ polygon(0.08, 0.08, 0.19, 0.08, 0.3, 0.42, 0.19, 0.42),
33
+ ],
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),
39
+ ],
40
+ [SeatShape.Armchair]: [
41
+ rectangle(-0.34, -0.4, 0.68, 0.46, 0.08),
42
+ rectangle(-0.42, -0.08, 0.14, 0.42, 0.07),
43
+ rectangle(0.28, -0.08, 0.14, 0.42, 0.07),
44
+ rectangle(-0.42, 0.08, 0.84, 0.34, 0.07),
45
+ ],
46
+ [SeatShape.Recliner]: [
47
+ polygon(-0.18, -0.42, 0.18, -0.42, 0.26, 0.1, -0.26, 0.1),
48
+ rectangle(-0.39, -0.12, 0.15, 0.36, 0.07),
49
+ rectangle(0.24, -0.12, 0.15, 0.36, 0.07),
50
+ rectangle(-0.26, 0.04, 0.52, 0.1, 0.02),
51
+ polygon(-0.21, 0.22, 0.21, 0.22, 0.3, 0.42, -0.3, 0.42),
52
+ ],
53
+ [SeatShape.Stool]: [
54
+ rectangle(-0.42, -0.42, 0.84, 0.57, 0.1),
55
+ polygon(-0.18, 0.1, -0.04, 0.1, -0.2, 0.42, -0.36, 0.42),
56
+ polygon(0.04, 0.1, 0.18, 0.1, 0.36, 0.42, 0.2, 0.42),
57
+ ],
58
+ [SeatShape.Bench]: [
59
+ rectangle(-0.42, -0.4, 0.84, 0.21, 0.035),
60
+ rectangle(-0.42, -0.12, 0.84, 0.35, 0.025),
61
+ rectangle(-0.23, 0.17, 0.09, 0.25, 0.015),
62
+ rectangle(0.14, 0.17, 0.09, 0.25, 0.015),
63
+ ],
64
+ };
65
+ export function seatShapeParts(shape) {
66
+ return shape === SeatShape.Circle ? [] : furniture[shape];
67
+ }
68
+ const contours = new WeakMap();
69
+ /**
70
+ * @method seatShapeContour
71
+ * @description Reuses bounded normalized contours so small furniture corners stay smooth after scaling.
72
+ * @param {SeatShapePart} part Shared normalized furniture primitive.
73
+ * @returns {readonly number[]} Cached polygon coordinates for the primitive.
74
+ */
75
+ export function seatShapeContour(part) {
76
+ if (part.kind === SeatShapePartKind.Polygon) {
77
+ return part.points;
78
+ }
79
+ const cached = contours.get(part);
80
+ if (cached) {
81
+ return cached;
82
+ }
83
+ const { x, y, width, height } = part;
84
+ const radius = Math.min(part.radius, width / 2, height / 2);
85
+ const points = [];
86
+ const centers = [
87
+ [x + width - radius, y + radius],
88
+ [x + width - radius, y + height - radius],
89
+ [x + radius, y + height - radius],
90
+ [x + radius, y + radius],
91
+ ];
92
+ for (let corner = 0; corner < 4; corner++) {
93
+ const center = centers[corner];
94
+ for (let step = 0; step <= 8; step++) {
95
+ const angle = ((corner - 1) * Math.PI) / 2 + (step * Math.PI) / 16;
96
+ points.push(center[0] + radius * Math.cos(angle), center[1] + radius * Math.sin(angle));
97
+ }
98
+ }
99
+ contours.set(part, points);
100
+ return points;
101
+ }
@@ -1,4 +1,4 @@
1
- import { SeatingKind, type StraightRows, type CurvedRows, type RoundTable, type RectangularTable, type PointM } from "../types.js";
1
+ import { SeatingKind, type StraightRows, type CurvedRows, type RoundTable, type RectangularTable, type PointM, type RowLayout, type LabelSequence } from "../types.js";
2
2
  export type RowsGeometry = Pick<StraightRows, "kind" | "recipe"> | Pick<CurvedRows, "kind" | "recipe">;
3
3
  export declare enum TableSide {
4
4
  Top = "top",
@@ -10,13 +10,16 @@ export type SeatGeometry = {
10
10
  position: PointM;
11
11
  rotationDeg: number;
12
12
  };
13
- export declare function rowSeatGeometry(group: RowsGeometry, row: number, seat: number, count: number, longestRow?: number): SeatGeometry;
13
+ export declare function rowSeatGeometry(group: RowsGeometry, row: number, seat: number, count: number, longestRow?: number, layout?: RowLayout): SeatGeometry;
14
+ /** Resolves inherited geometry once when a row becomes independently editable. */
15
+ export declare function resolveRowLayout(group: StraightRows | CurvedRows, rowIndex: number): RowLayout | null;
14
16
  export declare function roundChairGeometry(recipe: RoundTable["recipe"], chairHeightM: number, seat: number, count: number): SeatGeometry;
15
17
  export declare function rectangularChairGeometry(recipe: RectangularTable["recipe"], chairHeightM: number, side: TableSide, seat: number, count: number): SeatGeometry;
16
18
  export type SeatingPreview = (RowsGeometry & {
17
19
  rows: number;
18
20
  seatsPerRow: number;
19
21
  rowCounts?: readonly number[];
22
+ rowLayouts?: readonly (RowLayout | undefined)[];
20
23
  seatSizeM: number;
21
24
  }) | {
22
25
  kind: SeatingKind.Round;
@@ -30,7 +33,13 @@ export type SeatingPreview = (RowsGeometry & {
30
33
  seatSizeM: number;
31
34
  };
32
35
  export type PreviewNumbering = {
33
- rowStart: number;
36
+ rowSequence: LabelSequence;
37
+ logicalRow?: {
38
+ label: string;
39
+ sequence: LabelSequence;
40
+ offset: number;
41
+ total: number;
42
+ };
34
43
  tableLabel: string;
35
44
  seatFontSizeM: number;
36
45
  rowFontSizeM: number;
@@ -1,4 +1,4 @@
1
- import { CurveMode, RowAlignment, SeatingKind, } from "../types.js";
1
+ import { CurveMode, TableChairDistribution, RowAlignment, SeatingKind, } from "../types.js";
2
2
  import { ellipseAngleAtDistance } from "./ellipse.js";
3
3
  export var TableSide;
4
4
  (function (TableSide) {
@@ -7,7 +7,32 @@ export var TableSide;
7
7
  TableSide["Bottom"] = "bottom";
8
8
  TableSide["Left"] = "left";
9
9
  })(TableSide || (TableSide = {}));
10
- export function rowSeatGeometry(group, row, seat, count, longestRow = count) {
10
+ export function rowSeatGeometry(group, row, seat, count, longestRow = count, layout) {
11
+ if (layout) {
12
+ const sweep = (layout.curveDeg * Math.PI) / 180;
13
+ const fraction = count > 1 ? seat / (count - 1) : 0;
14
+ const angle = sweep * fraction;
15
+ const distance = seat * layout.seatPitchM;
16
+ // Stable straight-line limit avoids division by zero and cancellation near zero.
17
+ const sinc = Math.abs(angle) < 1e-6
18
+ ? 1 - (angle * angle) / 6
19
+ : Math.sin(angle) / angle;
20
+ const cosc = Math.abs(angle) < 1e-6
21
+ ? angle / 2 - (angle * angle * angle) / 24
22
+ : (1 - Math.cos(angle)) / angle;
23
+ const x = distance * sinc;
24
+ const y = -distance * cosc;
25
+ const rotation = (layout.rotationDeg * Math.PI) / 180;
26
+ return {
27
+ position: {
28
+ x: layout.originM.x + x * Math.cos(rotation) - y * Math.sin(rotation),
29
+ y: layout.originM.y + x * Math.sin(rotation) + y * Math.cos(rotation),
30
+ },
31
+ rotationDeg: layout.rotationDeg -
32
+ (angle * 180) / Math.PI +
33
+ (layout.seatRotationOffsetDeg ?? 0),
34
+ };
35
+ }
11
36
  if (group.kind === SeatingKind.Straight)
12
37
  return {
13
38
  position: {
@@ -45,9 +70,57 @@ export function rowSeatGeometry(group, row, seat, count, longestRow = count) {
45
70
  Math.PI,
46
71
  };
47
72
  }
73
+ /** Resolves inherited geometry once when a row becomes independently editable. */
74
+ export function resolveRowLayout(group, rowIndex) {
75
+ const row = group.rows[rowIndex];
76
+ if (row.layout)
77
+ return row.layout;
78
+ if (group.kind === SeatingKind.Curved && (group.recipe.axisRatio ?? 1) !== 1)
79
+ return null;
80
+ const longest = group.rows.reduce((max, item) => Math.max(max, item.seats.length), 0);
81
+ const first = rowSeatGeometry(group, rowIndex, 0, row.seats.length, longest);
82
+ if (group.kind === SeatingKind.Straight)
83
+ return {
84
+ originM: first.position,
85
+ seatPitchM: group.recipe.seatPitchM,
86
+ curveDeg: 0,
87
+ rotationDeg: ((((first.rotationDeg + 180) % 360) + 360) % 360) - 180,
88
+ };
89
+ const radius = group.recipe.innerRadiusM + rowIndex * group.recipe.rowPitchM;
90
+ const placement = group.recipe.placement;
91
+ const intervals = Math.max(0, row.seats.length - 1);
92
+ let sweep;
93
+ let pitch;
94
+ if (placement.kind === CurveMode.Pitch) {
95
+ pitch = placement.seatPitchM;
96
+ sweep = (((intervals * pitch) / radius) * 180) / Math.PI;
97
+ }
98
+ else {
99
+ sweep =
100
+ placement.sweepAngleDeg *
101
+ (Math.abs(placement.sweepAngleDeg) === 360
102
+ ? intervals / row.seats.length
103
+ : 1);
104
+ pitch = intervals
105
+ ? (((Math.abs(sweep) * Math.PI) / 180) * radius) / intervals
106
+ : 0.55;
107
+ }
108
+ const tangent = first.rotationDeg + (sweep < 0 ? 180 : 0);
109
+ return {
110
+ originM: first.position,
111
+ seatPitchM: pitch,
112
+ curveDeg: -sweep,
113
+ rotationDeg: ((((tangent + 180) % 360) + 360) % 360) - 180,
114
+ ...(sweep < 0 ? { seatRotationOffsetDeg: -180 } : {}),
115
+ };
116
+ }
48
117
  export function roundChairGeometry(recipe, chairHeightM, seat, count) {
49
118
  const radius = recipe.diameterM / 2 + recipe.chairGapM + chairHeightM / 2;
50
- const angle = recipe.startAngleDeg + (360 * seat) / count;
119
+ const arc = recipe.seatArcDeg ?? 360;
120
+ const angle = recipe.startAngleDeg +
121
+ (count === 1
122
+ ? 0
123
+ : (360 - arc) / 2 + (arc * seat) / (arc === 360 ? count : count - 1));
51
124
  return {
52
125
  position: {
53
126
  x: radius * Math.cos((angle * Math.PI) / 180),
@@ -59,9 +132,11 @@ export function roundChairGeometry(recipe, chairHeightM, seat, count) {
59
132
  export function rectangularChairGeometry(recipe, chairHeightM, side, seat, count) {
60
133
  const horizontal = side === TableSide.Top || side === TableSide.Bottom;
61
134
  const length = horizontal ? recipe.widthM : recipe.depthM;
62
- const along = recipe.chairPitchM === undefined
63
- ? -length / 2 + ((seat + 1) * length) / (count + 1)
64
- : (seat - (count - 1) / 2) * recipe.chairPitchM;
135
+ const along = recipe.chairDistribution === TableChairDistribution.EqualSegments
136
+ ? -length / 2 + ((seat + 0.5) * length) / count
137
+ : recipe.chairPitchM === undefined
138
+ ? -length / 2 + ((seat + 1) * length) / (count + 1)
139
+ : (seat - (count - 1) / 2) * recipe.chairPitchM;
65
140
  const gap = recipe.chairGapM + chairHeightM / 2;
66
141
  switch (side) {
67
142
  case TableSide.Top:
@@ -76,12 +151,22 @@ export function rectangularChairGeometry(recipe, chairHeightM, side, seat, count
76
151
  };
77
152
  case TableSide.Bottom:
78
153
  return {
79
- position: { x: -along, y: recipe.depthM / 2 + gap },
154
+ position: {
155
+ x: recipe.chairDistribution === TableChairDistribution.EqualSegments
156
+ ? along
157
+ : -along,
158
+ y: recipe.depthM / 2 + gap,
159
+ },
80
160
  rotationDeg: -90,
81
161
  };
82
162
  case TableSide.Left:
83
163
  return {
84
- position: { x: -recipe.widthM / 2 - gap, y: -along },
164
+ position: {
165
+ x: -recipe.widthM / 2 - gap,
166
+ y: recipe.chairDistribution === TableChairDistribution.EqualSegments
167
+ ? along
168
+ : -along,
169
+ },
85
170
  rotationDeg: 0,
86
171
  };
87
172
  default: {
@@ -99,7 +184,7 @@ export function* previewSeats(layout) {
99
184
  for (let row = 0; row < layout.rows; row++)
100
185
  for (let seat = 0; seat < (layout.rowCounts?.[row] ?? layout.seatsPerRow); seat++)
101
186
  yield {
102
- position: rowSeatGeometry(layout, row, seat, layout.rowCounts?.[row] ?? layout.seatsPerRow, longestRow).position,
187
+ position: rowSeatGeometry(layout, row, seat, layout.rowCounts?.[row] ?? layout.seatsPerRow, longestRow, layout.rowLayouts?.[row]).position,
103
188
  row,
104
189
  ordinal: seat + 1,
105
190
  };
@@ -2,4 +2,5 @@ import type { PhysicalDocumentV1 } from "./types.js";
2
2
  export declare function remapDocumentSteps(source: PhysicalDocumentV1, name: string): Generator<number, {
3
3
  document: PhysicalDocumentV1;
4
4
  warnings: string[];
5
+ identities: ReadonlyMap<string, string>;
5
6
  }>;
package/dist/identity.js CHANGED
@@ -44,7 +44,15 @@ export function* remapDocumentSteps(source, name) {
44
44
  return result;
45
45
  }
46
46
  if (typeof value === "string" &&
47
- ["id", "parentId", "sectionId", "companionForSeatId", "assetId"].includes(key))
47
+ [
48
+ "id",
49
+ "parentId",
50
+ "sectionId",
51
+ "companionForSeatId",
52
+ "assetId",
53
+ "categoryId",
54
+ "rowId",
55
+ ].includes(key))
48
56
  return ids.get(value) ?? value;
49
57
  return value;
50
58
  }
@@ -57,5 +65,9 @@ export function* remapDocumentSteps(source, name) {
57
65
  if (parsed.status !== DocumentParseStatus.Accepted)
58
66
  throw new Error("Identity remapping produced invalid physical structure.");
59
67
  yield 1;
60
- return { document: parsed.document, warnings: [...new Set(warnings)] };
68
+ return {
69
+ document: parsed.document,
70
+ warnings: [...new Set(warnings)],
71
+ identities: ids,
72
+ };
61
73
  }
package/dist/labels.d.ts CHANGED
@@ -1,3 +1,9 @@
1
1
  import { type LabelSequence } from "./types.js";
2
2
  export declare function labelKey(value: string): string;
3
+ /** Position in the buyer's sequence, independent of authored inventory identity. */
4
+ export declare function sequenceOrdinal(sequence: LabelSequence, index: number, count: number): number;
5
+ export declare function sequenceStep(sequence: LabelSequence): number;
6
+ /** Combined patterns own their order; the stored anchor remains available when switching back. */
7
+ export declare function sequenceOwnsOrder(scheme: string): boolean;
8
+ export declare function sequenceStart(sequence: LabelSequence, count: number): number;
3
9
  export declare function sequenceLabel(sequence: LabelSequence, index: number, count: number): string;
package/dist/labels.js CHANGED
@@ -24,22 +24,85 @@ export function labelKey(value) {
24
24
  .join("")
25
25
  .normalize("NFC");
26
26
  }
27
+ /** Position in the buyer's sequence, independent of authored inventory identity. */
28
+ export function sequenceOrdinal(sequence, index, count) {
29
+ const middle = Math.ceil(count / 2);
30
+ if (sequence.scheme === NumberingScheme.OutsideIn)
31
+ return index < middle ? index * 2 : (count - 1 - index) * 2 + 1;
32
+ if (sequence.scheme === NumberingScheme.InsideOut)
33
+ return index < middle ? (middle - 1 - index) * 2 : (index - middle) * 2 + 1;
34
+ if (sequence.direction === LabelDirection.Centre) {
35
+ const centre = Math.floor((count - 1) / 2);
36
+ if (index === centre)
37
+ return 0;
38
+ if (index < centre)
39
+ return (centre - index) * 2 - (count % 2);
40
+ return (index - centre) * 2 - (count % 2 === 0 ? 1 : 0);
41
+ }
42
+ return sequence.direction === LabelDirection.Reverse
43
+ ? count - 1 - index
44
+ : index;
45
+ }
46
+ export function sequenceStep(sequence) {
47
+ return sequence.scheme === NumberingScheme.Odd ||
48
+ sequence.scheme === NumberingScheme.Even
49
+ ? 2
50
+ : 1;
51
+ }
52
+ /** Combined patterns own their order; the stored anchor remains available when switching back. */
53
+ export function sequenceOwnsOrder(scheme) {
54
+ return (scheme === NumberingScheme.OutsideIn || scheme === NumberingScheme.InsideOut);
55
+ }
56
+ export function sequenceStart(sequence, count) {
57
+ let start = !sequenceOwnsOrder(sequence.scheme) &&
58
+ sequence.numberFrom === "last" &&
59
+ sequence.lastAt !== undefined
60
+ ? Math.max(0, sequence.lastAt - Math.max(0, count - 1) * sequenceStep(sequence))
61
+ : sequence.startAt;
62
+ if (sequence.scheme === NumberingScheme.Odd && start % 2 === 0)
63
+ start++;
64
+ if (sequence.scheme === NumberingScheme.Even && start % 2 === 1)
65
+ start++;
66
+ return start;
67
+ }
68
+ const romanParts = [
69
+ [1000, "M"],
70
+ [900, "CM"],
71
+ [500, "D"],
72
+ [400, "CD"],
73
+ [100, "C"],
74
+ [90, "XC"],
75
+ [50, "L"],
76
+ [40, "XL"],
77
+ [10, "X"],
78
+ [9, "IX"],
79
+ [5, "V"],
80
+ [4, "IV"],
81
+ [1, "I"],
82
+ ];
27
83
  export function sequenceLabel(sequence, index, count) {
28
- const ordinal = sequence.direction === LabelDirection.Reverse ? count - 1 - index : index;
29
- let n = sequence.startAt +
30
- ordinal *
31
- (sequence.scheme === NumberingScheme.Odd ||
32
- sequence.scheme === NumberingScheme.Even
33
- ? 2
34
- : 1);
84
+ let n = sequenceStart(sequence, count) +
85
+ sequenceOrdinal(sequence, index, count) * sequenceStep(sequence);
35
86
  let label = String(n);
36
- if (sequence.scheme === NumberingScheme.Alphabetic) {
87
+ if (sequence.scheme === NumberingScheme.Alphabetic ||
88
+ sequence.scheme === NumberingScheme.LowerAlphabetic) {
89
+ n = Math.max(1, n);
37
90
  label = "";
38
91
  while (n > 0) {
39
92
  n--;
40
93
  label = String.fromCharCode(65 + (n % 26)) + label;
41
94
  n = Math.floor(n / 26);
42
95
  }
96
+ if (sequence.scheme === NumberingScheme.LowerAlphabetic)
97
+ label = label.toLowerCase();
98
+ }
99
+ else if (sequence.scheme === NumberingScheme.Roman && n > 0) {
100
+ label = "";
101
+ for (const [value, glyph] of romanParts) {
102
+ const repeats = Math.floor(n / value);
103
+ label += glyph.repeat(repeats);
104
+ n %= value;
105
+ }
43
106
  }
44
107
  return (sequence.prefix ?? "") + label + (sequence.suffix ?? "");
45
108
  }
package/dist/preview.js CHANGED
@@ -1,6 +1,9 @@
1
- import { footprint, generateGroup, project, worldMatrices, } from "./geometry/geometry.js";
1
+ import { documentGroupSeats } from "./catalog.js";
2
+ import { footprint, project, worldMatrices, multiply, transformMatrix, } from "./geometry/geometry.js";
2
3
  import { emptyBounds, extend } from "./geometry/primitives.js";
3
- import { DecorationKind, SeatingKind, ShapeKind } from "./types.js";
4
+ import { categoryCatalog, categorySeatShape } from "./categories.js";
5
+ import { seatShapeParts, SeatShapePartKind } from "./geometry/seat-shape.js";
6
+ import { DecorationKind, SeatingKind, ShapeKind, SeatShape } from "./types.js";
4
7
  export const ThumbnailPolicy = {
5
8
  MaximumSvgLength: 128000,
6
9
  MaximumContentLength: 120000,
@@ -13,6 +16,7 @@ export const ThumbnailPolicy = {
13
16
  export function projectMapPreview(document) {
14
17
  const bounds = emptyBounds();
15
18
  const matrices = worldMatrices(document);
19
+ const categories = categoryCatalog(document);
16
20
  const sections = new Map(document.sections.map((section) => [section.id, section]));
17
21
  const foreground = parseInt(document.background.color.slice(1, 3), 16) +
18
22
  parseInt(document.background.color.slice(3, 5), 16) +
@@ -78,7 +82,11 @@ export function projectMapPreview(document) {
78
82
  : []);
79
83
  let index = 0;
80
84
  const rowIndices = new Map();
81
- for (const seat of generateGroup(group)) {
85
+ for (const seat of documentGroupSeats(document, group)) {
86
+ if (seat.slot.gap) {
87
+ index++;
88
+ continue;
89
+ }
82
90
  const position = project(matrix, seat.position);
83
91
  const radius = Math.max(seat.size.width, seat.size.height) / 2;
84
92
  for (const corner of footprint(seat, matrix))
@@ -94,7 +102,31 @@ export function projectMapPreview(document) {
94
102
  rows.set(seat.rowId, row);
95
103
  }
96
104
  if (glyphs < ThumbnailPolicy.MaximumSeatGlyphs && index % 8 === 0) {
97
- append(`<circle cx="${number(position.x)}" cy="${number(position.y)}" r="${number(radius)}" fill="${colour}" fill-opacity=".8"/>`);
105
+ const category = seat.categoryId
106
+ ? categories.get(seat.categoryId)
107
+ : undefined;
108
+ const shape = categorySeatShape(category, seat.slot);
109
+ const seatColour = category?.color ?? colour;
110
+ if (shape === SeatShape.Circle) {
111
+ append(`<circle cx="${number(position.x)}" cy="${number(position.y)}" r="${number(radius)}" fill="${seatColour}" fill-opacity=".8"/>`);
112
+ }
113
+ else {
114
+ const transform = multiply(matrix, transformMatrix({
115
+ positionM: seat.position,
116
+ rotationDeg: seat.rotationDeg,
117
+ }));
118
+ const shapeMarkup = seatShapeParts(shape)
119
+ .map((part) => {
120
+ if (part.kind === SeatShapePartKind.Rectangle)
121
+ return `<rect x="${number(part.x * seat.size.width)}" y="${number(part.y * seat.size.height)}" width="${number(part.width * seat.size.width)}" height="${number(part.height * seat.size.height)}" rx="${number(part.radius * Math.min(seat.size.width, seat.size.height))}"/>`;
122
+ const points = [];
123
+ for (let index = 0; index < part.points.length; index += 2)
124
+ points.push(`${number(part.points[index] * seat.size.width)},${number(part.points[index + 1] * seat.size.height)}`);
125
+ return `<polygon points="${points.join(" ")}"/>`;
126
+ })
127
+ .join("");
128
+ append(`<g transform="matrix(${transform.a} ${transform.b} ${transform.c} ${transform.d} ${transform.tx} ${transform.ty})" fill="${seatColour}" fill-opacity=".8">${shapeMarkup}</g>`);
129
+ }
98
130
  glyphs++;
99
131
  }
100
132
  index++;
@@ -110,7 +142,10 @@ export function projectMapPreview(document) {
110
142
  const path = area.shape.kind === ShapeKind.Polygon
111
143
  ? polygon(area.shape.boundary, matrix)
112
144
  : rectangle(area.shape.widthM, area.shape.heightM, matrix);
113
- append(`<path d="${path}" ${paint(sections.get(area.sectionId ?? "")?.style?.fill)} fill-rule="evenodd"/>`);
145
+ const category = area.categoryId
146
+ ? categories.get(area.categoryId)
147
+ : undefined;
148
+ append(`<path d="${path}" ${paint(category ? { color: category.color, opacity: 1 } : sections.get(area.sectionId ?? "")?.style?.fill)} fill-rule="evenodd"/>`);
114
149
  }
115
150
  for (const art of [...document.decorations].sort((left, right) => left.zIndex - right.zIndex)) {
116
151
  empty = false;
@@ -0,0 +1,26 @@
1
+ import { RowEnds, type PhysicalDocumentV1, type SeatingGroup, type RowInventory, type RowSlot, type SegmentedRow, type UUID, type PointM } from "./types.js";
2
+ export type RowSegment = {
3
+ row: SegmentedRow;
4
+ group: RowInventory;
5
+ part: RowSlot;
6
+ partIndex: number;
7
+ firstIndex: number;
8
+ totalSeats: number;
9
+ };
10
+ export type SegmentedRowEntry = {
11
+ row: SegmentedRow;
12
+ parts: readonly RowSegment[];
13
+ };
14
+ export declare function isRowInventory(group: SeatingGroup): group is RowInventory;
15
+ /** Logical rows associate independent physical parts without moving them between rendering banks. */
16
+ export declare function rowSegments(document: PhysicalDocumentV1): ReadonlyMap<UUID, RowSegment>;
17
+ export declare function changedSegmentGroups(before: PhysicalDocumentV1, after: PhysicalDocumentV1): ReadonlySet<UUID>;
18
+ export declare function suggestedRowEnds(document: PhysicalDocumentV1, rowId: UUID): RowEnds;
19
+ export type RowAisleGap = {
20
+ nextPartIndex: number;
21
+ distanceM: number;
22
+ requiredM: number;
23
+ deltaM: PointM;
24
+ };
25
+ /** A marked aisle leaves one seat of space between the adjacent seat centres. */
26
+ export declare function rowAisleGaps(document: PhysicalDocumentV1, rowId: UUID): RowAisleGap[];
@@ -0,0 +1,112 @@
1
+ import { generateGroup, project, worldMatrices } from "./geometry/geometry.js";
2
+ import { SeatingKind, RowEnds, RowJoin, } from "./types.js";
3
+ const segments = new WeakMap();
4
+ export function isRowInventory(group) {
5
+ return (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved);
6
+ }
7
+ /** Logical rows associate independent physical parts without moving them between rendering banks. */
8
+ export function rowSegments(document) {
9
+ const cached = segments.get(document);
10
+ if (cached)
11
+ return cached;
12
+ const owners = new Map(document.seatingGroups.flatMap((group) => isRowInventory(group)
13
+ ? group.rows.map((part) => [part.id, { group, part }])
14
+ : []));
15
+ const result = new Map();
16
+ for (const row of document.segmentedRows ?? []) {
17
+ const parts = row.parts.map((part) => owners.get(part.rowId));
18
+ const totalSeats = parts.reduce((sum, item) => sum + item.part.seats.length, 0);
19
+ let firstIndex = 0;
20
+ parts.forEach((item, partIndex) => {
21
+ result.set(item.part.id, {
22
+ row,
23
+ ...item,
24
+ partIndex,
25
+ firstIndex,
26
+ totalSeats,
27
+ });
28
+ firstIndex += item.part.seats.length;
29
+ });
30
+ }
31
+ segments.set(document, result);
32
+ return result;
33
+ }
34
+ export function changedSegmentGroups(before, after) {
35
+ const groups = new Set();
36
+ if (before.segmentedRows === after.segmentedRows &&
37
+ before.seatingGroups === after.seatingGroups)
38
+ return groups;
39
+ const previous = new Map((before.segmentedRows ?? []).map((row) => [row.id, row]));
40
+ const next = new Map((after.segmentedRows ?? []).map((row) => [row.id, row]));
41
+ for (const id of new Set([...previous.keys(), ...next.keys()])) {
42
+ const previousRow = previous.get(id), nextRow = next.get(id);
43
+ if (previousRow === nextRow &&
44
+ previousRow?.parts.every((part) => rowSegments(before).get(part.rowId).part.seats.length ===
45
+ rowSegments(after).get(part.rowId).part.seats.length))
46
+ continue;
47
+ for (const part of previous.get(id)?.parts ?? [])
48
+ groups.add(rowSegments(before).get(part.rowId).group.id);
49
+ for (const part of next.get(id)?.parts ?? [])
50
+ groups.add(rowSegments(after).get(part.rowId).group.id);
51
+ }
52
+ return groups;
53
+ }
54
+ export function suggestedRowEnds(document, rowId) {
55
+ const segment = rowSegments(document).get(rowId);
56
+ if (!segment)
57
+ return RowEnds.Both;
58
+ const first = segment.partIndex === 0 ||
59
+ segment.row.parts[segment.partIndex].joinBefore === RowJoin.Aisle;
60
+ const last = segment.partIndex === segment.row.parts.length - 1 ||
61
+ segment.row.parts[segment.partIndex + 1].joinBefore === RowJoin.Aisle;
62
+ if (first && last)
63
+ return RowEnds.Both;
64
+ if (first)
65
+ return RowEnds.Start;
66
+ return last ? RowEnds.End : RowEnds.None;
67
+ }
68
+ /** A marked aisle leaves one seat of space between the adjacent seat centres. */
69
+ export function rowAisleGaps(document, rowId) {
70
+ const row = document.segmentedRows.find((row) => row.id === rowId);
71
+ const segments = rowSegments(document);
72
+ const matrices = worldMatrices(document);
73
+ const seats = new Map();
74
+ const edges = row.parts.map((part) => {
75
+ const segment = segments.get(part.rowId);
76
+ let generated = seats.get(segment.group.id);
77
+ if (!generated) {
78
+ generated = [...generateGroup(segment.group)];
79
+ seats.set(segment.group.id, generated);
80
+ }
81
+ const physical = generated.filter((seat) => seat.rowId === part.rowId);
82
+ const matrix = matrices.get(segment.group.id);
83
+ return {
84
+ first: project(matrix, physical[0].position),
85
+ last: project(matrix, physical.at(-1).position),
86
+ pitchM: segment.part.layout.seatPitchM,
87
+ };
88
+ });
89
+ return row.parts.flatMap((part, index) => {
90
+ if (!index || part.joinBefore !== RowJoin.Aisle)
91
+ return [];
92
+ const previous = edges[index - 1], next = edges[index];
93
+ const dx = next.first.x - previous.last.x;
94
+ const dy = next.first.y - previous.last.y;
95
+ const distanceM = Math.hypot(dx, dy);
96
+ const requiredM = previous.pitchM + next.pitchM;
97
+ if (distanceM >= requiredM - 1e-9)
98
+ return [];
99
+ const angle = Math.atan2(dy, dx);
100
+ return [
101
+ {
102
+ nextPartIndex: index,
103
+ distanceM,
104
+ requiredM,
105
+ deltaM: {
106
+ x: Math.cos(angle) * (requiredM - distanceM),
107
+ y: Math.sin(angle) * (requiredM - distanceM),
108
+ },
109
+ },
110
+ ];
111
+ });
112
+ }