@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
@@ -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";
@@ -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,19 @@ export declare enum TableSide {
6
6
  Bottom = "bottom",
7
7
  Left = "left"
8
8
  }
9
+ export declare function rowStaggerOffset(recipe: StraightRows["recipe"], index: number): number;
10
+ /** A lane shift is derived from the recipe. The row offset remains an independent edit. */
11
+ export declare function rowPlacementOffset(group: RowsGeometry, index: number, offset?: PointM): PointM;
9
12
  export type SeatGeometry = {
10
13
  position: PointM;
11
14
  rotationDeg: number;
12
15
  };
13
16
  export declare function rowSeatGeometry(group: RowsGeometry, row: number, seat: number, count: number, longestRow?: number, layout?: RowLayout): SeatGeometry;
17
+ /** The row axis is independent of its chair-facing offset. */
18
+ export declare function rowLayoutAxisRotation(layout: RowLayout): number;
19
+ export declare function setRowLayoutAxisRotation(layout: RowLayout, rotationDeg: number): RowLayout;
20
+ /** Curve edits preserve the row axis and its independent chair-facing offset. */
21
+ export declare function setRowLayoutCurve(layout: RowLayout, curveDeg: number): RowLayout;
14
22
  /** Resolves inherited geometry once when a row becomes independently editable. */
15
23
  export declare function resolveRowLayout(group: StraightRows | CurvedRows, rowIndex: number): RowLayout | null;
16
24
  export declare function roundChairGeometry(recipe: RoundTable["recipe"], chairHeightM: number, seat: number, count: number): SeatGeometry;
@@ -1,4 +1,4 @@
1
- import { CurveMode, TableChairDistribution, RowAlignment, SeatingKind, } from "../types.js";
1
+ import { CurveMode, TableChairDistribution, RowAlignment, RowStagger, SeatingKind, } from "../physical-document.interface.js";
2
2
  import { ellipseAngleAtDistance } from "./ellipse.js";
3
3
  export var TableSide;
4
4
  (function (TableSide) {
@@ -7,30 +7,31 @@ export var TableSide;
7
7
  TableSide["Bottom"] = "bottom";
8
8
  TableSide["Left"] = "left";
9
9
  })(TableSide || (TableSide = {}));
10
+ export function rowStaggerOffset(recipe, index) {
11
+ const lane = index % 2 === 0 ? RowStagger.First : RowStagger.Second;
12
+ return recipe.stagger === lane ? recipe.seatPitchM / 2 : 0;
13
+ }
14
+ /** A lane shift is derived from the recipe. The row offset remains an independent edit. */
15
+ export function rowPlacementOffset(group, index, offset) {
16
+ return {
17
+ x: (offset?.x ?? 0) + (group.kind === SeatingKind.Straight ? rowStaggerOffset(group.recipe, index) : 0),
18
+ y: offset?.y ?? 0,
19
+ };
20
+ }
10
21
  export function rowSeatGeometry(group, row, seat, count, longestRow = count, layout) {
11
22
  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;
23
+ const halfStep = (layout.curveDeg * Math.PI) / (360 * Math.max(1, count - 1));
24
+ const halfAngle = seat * halfStep;
25
+ // The pitch is a straight-line gap between adjacent seat centres.
26
+ const chord = halfStep ? Math.sin(halfAngle) / Math.sin(halfStep) : seat;
27
+ const distance = layout.seatPitchM * chord;
28
+ const direction = (layout.rotationDeg * Math.PI) / 180 - halfAngle;
26
29
  return {
27
30
  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),
31
+ x: layout.originM.x + distance * Math.cos(direction),
32
+ y: layout.originM.y + distance * Math.sin(direction),
30
33
  },
31
- rotationDeg: layout.rotationDeg -
32
- (angle * 180) / Math.PI +
33
- (layout.seatRotationOffsetDeg ?? 0),
34
+ rotationDeg: layout.rotationDeg - (halfAngle * 360) / Math.PI + (layout.seatRotationOffsetDeg ?? 0),
34
35
  };
35
36
  }
36
37
  if (group.kind === SeatingKind.Straight)
@@ -49,27 +50,50 @@ export function rowSeatGeometry(group, row, seat, count, longestRow = count, lay
49
50
  rotationDeg: 0,
50
51
  };
51
52
  const radius = group.recipe.innerRadiusM + row * group.recipe.rowPitchM;
52
- const horizontal = group.recipe.innerRadiusM * (group.recipe.axisRatio ?? 1) +
53
- row * group.recipe.rowPitchM;
53
+ const horizontal = group.recipe.innerRadiusM * (group.recipe.axisRatio ?? 1) + row * group.recipe.rowPitchM;
54
54
  const p = group.recipe.placement;
55
55
  const angle = p.kind === CurveMode.Pitch
56
56
  ? ellipseAngleAtDistance(horizontal, radius, (p.centerAngleDeg * Math.PI) / 180, (seat - (count - 1) / 2) * p.seatPitchM)
57
57
  : ((p.startAngleDeg +
58
58
  (count === 1
59
59
  ? p.sweepAngleDeg / 2
60
- : (p.sweepAngleDeg * seat) /
61
- (Math.abs(p.sweepAngleDeg) === 360 ? count : count - 1))) *
60
+ : (p.sweepAngleDeg * seat) / (Math.abs(p.sweepAngleDeg) === 360 ? count : count - 1))) *
62
61
  Math.PI) /
63
62
  180;
64
63
  return {
65
64
  position: { x: horizontal * Math.cos(angle), y: radius * Math.sin(angle) },
66
65
  rotationDeg: horizontal === radius
67
66
  ? (angle * 180) / Math.PI + 90
68
- : (Math.atan2(radius * Math.cos(angle), -horizontal * Math.sin(angle)) *
69
- 180) /
70
- Math.PI,
67
+ : (Math.atan2(radius * Math.cos(angle), -horizontal * Math.sin(angle)) * 180) / Math.PI,
68
+ };
69
+ }
70
+ function normalizeRowAngle(rotationDeg) {
71
+ return ((((rotationDeg + 180) % 360) + 360) % 360) - 180;
72
+ }
73
+ function rowCurveAxisOffset(curveDeg) {
74
+ return curveDeg < 0 ? 180 : 0;
75
+ }
76
+ /** The row axis is independent of its chair-facing offset. */
77
+ export function rowLayoutAxisRotation(layout) {
78
+ return layout.rotationDeg - rowCurveAxisOffset(layout.curveDeg);
79
+ }
80
+ export function setRowLayoutAxisRotation(layout, rotationDeg) {
81
+ const rotation = rotationDeg + rowCurveAxisOffset(layout.curveDeg);
82
+ return {
83
+ ...layout,
84
+ rotationDeg: normalizeRowAngle(rotation),
71
85
  };
72
86
  }
87
+ /** Curve edits preserve the row axis and its independent chair-facing offset. */
88
+ export function setRowLayoutCurve(layout, curveDeg) {
89
+ const axisRotation = rowLayoutAxisRotation(layout);
90
+ const facingOffset = layout.rotationDeg + (layout.seatRotationOffsetDeg ?? 0) - axisRotation;
91
+ return setRowLayoutAxisRotation({
92
+ ...layout,
93
+ curveDeg,
94
+ seatRotationOffsetDeg: normalizeRowAngle(facingOffset - rowCurveAxisOffset(curveDeg)),
95
+ }, axisRotation);
96
+ }
73
97
  /** Resolves inherited geometry once when a row becomes independently editable. */
74
98
  export function resolveRowLayout(group, rowIndex) {
75
99
  const row = group.rows[rowIndex];
@@ -84,43 +108,32 @@ export function resolveRowLayout(group, rowIndex) {
84
108
  originM: first.position,
85
109
  seatPitchM: group.recipe.seatPitchM,
86
110
  curveDeg: 0,
87
- rotationDeg: ((((first.rotationDeg + 180) % 360) + 360) % 360) - 180,
111
+ rotationDeg: normalizeRowAngle(first.rotationDeg),
88
112
  };
89
113
  const radius = group.recipe.innerRadiusM + rowIndex * group.recipe.rowPitchM;
90
114
  const placement = group.recipe.placement;
91
115
  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;
116
+ const sweep = placement.kind === CurveMode.Pitch
117
+ ? (((intervals * placement.seatPitchM) / radius) * 180) / Math.PI
118
+ : placement.sweepAngleDeg * (Math.abs(placement.sweepAngleDeg) === 360 ? intervals / row.seats.length : 1);
119
+ let pitch = placement.kind === CurveMode.Pitch ? placement.seatPitchM : 0.55;
120
+ if (intervals) {
121
+ const second = rowSeatGeometry(group, rowIndex, 1, row.seats.length, longest).position;
122
+ pitch = Math.hypot(second.x - first.position.x, second.y - first.position.y);
107
123
  }
108
124
  const tangent = first.rotationDeg + (sweep < 0 ? 180 : 0);
109
125
  return {
110
126
  originM: first.position,
111
127
  seatPitchM: pitch,
112
128
  curveDeg: -sweep,
113
- rotationDeg: ((((tangent + 180) % 360) + 360) % 360) - 180,
129
+ rotationDeg: normalizeRowAngle(tangent),
114
130
  ...(sweep < 0 ? { seatRotationOffsetDeg: -180 } : {}),
115
131
  };
116
132
  }
117
133
  export function roundChairGeometry(recipe, chairHeightM, seat, count) {
118
134
  const radius = recipe.diameterM / 2 + recipe.chairGapM + chairHeightM / 2;
119
135
  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));
136
+ const angle = recipe.startAngleDeg + (count === 1 ? 0 : (360 - arc) / 2 + (arc * seat) / (arc === 360 ? count : count - 1));
124
137
  return {
125
138
  position: {
126
139
  x: radius * Math.cos((angle * Math.PI) / 180),
@@ -152,9 +165,7 @@ export function rectangularChairGeometry(recipe, chairHeightM, side, seat, count
152
165
  case TableSide.Bottom:
153
166
  return {
154
167
  position: {
155
- x: recipe.chairDistribution === TableChairDistribution.EqualSegments
156
- ? along
157
- : -along,
168
+ x: recipe.chairDistribution === TableChairDistribution.EqualSegments ? along : -along,
158
169
  y: recipe.depthM / 2 + gap,
159
170
  },
160
171
  rotationDeg: -90,
@@ -163,9 +174,7 @@ export function rectangularChairGeometry(recipe, chairHeightM, side, seat, count
163
174
  return {
164
175
  position: {
165
176
  x: -recipe.widthM / 2 - gap,
166
- y: recipe.chairDistribution === TableChairDistribution.EqualSegments
167
- ? along
168
- : -along,
177
+ y: recipe.chairDistribution === TableChairDistribution.EqualSegments ? along : -along,
169
178
  },
170
179
  rotationDeg: 0,
171
180
  };
@@ -179,8 +188,7 @@ export function* previewSeats(layout) {
179
188
  switch (layout.kind) {
180
189
  case SeatingKind.Straight:
181
190
  case SeatingKind.Curved: {
182
- const longestRow = layout.rowCounts?.reduce((max, count) => Math.max(max, count), 0) ??
183
- layout.seatsPerRow;
191
+ const longestRow = layout.rowCounts?.reduce((max, count) => Math.max(max, count), 0) ?? layout.seatsPerRow;
184
192
  for (let row = 0; row < layout.rows; row++)
185
193
  for (let seat = 0; seat < (layout.rowCounts?.[row] ?? layout.seatsPerRow); seat++)
186
194
  yield {
@@ -203,7 +211,8 @@ export function* previewSeats(layout) {
203
211
  for (const side of Object.values(TableSide))
204
212
  for (let seat = 0; seat < layout.sides[side]; seat++)
205
213
  yield {
206
- position: rectangularChairGeometry(layout.recipe, layout.seatSizeM, side, seat, layout.sides[side]).position,
214
+ position: rectangularChairGeometry(layout.recipe, layout.seatSizeM, side, seat, layout.sides[side])
215
+ .position,
207
216
  row: null,
208
217
  ordinal: ++ordinal,
209
218
  };
@@ -0,0 +1,8 @@
1
+ export declare const LayoutUnitM: number;
2
+ /**
3
+ * @method toLayoutUnits
4
+ * @description Convert through the authored scale without rounding precise geometry to a canvas grid.
5
+ * @param {number} distanceM - Distance in metres.
6
+ * @returns {number} Distance in authoring layout units.
7
+ */
8
+ export declare function toLayoutUnits(distanceM: number): number;
@@ -0,0 +1,13 @@
1
+ const layoutScaleM = 0.55;
2
+ const layoutScaleUnits = 24;
3
+ // Standard authoring scale: 24 canvas units span a 0.55m seat pitch.
4
+ export const LayoutUnitM = layoutScaleM / layoutScaleUnits;
5
+ /**
6
+ * @method toLayoutUnits
7
+ * @description Convert through the authored scale without rounding precise geometry to a canvas grid.
8
+ * @param {number} distanceM - Distance in metres.
9
+ * @returns {number} Distance in authoring layout units.
10
+ */
11
+ export function toLayoutUnits(distanceM) {
12
+ return (distanceM / layoutScaleM) * layoutScaleUnits;
13
+ }
@@ -1,21 +1,7 @@
1
- import type { PointM, PolygonM } from "../types.js";
2
- export declare enum OutlineKind {
3
- Rectangle = "rectangle",
4
- Ellipse = "ellipse",
5
- Sector = "sector",
6
- Envelope = "envelope"
7
- }
8
- export type OutlineParameters = {
9
- kind: Exclude<OutlineKind, "envelope">;
10
- center: PointM;
11
- radiusX: number;
12
- radiusY: number;
13
- innerRatio: number;
14
- startDeg: number;
15
- sweepDeg: number;
16
- };
1
+ import type { PointM, PolygonM } from "../physical-document.interface.js";
2
+ import { type OutlineParameters } from "./venue-outline.interface.js";
17
3
  export declare function sampledOutline(p: OutlineParameters): PolygonM;
18
4
  /** Conservative convex envelope, with no invented architectural voids. */
19
5
  export declare function memberEnvelope(points: readonly PointM[], paddingM?: number): PolygonM;
20
- /** Deterministic widest interior scan interval; holes participate in every scan. */
21
- export declare function interiorLabelPoint(polygon: PolygonM): PointM;
6
+ /** Maximum-clearance interior anchor. Holes and curved contours share the same geometry owner. */
7
+ export declare function interiorLabelPoint(source: PolygonM): PointM;
@@ -0,0 +1,23 @@
1
+ import type { PointM } from "../physical-document.interface.js";
2
+ export declare enum OutlineKind {
3
+ Rectangle = "rectangle",
4
+ Ellipse = "ellipse",
5
+ Sector = "sector",
6
+ Envelope = "envelope"
7
+ }
8
+ export type OutlineParameters = {
9
+ kind: Exclude<OutlineKind, OutlineKind.Envelope>;
10
+ center: PointM;
11
+ radiusX: number;
12
+ radiusY: number;
13
+ innerRatio: number;
14
+ startDeg: number;
15
+ sweepDeg: number;
16
+ };
17
+ export interface InteriorLabelCell {
18
+ center: PointM;
19
+ halfWidthM: number;
20
+ halfHeightM: number;
21
+ distanceM: number;
22
+ maximumM: number;
23
+ }
@@ -0,0 +1,7 @@
1
+ export var OutlineKind;
2
+ (function (OutlineKind) {
3
+ OutlineKind["Rectangle"] = "rectangle";
4
+ OutlineKind["Ellipse"] = "ellipse";
5
+ OutlineKind["Sector"] = "sector";
6
+ OutlineKind["Envelope"] = "envelope";
7
+ })(OutlineKind || (OutlineKind = {}));
@@ -1,22 +1,11 @@
1
+ import { polygonContour } from "./polygon-curves.js";
1
2
  import { pointsBounds, containsPoint } from "./primitives.js";
2
3
  import { ellipseSegments } from "./ellipse.js";
3
- export var OutlineKind;
4
- (function (OutlineKind) {
5
- OutlineKind["Rectangle"] = "rectangle";
6
- OutlineKind["Ellipse"] = "ellipse";
7
- OutlineKind["Sector"] = "sector";
8
- OutlineKind["Envelope"] = "envelope";
9
- })(OutlineKind || (OutlineKind = {}));
4
+ import TinyQueue from "tinyqueue";
5
+ import { LayoutUnitM } from "./units.js";
6
+ import { OutlineKind } from "./venue-outline.interface.js";
10
7
  export function sampledOutline(p) {
11
- if (![
12
- p.center.x,
13
- p.center.y,
14
- p.radiusX,
15
- p.radiusY,
16
- p.innerRatio,
17
- p.startDeg,
18
- p.sweepDeg,
19
- ].every(Number.isFinite) ||
8
+ if (![p.center.x, p.center.y, p.radiusX, p.radiusY, p.innerRatio, p.startDeg, p.sweepDeg].every(Number.isFinite) ||
20
9
  p.radiusX <= 0 ||
21
10
  p.radiusY <= 0 ||
22
11
  p.innerRatio < 0 ||
@@ -38,9 +27,7 @@ export function sampledOutline(p) {
38
27
  ],
39
28
  holes: [],
40
29
  };
41
- const sweep = p.kind === OutlineKind.Ellipse
42
- ? Math.PI * 2
43
- : (p.sweepDeg * Math.PI) / 180, start = (p.startDeg * Math.PI) / 180, full = Math.abs(sweep) === Math.PI * 2;
30
+ const sweep = p.kind === OutlineKind.Ellipse ? Math.PI * 2 : (p.sweepDeg * Math.PI) / 180, start = (p.startDeg * Math.PI) / 180, full = Math.abs(sweep) === Math.PI * 2;
44
31
  const count = ellipseSegments(p.radiusX, p.radiusY, sweep);
45
32
  const arc = (ratio) => Array.from({ length: count + (full ? 0 : 1) }, (_, i) => point(start + (sweep * i) / count, ratio));
46
33
  const outer = arc(1);
@@ -49,10 +36,7 @@ export function sampledOutline(p) {
49
36
  outer,
50
37
  holes: p.innerRatio > 0 ? [arc(p.innerRatio).reverse()] : [],
51
38
  };
52
- const ring = [
53
- ...outer,
54
- ...(p.innerRatio > 0 ? arc(p.innerRatio).reverse() : [p.center]),
55
- ];
39
+ const ring = [...outer, ...(p.innerRatio > 0 ? arc(p.innerRatio).reverse() : [p.center])];
56
40
  if (ring.length > 10000)
57
41
  throw new Error("The sector exceeds the 10,000-vertex limit at 1mm accuracy.");
58
42
  return { outer: ring, holes: [] };
@@ -73,8 +57,7 @@ export function memberEnvelope(points, paddingM = 0.15) {
73
57
  const half = (input) => {
74
58
  const result = [];
75
59
  for (const p of input) {
76
- while (result.length > 1 &&
77
- cross(result[result.length - 2], result[result.length - 1], p) <= 0)
60
+ while (result.length > 1 && cross(result[result.length - 2], result[result.length - 1], p) <= 0)
78
61
  result.pop();
79
62
  result.push(p);
80
63
  }
@@ -88,33 +71,108 @@ export function memberEnvelope(points, paddingM = 0.15) {
88
71
  throw new Error("The envelope exceeds the boundary vertex limit.");
89
72
  return { outer, holes: [] };
90
73
  }
91
- /** Deterministic widest interior scan interval; holes participate in every scan. */
92
- export function interiorLabelPoint(polygon) {
93
- const bounds = pointsBounds(polygon.outer), inside = (p) => containsPoint(polygon.outer, p) &&
94
- !polygon.holes.some((h) => containsPoint(h, p));
95
- const center = {
96
- x: (bounds.minX + bounds.maxX) / 2,
97
- y: (bounds.minY + bounds.maxY) / 2,
74
+ const labelSearchPrecisionM = 1.5 * LayoutUnitM;
75
+ const labelInitialCellLimit = 64;
76
+ const labelSearchRoundoff = 16 * Number.EPSILON;
77
+ const labelPoints = new WeakMap();
78
+ function outlineClearance(polygon, point) {
79
+ let distanceSquared = Infinity;
80
+ for (const ring of [polygon.outer, ...polygon.holes]) {
81
+ for (let index = 0; index < ring.length; index++) {
82
+ const start = ring[index], end = ring[(index + 1) % ring.length];
83
+ const dx = end.x - start.x, dy = end.y - start.y;
84
+ const lengthSquared = dx * dx + dy * dy;
85
+ const fraction = lengthSquared === 0
86
+ ? 0
87
+ : Math.max(0, Math.min(1, ((point.x - start.x) * dx + (point.y - start.y) * dy) / lengthSquared));
88
+ const x = point.x - start.x - fraction * dx, y = point.y - start.y - fraction * dy;
89
+ distanceSquared = Math.min(distanceSquared, x * x + y * y);
90
+ }
91
+ }
92
+ const inside = containsPoint(polygon.outer, point) && !polygon.holes.some((hole) => containsPoint(hole, point));
93
+ return Math.sqrt(distanceSquared) * (inside ? 1 : -1);
94
+ }
95
+ function outlineCentroid(polygon) {
96
+ let area = 0, x = 0, y = 0;
97
+ const ring = polygon.outer;
98
+ const origin = ring[0];
99
+ for (let index = 0; index < ring.length; index++) {
100
+ const start = ring[index], end = ring[(index + 1) % ring.length];
101
+ const startX = start.x - origin.x, startY = start.y - origin.y;
102
+ const endX = end.x - origin.x, endY = end.y - origin.y;
103
+ const cross = startX * endY - endX * startY;
104
+ area += cross;
105
+ x += (startX + endX) * cross;
106
+ y += (startY + endY) * cross;
107
+ }
108
+ return area === 0 ? origin : { x: origin.x + x / (3 * area), y: origin.y + y / (3 * area) };
109
+ }
110
+ /** Maximum-clearance interior anchor. Holes and curved contours share the same geometry owner. */
111
+ export function interiorLabelPoint(source) {
112
+ const cached = labelPoints.get(source);
113
+ if (cached)
114
+ return cached;
115
+ const polygon = polygonContour(source);
116
+ const bounds = pointsBounds(polygon.outer);
117
+ const width = bounds.maxX - bounds.minX, height = bounds.maxY - bounds.minY;
118
+ const roundoffM = Math.max(width, height, Math.abs(bounds.minX), Math.abs(bounds.minY), Math.abs(bounds.maxX), Math.abs(bounds.maxY)) * labelSearchRoundoff;
119
+ const cell = (center, halfWidthM, halfHeightM) => {
120
+ const distanceM = outlineClearance(polygon, center);
121
+ return { center, halfWidthM, halfHeightM, distanceM, maximumM: distanceM + Math.hypot(halfWidthM, halfHeightM) };
98
122
  };
99
- if (inside(center))
100
- return center;
101
- let result = polygon.outer[0] ?? { x: 0, y: 0 }, width = -1;
102
- for (let scan = 1; scan < 64; scan++) {
103
- const y = bounds.minY + ((bounds.maxY - bounds.minY) * scan) / 64, cuts = [];
104
- for (const ring of [polygon.outer, ...polygon.holes])
105
- for (let i = 0; i < ring.length; i++) {
106
- const a = ring[i], b = ring[(i + 1) % ring.length];
107
- if (a.y > y !== b.y > y)
108
- cuts.push(a.x + ((b.x - a.x) * (y - a.y)) / (b.y - a.y));
123
+ let best = cell(outlineCentroid(polygon), 0, 0);
124
+ const center = cell({ x: (bounds.minX + bounds.maxX) / 2, y: (bounds.minY + bounds.maxY) / 2 }, 0, 0);
125
+ if (center.distanceM > best.distanceM + roundoffM)
126
+ best = center;
127
+ // A boundary vertex is an admissible initial point when both centroids fall in a void.
128
+ if (best.distanceM < 0)
129
+ best = cell(polygon.outer[0], 0, 0);
130
+ // No inscribed circle can exceed half the smaller bounding-box dimension.
131
+ if (Math.min(width, height) / 2 - best.distanceM <= labelSearchPrecisionM) {
132
+ labelPoints.set(source, best.center);
133
+ return best.center;
134
+ }
135
+ const queue = new TinyQueue([], (left, right) => {
136
+ const difference = right.maximumM - left.maximumM;
137
+ // Symmetric cells must keep the same queue order across layout-unit/metre conversion.
138
+ return Math.abs(difference) <= roundoffM ? 0 : difference;
139
+ });
140
+ const smallerSpanM = Math.min(width, height);
141
+ const coarsening = 2 ** Math.max(0, Math.ceil(Math.log2(Math.max(width, height) / smallerSpanM / labelInitialCellLimit)));
142
+ const sizeM = Math.max(labelSearchPrecisionM, smallerSpanM * coarsening);
143
+ const halfWidthM = Math.min(sizeM, width) / 2, halfHeightM = Math.min(sizeM, height) / 2;
144
+ for (let x = bounds.minX; x < bounds.maxX; x += sizeM) {
145
+ for (let y = bounds.minY; y < bounds.maxY; y += sizeM) {
146
+ queue.push(cell({ x: x + halfWidthM, y: y + halfHeightM }, halfWidthM, halfHeightM));
147
+ }
148
+ }
149
+ while (queue.length) {
150
+ const current = queue.pop();
151
+ if (current.distanceM > best.distanceM + roundoffM)
152
+ best = current;
153
+ if (smallerSpanM / 2 - best.distanceM <= labelSearchPrecisionM)
154
+ break;
155
+ if (current.maximumM - best.distanceM <= labelSearchPrecisionM)
156
+ continue;
157
+ const halfWidth = current.halfWidthM / 2, halfHeight = current.halfHeightM / 2;
158
+ if (current.halfWidthM > current.halfHeightM) {
159
+ for (const dx of [-halfWidth, halfWidth]) {
160
+ queue.push(cell({ x: current.center.x + dx, y: current.center.y }, halfWidth, current.halfHeightM));
109
161
  }
110
- cuts.sort((a, b) => a - b);
111
- for (let i = 1; i < cuts.length; i++) {
112
- const p = { x: (cuts[i - 1] + cuts[i]) / 2, y }, span = cuts[i] - cuts[i - 1];
113
- if (span > width && inside(p)) {
114
- result = p;
115
- width = span;
162
+ }
163
+ else if (current.halfHeightM > current.halfWidthM) {
164
+ for (const dy of [-halfHeight, halfHeight]) {
165
+ queue.push(cell({ x: current.center.x, y: current.center.y + dy }, current.halfWidthM, halfHeight));
166
+ }
167
+ }
168
+ else {
169
+ for (const dy of [-halfHeight, halfHeight]) {
170
+ for (const dx of [-halfWidth, halfWidth]) {
171
+ queue.push(cell({ x: current.center.x + dx, y: current.center.y + dy }, halfWidth, halfHeight));
172
+ }
116
173
  }
117
174
  }
118
175
  }
119
- return result;
176
+ labelPoints.set(source, best.center);
177
+ return best.center;
120
178
  }
@@ -1,4 +1,6 @@
1
- import type { PhysicalDocumentV1 } from "./types.js";
1
+ import type { PhysicalDocumentV1 } from "./physical-document.interface.js";
2
+ /** Work reported by allocation, remapping and final document validation. Assets keep their IDs. */
3
+ export declare function remapDocumentWork(source: PhysicalDocumentV1): number;
2
4
  export declare function remapDocumentSteps(source: PhysicalDocumentV1, name: string): Generator<number, {
3
5
  document: PhysicalDocumentV1;
4
6
  warnings: string[];
package/dist/identity.js CHANGED
@@ -1,5 +1,31 @@
1
1
  import { z } from "zod";
2
- import { DocumentParseStatus, parsePhysicalDocument } from "./schema.js";
2
+ import { DocumentParseStatus, groupSeatCount, parsePhysicalDocument } from "./schema.js";
3
+ const identityFields = new Set([
4
+ "id",
5
+ "parentId",
6
+ "sectionId",
7
+ "companionForSeatId",
8
+ "assetId",
9
+ "categoryId",
10
+ "rowId",
11
+ "floorId",
12
+ "zoneId",
13
+ "gateId",
14
+ ]);
15
+ const identityRecordSchema = z.record(z.string(), z.unknown());
16
+ /** Work reported by allocation, remapping and final document validation. Assets keep their IDs. */
17
+ export function remapDocumentWork(source) {
18
+ const identities = source.sections.length +
19
+ source.collections.length +
20
+ source.areas.length +
21
+ source.decorations.length +
22
+ (source.floors?.length ?? 0) +
23
+ (source.zones?.length ?? 0) +
24
+ (source.segmentedRows?.length ?? 0) +
25
+ (source.categories?.reduce((total, category) => total + 1 + (category.ticketOptions?.length ?? 0), 0) ?? 0) +
26
+ source.seatingGroups.reduce((total, group) => total + 1 + groupSeatCount(group) + ("rows" in group ? group.rows.length : 0), 0);
27
+ return identities * 2 + source.assets.length + 1;
28
+ }
3
29
  export function* remapDocumentSteps(source, name) {
4
30
  const ids = new Map(), warnings = [];
5
31
  function* allocate(value) {
@@ -11,7 +37,7 @@ export function* remapDocumentSteps(source, name) {
11
37
  yield* allocate(child);
12
38
  return;
13
39
  }
14
- const record = z.record(z.string(), z.unknown()).parse(value);
40
+ const record = identityRecordSchema.parse(value);
15
41
  if (typeof record.id === "string")
16
42
  ids.set(record.id, crypto.randomUUID());
17
43
  yield typeof record.id === "string" ? 1 : 0;
@@ -29,13 +55,11 @@ export function* remapDocumentSteps(source, name) {
29
55
  return result;
30
56
  }
31
57
  if (value && typeof value === "object") {
32
- const record = z.record(z.string(), z.unknown()).parse(value);
58
+ const record = identityRecordSchema.parse(value);
33
59
  yield typeof record.id === "string" ? 1 : 0;
34
60
  const result = {};
35
61
  for (const [field, child] of Object.entries(record)) {
36
- if (field === "companionForSeatId" &&
37
- typeof child === "string" &&
38
- !ids.has(child)) {
62
+ if (field === "companionForSeatId" && typeof child === "string" && !ids.has(child)) {
39
63
  warnings.push("An external companion relationship was cleared.");
40
64
  continue;
41
65
  }
@@ -43,22 +67,13 @@ export function* remapDocumentSteps(source, name) {
43
67
  }
44
68
  return result;
45
69
  }
46
- if (typeof value === "string" &&
47
- [
48
- "id",
49
- "parentId",
50
- "sectionId",
51
- "companionForSeatId",
52
- "assetId",
53
- "categoryId",
54
- "rowId",
55
- ].includes(key))
70
+ if (typeof value === "string" && identityFields.has(key))
56
71
  return ids.get(value) ?? value;
57
72
  return value;
58
73
  }
59
74
  const remapped = yield* remap(source);
60
75
  const parsed = parsePhysicalDocument({
61
- ...z.record(z.string(), z.unknown()).parse(remapped),
76
+ ...identityRecordSchema.parse(remapped),
62
77
  mapId: crypto.randomUUID(),
63
78
  name,
64
79
  });