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

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 (62) hide show
  1. package/dist/catalog.d.ts +10 -3
  2. package/dist/catalog.js +66 -10
  3. package/dist/categories.d.ts +26 -0
  4. package/dist/categories.js +168 -0
  5. package/dist/editor-state.d.ts +49 -0
  6. package/dist/editor-state.js +266 -0
  7. package/dist/floors.d.ts +19 -0
  8. package/dist/floors.js +68 -0
  9. package/dist/geometry/boundary.d.ts +1 -1
  10. package/dist/geometry/boundary.js +10 -12
  11. package/dist/geometry/curve-warnings.d.ts +1 -1
  12. package/dist/geometry/curve-warnings.js +3 -5
  13. package/dist/geometry/decoration-bounds.d.ts +4 -0
  14. package/dist/geometry/decoration-bounds.js +42 -0
  15. package/dist/geometry/ellipse.js +4 -12
  16. package/dist/geometry/geometry.d.ts +12 -3
  17. package/dist/geometry/geometry.js +35 -26
  18. package/dist/geometry/polygon-curves.d.ts +12 -0
  19. package/dist/geometry/polygon-curves.js +132 -0
  20. package/dist/geometry/primitives.d.ts +1 -1
  21. package/dist/geometry/primitives.js +2 -3
  22. package/dist/geometry/seat-shape.d.ts +24 -0
  23. package/dist/geometry/seat-shape.js +101 -0
  24. package/dist/geometry/seating-layout.d.ts +14 -3
  25. package/dist/geometry/seating-layout.js +91 -19
  26. package/dist/geometry/units.d.ts +1 -0
  27. package/dist/geometry/units.js +2 -0
  28. package/dist/geometry/venue-outline.d.ts +2 -2
  29. package/dist/geometry/venue-outline.js +8 -21
  30. package/dist/identity.d.ts +4 -1
  31. package/dist/identity.js +36 -10
  32. package/dist/issues.d.ts +9 -2
  33. package/dist/issues.js +8 -6
  34. package/dist/labels.d.ts +12 -1
  35. package/dist/labels.js +76 -11
  36. package/dist/layers.d.ts +26 -0
  37. package/dist/layers.js +86 -0
  38. package/dist/media.d.ts +27 -0
  39. package/dist/media.js +89 -0
  40. package/dist/physical-document.interface.d.ts +518 -0
  41. package/dist/{types.js → physical-document.interface.js} +71 -0
  42. package/dist/preview.d.ts +1 -1
  43. package/dist/preview.js +65 -24
  44. package/dist/reference.js +1 -1
  45. package/dist/row-segments.d.ts +30 -0
  46. package/dist/row-segments.js +112 -0
  47. package/dist/schema.d.ts +1192 -68
  48. package/dist/schema.js +372 -96
  49. package/dist/seat-proximity.d.ts +4 -0
  50. package/dist/seat-proximity.js +119 -0
  51. package/dist/sections.d.ts +23 -0
  52. package/dist/sections.js +149 -0
  53. package/dist/selling.d.ts +34 -0
  54. package/dist/selling.js +148 -0
  55. package/dist/spacing-repairs.d.ts +31 -0
  56. package/dist/spacing-repairs.js +168 -0
  57. package/dist/table-layout.d.ts +29 -0
  58. package/dist/table-layout.js +134 -0
  59. package/dist/validation.d.ts +3 -1
  60. package/dist/validation.js +124 -74
  61. package/package.json +59 -3
  62. package/dist/types.d.ts +0 -313
package/dist/floors.js ADDED
@@ -0,0 +1,68 @@
1
+ import { documentCatalog } from "./catalog.js";
2
+ import { groupInventoryCount } from "./schema.js";
3
+ import { AreaKind } from "./physical-document.interface.js";
4
+ const catalogs = new WeakMap();
5
+ /** Derive physical membership and counts once, without creating another editable document. */
6
+ export function floorCatalog(document) {
7
+ const cached = catalogs.get(document);
8
+ if (cached)
9
+ return cached;
10
+ const entries = new Map();
11
+ const owners = new Map();
12
+ for (const floor of document.floors ?? [])
13
+ entries.set(floor.id, { floor, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, gapCount: 0 });
14
+ if (!document.floors)
15
+ entries.set(null, { floor: null, members: [], capacity: { physicalSeats: 0, gaQuantity: 0 }, gapCount: 0 });
16
+ for (const member of [
17
+ ...document.sections,
18
+ ...document.collections,
19
+ ...document.seatingGroups,
20
+ ...document.areas,
21
+ ...document.decorations,
22
+ ]) {
23
+ const id = member.floorId ?? null;
24
+ owners.set(member.id, id);
25
+ entries.get(id).members.push(member.id);
26
+ }
27
+ for (const group of document.seatingGroups) {
28
+ const id = group.floorId ?? null;
29
+ const entry = entries.get(id);
30
+ const inventoryCount = groupInventoryCount(group);
31
+ let slotCount = 0;
32
+ if ("rows" in group) {
33
+ for (const row of group.rows) {
34
+ owners.set(row.id, id);
35
+ slotCount += row.seats.length;
36
+ }
37
+ }
38
+ else if ("chairs" in group)
39
+ slotCount = group.chairs.length;
40
+ else
41
+ for (const side of Object.values(group.chairsBySide))
42
+ slotCount += side.length;
43
+ entry.capacity.physicalSeats += inventoryCount;
44
+ entry.gapCount += slotCount - inventoryCount;
45
+ }
46
+ for (const area of document.areas) {
47
+ const count = entries.get(area.floorId ?? null).capacity;
48
+ if (area.kind === AreaKind.Booth)
49
+ count.physicalSeats++;
50
+ else
51
+ count.gaQuantity += area.capacity;
52
+ }
53
+ for (const row of document.segmentedRows ?? [])
54
+ owners.set(row.id, owners.get(row.parts[0].rowId));
55
+ const catalog = { entries, owners };
56
+ catalogs.set(document, catalog);
57
+ return catalog;
58
+ }
59
+ /** Resolve seats through their physical owner; logical rows use their first physical part. */
60
+ export function objectFloorId(document, id) {
61
+ const owners = floorCatalog(document).owners;
62
+ if (owners.has(id))
63
+ return owners.get(id);
64
+ return documentCatalog(document).seats.get(id)?.group.floorId ?? null;
65
+ }
66
+ export function floorLabel(floor) {
67
+ return /^\d+$/u.test(floor.name) ? `Floor ${floor.name}` : floor.name;
68
+ }
@@ -1,4 +1,4 @@
1
- import type { PointM, PolygonM } from "../types.js";
1
+ import type { PointM, PolygonM } from "../physical-document.interface.js";
2
2
  import { type Bounds } from "./primitives.js";
3
3
  export declare enum BoundaryLocation {
4
4
  Inside = "inside",
@@ -1,4 +1,5 @@
1
- import { containsPoint, pointsBounds, intersects, } from "./primitives.js";
1
+ import { polygonContour } from "./polygon-curves.js";
2
+ import { containsPoint, pointsBounds, intersects } from "./primitives.js";
2
3
  export var BoundaryLocation;
3
4
  (function (BoundaryLocation) {
4
5
  BoundaryLocation["Inside"] = "inside";
@@ -11,10 +12,11 @@ export function prepareBoundary(polygon) {
11
12
  const cached = prepared.get(polygon);
12
13
  if (cached)
13
14
  return cached;
15
+ const contour = polygonContour(polygon);
14
16
  const boundary = {
15
- polygon,
16
- bounds: pointsBounds(polygon.outer),
17
- edges: [polygon.outer, ...polygon.holes].flatMap((r) => r.map((a, i) => ({
17
+ polygon: contour,
18
+ bounds: pointsBounds(contour.outer),
19
+ edges: [contour.outer, ...contour.holes].flatMap((r) => r.map((a, i) => ({
18
20
  a,
19
21
  b: r[(i + 1) % r.length],
20
22
  bounds: pointsBounds([a, r[(i + 1) % r.length]]),
@@ -24,16 +26,13 @@ export function prepareBoundary(polygon) {
24
26
  return boundary;
25
27
  }
26
28
  function onEdge(edge, p) {
27
- const dx = edge.b.x - edge.a.x, dy = edge.b.y - edge.a.y, t = Math.max(0, Math.min(1, ((p.x - edge.a.x) * dx + (p.y - edge.a.y) * dy) /
28
- Math.max(1e-30, dx * dx + dy * dy)));
29
- return (Math.hypot(p.x - edge.a.x - t * dx, p.y - edge.a.y - t * dy) <=
30
- BoundaryToleranceM);
29
+ const dx = edge.b.x - edge.a.x, dy = edge.b.y - edge.a.y, t = Math.max(0, Math.min(1, ((p.x - edge.a.x) * dx + (p.y - edge.a.y) * dy) / Math.max(1e-30, dx * dx + dy * dy)));
30
+ return Math.hypot(p.x - edge.a.x - t * dx, p.y - edge.a.y - t * dy) <= BoundaryToleranceM;
31
31
  }
32
32
  export function classifyBoundary(boundary, p) {
33
33
  if (boundary.edges.some((e) => onEdge(e, p)))
34
34
  return BoundaryLocation.Boundary;
35
- if (!containsPoint(boundary.polygon.outer, p) ||
36
- boundary.polygon.holes.some((h) => containsPoint(h, p)))
35
+ if (!containsPoint(boundary.polygon.outer, p) || boundary.polygon.holes.some((h) => containsPoint(h, p)))
37
36
  return BoundaryLocation.Outside;
38
37
  return BoundaryLocation.Inside;
39
38
  }
@@ -55,8 +54,7 @@ export function footprintInBoundary(boundary, points) {
55
54
  cuts.sort((l, r) => l - r);
56
55
  for (let j = 1; j < cuts.length; j++) {
57
56
  const t = (cuts[j - 1] + cuts[j]) / 2;
58
- if (classifyBoundary(boundary, { x: a.x + t * dx, y: a.y + t * dy }) ===
59
- BoundaryLocation.Outside)
57
+ if (classifyBoundary(boundary, { x: a.x + t * dx, y: a.y + t * dy }) === BoundaryLocation.Outside)
60
58
  return false;
61
59
  }
62
60
  }
@@ -1,4 +1,4 @@
1
- import { type CurvedRows, type RowSlot } from "../types.js";
1
+ import { type CurvedRows, type RowSlot } from "../physical-document.interface.js";
2
2
  export declare enum CurveWarningKind {
3
3
  Overrun = "overrun",
4
4
  Clearance = "clearance"
@@ -1,4 +1,4 @@
1
- import { CurveMode, SeatingKind, } from "../types.js";
1
+ import { CurveMode, SeatingKind } from "../physical-document.interface.js";
2
2
  import { ellipsePerimeter } from "./ellipse.js";
3
3
  import { rowSeatGeometry } from "./seating-layout.js";
4
4
  export var CurveWarningKind;
@@ -13,8 +13,7 @@ export function curveWarnings(recipe, counts, size, slots) {
13
13
  for (let row = 0; row < counts.length; row++) {
14
14
  const count = counts[row], b = recipe.innerRadiusM + row * recipe.rowPitchM, a = recipe.innerRadiusM * (recipe.axisRatio ?? 1) + row * recipe.rowPitchM;
15
15
  if (recipe.placement.kind === CurveMode.Pitch &&
16
- (count - 1) * recipe.placement.seatPitchM + size.width >
17
- ellipsePerimeter(a, b)) {
16
+ (count - 1) * recipe.placement.seatPitchM + size.width > ellipsePerimeter(a, b)) {
18
17
  warnings.push({
19
18
  kind: CurveWarningKind.Overrun,
20
19
  row,
@@ -30,8 +29,7 @@ export function curveWarnings(recipe, counts, size, slots) {
30
29
  }, seatSize = slot?.override?.sizeM ?? size;
31
30
  if (previous &&
32
31
  Math.hypot(point.x - previous.point.x, point.y - previous.point.y) <
33
- Math.min(previous.size.width + seatSize.width, previous.size.height + seatSize.height) /
34
- 2) {
32
+ Math.min(previous.size.width + seatSize.width, previous.size.height + seatSize.height) / 2) {
35
33
  warnings.push({
36
34
  kind: CurveWarningKind.Clearance,
37
35
  row,
@@ -0,0 +1,4 @@
1
+ import { type Decoration } from "../physical-document.interface.js";
2
+ import { type Bounds, type Matrix } from "./geometry.js";
3
+ /** World bounds of the physical artwork, independent of editor selection and section ownership. */
4
+ export declare function decorationBounds(decoration: Decoration, matrix: Matrix): Bounds;
@@ -0,0 +1,42 @@
1
+ import { polygonContour } from "./polygon-curves.js";
2
+ import { DecorationKind, LabelAlignment } from "../physical-document.interface.js";
3
+ import { pointsBounds, project } from "./geometry.js";
4
+ /** World bounds of the physical artwork, independent of editor selection and section ownership. */
5
+ export function decorationBounds(decoration, matrix) {
6
+ let points;
7
+ switch (decoration.kind) {
8
+ case DecorationKind.Line:
9
+ points = decoration.pointsM;
10
+ break;
11
+ case DecorationKind.Polygon:
12
+ points = polygonContour(decoration.boundary).outer;
13
+ break;
14
+ case DecorationKind.Text: {
15
+ const width = Math.max(decoration.fontSizeM, Array.from(decoration.text).length * decoration.fontSizeM * 0.65);
16
+ let start = -width / 2;
17
+ if (decoration.align === LabelAlignment.Left)
18
+ start = 0;
19
+ else if (decoration.align === LabelAlignment.Right)
20
+ start = -width;
21
+ points = rectanglePoints(width, decoration.fontSizeM).map((point) => ({
22
+ x: point.x + start + width / 2,
23
+ y: point.y,
24
+ }));
25
+ break;
26
+ }
27
+ case DecorationKind.Circle:
28
+ points = rectanglePoints(decoration.radiusM * 2, decoration.radiusM * 2);
29
+ break;
30
+ default:
31
+ points = rectanglePoints(decoration.sizeM.width, decoration.sizeM.height);
32
+ }
33
+ return pointsBounds(points.map((point) => project(matrix, point)));
34
+ }
35
+ function rectanglePoints(width, height) {
36
+ return [
37
+ { x: -width / 2, y: -height / 2 },
38
+ { x: width / 2, y: -height / 2 },
39
+ { x: width / 2, y: height / 2 },
40
+ { x: -width / 2, y: height / 2 },
41
+ ];
42
+ }
@@ -21,11 +21,7 @@ function table(a, b) {
21
21
  for (let i = 1; i <= count; i++) {
22
22
  const start = (tau * (i - 1)) / count, end = (tau * i) / count;
23
23
  angles[i] = end;
24
- lengths[i] =
25
- lengths[i - 1] +
26
- ((end - start) *
27
- (speed(start) + 4 * speed((start + end) / 2) + speed(end))) /
28
- 6;
24
+ lengths[i] = lengths[i - 1] + ((end - start) * (speed(start) + 4 * speed((start + end) / 2) + speed(end))) / 6;
29
25
  }
30
26
  const result = { angles, lengths, perimeter: lengths[count] };
31
27
  if (cache.size >= 128)
@@ -46,23 +42,19 @@ function interval(keys, value) {
46
42
  }
47
43
  function partial(a, b, start, end) {
48
44
  const speed = (t) => Math.hypot(a * Math.sin(t), b * Math.cos(t));
49
- return (((end - start) *
50
- (speed(start) + 4 * speed((start + end) / 2) + speed(end))) /
51
- 6);
45
+ return ((end - start) * (speed(start) + 4 * speed((start + end) / 2) + speed(end))) / 6;
52
46
  }
53
47
  export function ellipseArcLength(a, b, angle) {
54
48
  if (a === b)
55
49
  return a * angle;
56
50
  const t = table(a, b), turns = Math.floor(angle / tau), within = angle - turns * tau, i = interval(t.angles, within);
57
- return (turns * t.perimeter + t.lengths[i] + partial(a, b, t.angles[i], within));
51
+ return turns * t.perimeter + t.lengths[i] + partial(a, b, t.angles[i], within);
58
52
  }
59
53
  export function ellipseAngleAtDistance(a, b, center, distance) {
60
54
  if (a === b)
61
55
  return center + distance / a;
62
56
  const t = table(a, b), length = ellipseArcLength(a, b, center) + distance, turns = Math.floor(length / t.perimeter), within = length - turns * t.perimeter, i = interval(t.lengths, within);
63
- let angle = t.angles[i] +
64
- ((within - t.lengths[i]) / (t.lengths[i + 1] - t.lengths[i])) *
65
- (t.angles[i + 1] - t.angles[i]);
57
+ let angle = t.angles[i] + ((within - t.lengths[i]) / (t.lengths[i + 1] - t.lengths[i])) * (t.angles[i + 1] - t.angles[i]);
66
58
  for (let n = 0; n < 5; n++) {
67
59
  const error = t.lengths[i] + partial(a, b, t.angles[i], angle) - within;
68
60
  angle = Math.max(t.angles[i], Math.min(t.angles[i + 1], angle - error / Math.hypot(a * Math.sin(angle), b * Math.cos(angle))));
@@ -1,4 +1,4 @@
1
- import { type PhysicalDocumentV1, type PointM, type PolygonM, type SeatingGroup, type SeatSlot, type SizeM, type Transform, type UUID } 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,18 +8,26 @@ 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;
21
+ logicalRowLabel?: string;
22
+ logicalRowId?: UUID;
23
+ logicalPartIndex?: number;
24
+ logicalSequence?: LabelSequence;
19
25
  position: PointM;
20
26
  rotationDeg: number;
21
27
  size: SizeM;
22
28
  slot: SeatSlot;
29
+ aisle: boolean;
30
+ categoryId: UUID | null;
23
31
  };
24
32
  export declare const identityMatrix: Matrix;
25
33
  export declare const radians: (value: number) => number;
@@ -31,6 +39,7 @@ export declare function project(m: Matrix, p: PointM): PointM;
31
39
  /** Table bodies remain part of drawable bounds even with chairs on one side. */
32
40
  export declare function tableBodyBounds(group: SeatingGroup, matrix: Matrix): Bounds | null;
33
41
  export declare function worldMatrices(document: PhysicalDocumentV1): Map<UUID, Matrix>;
42
+ export declare function generatedSeats(group: SeatingGroup): readonly GeneratedSeat[];
34
43
  export declare function generateGroup(group: SeatingGroup): Generator<GeneratedSeat>;
35
44
  export declare function footprint(seat: GeneratedSeat, world?: Matrix): PointM[];
36
45
  export declare function footprintInside(points: PointM[], polygon: PolygonM): boolean;
@@ -1,8 +1,10 @@
1
- import { rowSeatGeometry, roundChairGeometry, rectangularChairGeometry, TableSide, } from "./seating-layout.js";
2
- import { SeatingKind, } from "../types.js";
3
- import { sequenceLabel } from "../labels.js";
4
- import { containsPoint, intersects, pointsBounds, } from "./primitives.js";
5
- export { containsPoint, emptyBounds, extend, intersects, pointsBounds, } from "./primitives.js";
1
+ import { polygonContour } from "./polygon-curves.js";
2
+ import { 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";
5
+ import { seatCategoryId } from "../categories.js";
6
+ import { containsPoint, intersects, pointsBounds } from "./primitives.js";
7
+ export { containsPoint, emptyBounds, extend, intersects, pointsBounds } from "./primitives.js";
6
8
  import { prepareBoundary, footprintInBoundary } from "./boundary.js";
7
9
  export const identityMatrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
8
10
  export const radians = (value) => (value * Math.PI) / 180;
@@ -80,21 +82,26 @@ export function worldMatrices(document) {
80
82
  };
81
83
  for (const c of document.collections)
82
84
  resolve(c.id);
83
- for (const entity of [
84
- ...document.seatingGroups,
85
- ...document.areas,
86
- ...document.decorations,
87
- ])
85
+ for (const entity of [...document.seatingGroups, ...document.areas, ...document.decorations])
88
86
  result.set(entity.id, multiply(entity.parentId ? resolve(entity.parentId) : identityMatrix, transformMatrix(entity.transform)));
89
87
  return result;
90
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
+ }
91
98
  export function* generateGroup(group) {
92
- const emit = (slot, p, rotationDeg, label, ownerLabel, rowId) => ({
99
+ const emit = (slot, p, rotationDeg, label, ownerLabel, rowId, aisle = false, categoryId = seatCategoryId(group, slot)) => ({
93
100
  id: slot.id,
94
101
  groupId: group.id,
95
102
  rowId,
96
- sectionId: group.sectionId,
97
103
  label: slot.labelOverride ?? label,
104
+ bookingLabel: label,
98
105
  ownerLabel,
99
106
  position: {
100
107
  x: p.x + (slot.override?.offsetM?.x ?? 0),
@@ -103,38 +110,42 @@ export function* generateGroup(group) {
103
110
  rotationDeg: normalizeAngle(rotationDeg + (slot.override?.rotationDeltaDeg ?? 0)),
104
111
  size: slot.override?.sizeM ?? group.seatSizeM,
105
112
  slot,
113
+ aisle,
114
+ categoryId,
106
115
  });
107
- if (group.kind === SeatingKind.Straight ||
108
- group.kind === SeatingKind.Curved) {
116
+ if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved) {
109
117
  const longestRow = group.rows.reduce((max, row) => Math.max(max, row.seats.length), 0);
110
118
  for (let r = 0; r < group.rows.length; r++) {
111
119
  const row = group.rows[r];
112
- const owner = row.labelOverride ??
113
- sequenceLabel(group.labels.rows, r, group.rows.length);
120
+ const owner = rowDisplayLabel(group, r);
114
121
  for (let i = 0; i < row.seats.length; i++) {
115
- const geometry = rowSeatGeometry(group, r, i, row.seats.length, longestRow);
122
+ const geometry = rowSeatGeometry(group, r, i, row.seats.length, longestRow, row.layout);
116
123
  let p = geometry.position;
117
124
  const rotation = geometry.rotationDeg;
118
125
  p = { x: p.x + (row.offsetM?.x ?? 0), y: p.y + (row.offsetM?.y ?? 0) };
119
- yield emit(row.seats[i], p, rotation, sequenceLabel(row.seatSequenceOverride ?? group.labels.seats, i, row.seats.length), owner, row.id);
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
+ yield seat;
120
129
  }
121
130
  }
122
131
  }
123
132
  else if (group.kind === SeatingKind.Round) {
124
133
  for (let i = 0; i < group.chairs.length; i++) {
125
134
  const geometry = roundChairGeometry(group.recipe, group.seatSizeM.height, i, group.chairs.length);
126
- 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);
127
136
  }
128
137
  }
129
138
  else {
130
- const sides = Object.values(TableSide);
139
+ const sides = group.recipe.chairDistribution === TableChairDistribution.EqualSegments
140
+ ? [TableSide.Top, TableSide.Bottom, TableSide.Left, TableSide.Right]
141
+ : Object.values(TableSide);
131
142
  const total = sides.reduce((n, s) => n + group.chairsBySide[s].length, 0);
132
143
  let ordinal = 0;
133
144
  for (const side of sides) {
134
145
  const list = group.chairsBySide[side];
135
146
  for (let i = 0; i < list.length; i++) {
136
147
  const geometry = rectangularChairGeometry(group.recipe, group.seatSizeM.height, side, i, list.length);
137
- 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);
138
149
  }
139
150
  }
140
151
  }
@@ -153,8 +164,7 @@ export function footprint(seat, world = identityMatrix) {
153
164
  }
154
165
  function crosses(a, b, c, d) {
155
166
  const side = (p, q, r) => (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x);
156
- return (side(a, b, c) * side(a, b, d) < -1e-12 &&
157
- 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;
158
168
  }
159
169
  export function footprintInside(points, polygon) {
160
170
  return footprintInBoundary(prepareBoundary(polygon), points);
@@ -164,7 +174,7 @@ export function invalidPolygon(polygon) {
164
174
  const cached = polygonValidity.get(polygon);
165
175
  if (cached !== undefined)
166
176
  return cached;
167
- const result = calculateInvalidPolygon(polygon);
177
+ const result = calculateInvalidPolygon(polygonContour(polygon));
168
178
  polygonValidity.set(polygon, result);
169
179
  return result;
170
180
  }
@@ -191,8 +201,7 @@ function calculateInvalidPolygon(polygon) {
191
201
  for (let i = 0; i < edges.length; i++)
192
202
  for (let j = i + 1; j < edges.length && edges[j].bounds.minX <= edges[i].bounds.maxX; j++) {
193
203
  const a = edges[i], b = edges[j];
194
- if (Math.abs(a.index - b.index) === 1 ||
195
- 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)
196
205
  continue;
197
206
  if (intersects(a.bounds, b.bounds) &&
198
207
  (crosses(a.a, a.b, b.a, b.b) ||
@@ -0,0 +1,12 @@
1
+ import type { PointM, PolygonM } from "../physical-document.interface.js";
2
+ export declare const PolygonVertexLimit = 10000;
3
+ export declare const PolygonCornerRadiusMaxM = 2.75;
4
+ /** Quadratic control lies at the chord midpoint plus its signed, dimensionless normal offset. */
5
+ export declare function sideCurvePoint(start: PointM, end: PointM, curvature: number, fraction: number): PointM;
6
+ /** Uniform quadratic subdivision bounds the chord deviation by the existing 1mm curve tolerance. */
7
+ export declare function sideCurveSegments(start: PointM, end: PointM, curvature: number): number;
8
+ /** A rounding input takes effect when at least one authored corner can use it. */
9
+ export declare function effectiveCornerRounding(polygon: PolygonM): number;
10
+ export declare function polygonContourVertexCount(polygon: PolygonM): number;
11
+ /** Authored corners remain stable; all geometric consumers share one derived, immutable contour. */
12
+ export declare function polygonContour(polygon: PolygonM): PolygonM;
@@ -0,0 +1,132 @@
1
+ import { CurveToleranceM } from "./ellipse.js";
2
+ export const PolygonVertexLimit = 10_000;
3
+ export const PolygonCornerRadiusMaxM = 2.75;
4
+ const contours = new WeakMap();
5
+ /** Quadratic control lies at the chord midpoint plus its signed, dimensionless normal offset. */
6
+ export function sideCurvePoint(start, end, curvature, fraction) {
7
+ const x = end.x - start.x, y = end.y - start.y;
8
+ const bow = (2 * fraction * (1 - fraction) * curvature) / 100;
9
+ return { x: start.x + fraction * x - bow * y, y: start.y + fraction * y + bow * x };
10
+ }
11
+ /** Uniform quadratic subdivision bounds the chord deviation by the existing 1mm curve tolerance. */
12
+ export function sideCurveSegments(start, end, curvature) {
13
+ const sagitta = (Math.abs(curvature) * Math.hypot(end.x - start.x, end.y - start.y)) / 200;
14
+ return Math.max(1, Math.ceil(Math.sqrt(sagitta / CurveToleranceM)));
15
+ }
16
+ function cornerFillet(previous, point, next, strengthSquared, radiusM) {
17
+ const incomingX = point.x - previous.x;
18
+ const incomingY = point.y - previous.y;
19
+ const outgoingX = next.x - point.x;
20
+ const outgoingY = next.y - point.y;
21
+ const incomingLength = Math.hypot(incomingX, incomingY);
22
+ const outgoingLength = Math.hypot(outgoingX, outgoingY);
23
+ const sweep = Math.atan2(incomingX * outgoingY - incomingY * outgoingX, incomingX * outgoingX + incomingY * outgoingY);
24
+ if (!incomingLength || !outgoingLength || Math.abs(sweep) < 1e-9)
25
+ return null;
26
+ const halfTurn = Math.tan(Math.abs(sweep) / 2);
27
+ const shortestSide = Math.min(incomingLength, outgoingLength);
28
+ let trim;
29
+ if (radiusM) {
30
+ trim = Math.min(shortestSide / 2, radiusM * halfTurn);
31
+ }
32
+ else {
33
+ // Fit the percentage activation threshold and tangent cut to the measured section profiles.
34
+ const activation = (2 / 3) * halfTurn + 0.02 * Math.cos(sweep);
35
+ if (strengthSquared <= activation)
36
+ return null;
37
+ trim = shortestSide * Math.min(0.49, (strengthSquared - activation) / (4 * halfTurn));
38
+ }
39
+ const radius = trim / halfTurn;
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
+ const signedRadius = Math.sign(sweep) * radius;
43
+ const center = {
44
+ x: before.x - (incomingY * signedRadius) / incomingLength,
45
+ y: before.y + (incomingX * signedRadius) / incomingLength,
46
+ };
47
+ const maxStep = 4 * Math.asin(Math.sqrt(Math.min(1, CurveToleranceM / (2 * radius))));
48
+ return { before, after, center, radius, sweep, segments: Math.max(1, Math.ceil(Math.abs(sweep) / maxStep)) };
49
+ }
50
+ function contourGeometry(polygon) {
51
+ const cached = contours.get(polygon);
52
+ if (cached)
53
+ return cached;
54
+ const strengthSquared = ((polygon.cornerRounding ?? 0) / 100) ** 2;
55
+ const radiusM = polygon.cornerRadiusM ?? 0;
56
+ const { outer } = polygon;
57
+ const corners = strengthSquared || radiusM
58
+ ? outer.map((point, index) => cornerFillet(outer[(index + outer.length - 1) % outer.length], point, outer[(index + 1) % outer.length], strengthSquared, radiusM))
59
+ : [];
60
+ const geometry = { corners };
61
+ contours.set(polygon, geometry);
62
+ return geometry;
63
+ }
64
+ /** A rounding input takes effect when at least one authored corner can use it. */
65
+ export function effectiveCornerRounding(polygon) {
66
+ return polygon.cornerRounding && contourGeometry(polygon).corners.some(Boolean) ? polygon.cornerRounding : 0;
67
+ }
68
+ function contourSpanSegments(polygon, corners, side) {
69
+ const next = (side + 1) % polygon.outer.length;
70
+ const start = polygon.outer[side];
71
+ const end = polygon.outer[next];
72
+ const curvature = polygon.edgeCurvature?.[side] ?? 0;
73
+ const from = corners[side]?.after;
74
+ const to = corners[next]?.before;
75
+ if (!curvature && from && to && Math.hypot(to.x - from.x, to.y - from.y) < 1e-9)
76
+ return 0;
77
+ return sideCurveSegments(start, end, curvature);
78
+ }
79
+ export function polygonContourVertexCount(polygon) {
80
+ const { outer, edgeCurvature } = polygon;
81
+ if (!polygon.cornerRounding && !polygon.cornerRadiusM && !edgeCurvature)
82
+ return outer.length;
83
+ const { corners } = contourGeometry(polygon);
84
+ return outer.reduce((total, _, side) => total + (corners[side]?.segments ?? 0) + contourSpanSegments(polygon, corners, side), 0);
85
+ }
86
+ /** Authored corners remain stable; all geometric consumers share one derived, immutable contour. */
87
+ export function polygonContour(polygon) {
88
+ const curved = polygon.edgeCurvature?.some((value) => value !== 0);
89
+ if (!polygon.cornerRounding && !polygon.cornerRadiusM && !curved)
90
+ return polygon;
91
+ const geometry = contourGeometry(polygon);
92
+ if (geometry.contour)
93
+ return geometry.contour;
94
+ const { corners } = geometry;
95
+ if (!curved && !corners.some(Boolean))
96
+ return polygon;
97
+ if (polygonContourVertexCount(polygon) > PolygonVertexLimit)
98
+ throw new RangeError("The boundary exceeds the 1mm / 10,000-vertex curve limit.");
99
+ const outer = polygon.outer.flatMap((start, side) => {
100
+ const next = (side + 1) % polygon.outer.length;
101
+ const end = polygon.outer[next];
102
+ const corner = corners[side];
103
+ const trimmedStart = corner?.after ?? start;
104
+ const trimmedEnd = corners[next]?.before ?? end;
105
+ const startAngle = corner ? Math.atan2(corner.before.y - corner.center.y, corner.before.x - corner.center.x) : 0;
106
+ const arc = corner
107
+ ? Array.from({ length: corner.segments }, (_, index) => {
108
+ if (index === 0)
109
+ return corner.before;
110
+ const angle = startAngle + (corner.sweep * index) / corner.segments;
111
+ return {
112
+ x: corner.center.x + corner.radius * Math.cos(angle),
113
+ y: corner.center.y + corner.radius * Math.sin(angle),
114
+ };
115
+ })
116
+ : [];
117
+ const curvature = polygon.edgeCurvature?.[side] ?? 0;
118
+ const segments = contourSpanSegments(polygon, corners, side);
119
+ const span = Array.from({ length: segments }, (_, index) => {
120
+ const t = index / segments;
121
+ const point = sideCurvePoint(start, end, curvature, t);
122
+ // Trim the span without changing the authored side's bow vector.
123
+ return {
124
+ x: point.x + (1 - t) * (trimmedStart.x - start.x) + t * (trimmedEnd.x - end.x),
125
+ y: point.y + (1 - t) * (trimmedStart.y - start.y) + t * (trimmedEnd.y - end.y),
126
+ };
127
+ });
128
+ return [...arc, ...span];
129
+ });
130
+ geometry.contour = { outer, holes: polygon.holes };
131
+ return geometry.contour;
132
+ }
@@ -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;
@@ -0,0 +1,24 @@
1
+ import { SeatShape } from "../physical-document.interface.js";
2
+ export declare enum SeatShapePartKind {
3
+ Rectangle = "rectangle",
4
+ Polygon = "polygon"
5
+ }
6
+ export type SeatShapePart = {
7
+ kind: SeatShapePartKind.Rectangle;
8
+ x: number;
9
+ y: number;
10
+ width: number;
11
+ height: number;
12
+ radius: number;
13
+ } | {
14
+ kind: SeatShapePartKind.Polygon;
15
+ points: readonly number[];
16
+ };
17
+ export declare function seatShapeParts(shape: SeatShape): readonly SeatShapePart[];
18
+ /**
19
+ * @method seatShapeContour
20
+ * @description Reuses bounded normalized contours so small furniture corners stay smooth after scaling.
21
+ * @param {SeatShapePart} part Shared normalized furniture primitive.
22
+ * @returns {readonly number[]} Cached polygon coordinates for the primitive.
23
+ */
24
+ export declare function seatShapeContour(part: SeatShapePart): readonly number[];