@seatmap-fyi/map-domain 0.1.0-alpha.55 → 0.1.0-alpha.56

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.
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { SectionOutlineRole, type PhysicalDocumentV1, type PointM, type PolygonM, type Section } from "./physical-document.interface.js";
2
+ import { SectionOutlineRole, type PhysicalDocumentV1, type PointM, type PolygonM, type Section, type UUID } from "./physical-document.interface.js";
3
3
  import { SectionFillDirection, SectionFillNumbering, type SectionFillInput, type SectionFillPlan, type SectionGrowInput } from "./section-fill.interface.js";
4
4
  export { SectionFillDirection, SectionFillNumbering, SectionFillStatus } from "./section-fill.interface.js";
5
5
  export type { SectionFillInput, SectionFillPart, SectionFillPlan, SectionFillRow, SectionFillReview, SectionGrowInput, } from "./section-fill.interface.js";
@@ -49,16 +49,27 @@ export declare const sectionGrowInputSchema: z.ZodObject<{
49
49
  }, z.core.$strict>;
50
50
  }, z.core.$strict>;
51
51
  export declare function sectionFillFocalPoint(document: PhysicalDocumentV1, section: Section): PointM;
52
+ /**
53
+ * @method planFillForSection
54
+ * @description Plan rows in the part of the section available under the document's inventory ownership order.
55
+ * @param {PhysicalDocumentV1} document - Current physical document.
56
+ * @param {Section & { outline: PolygonM }} section - Section with an authored outline.
57
+ * @param {SectionFillInput} request - Capacity, spacing and orientation settings.
58
+ * @returns {SectionFillPlan} Preview and capacity for the selected section.
59
+ */
60
+ export declare function planFillForSection(document: PhysicalDocumentV1, section: Section & {
61
+ outline: PolygonM;
62
+ }, request: SectionFillInput): SectionFillPlan;
52
63
  export declare function planSectionGrowth(document: PhysicalDocumentV1, { sectionId, fill }: SectionGrowInput): {
53
64
  section: {
54
65
  outline: PolygonM;
55
66
  entrance?: import("./wayfinding.interface.js").EntranceAssignment;
56
67
  buyerPhoto?: import("./physical-document.interface.js").BuyerPhoto;
57
- floorId?: import("./physical-document.interface.js").UUID;
58
- zoneId?: import("./physical-document.interface.js").UUID;
68
+ floorId?: UUID;
69
+ zoneId?: UUID;
59
70
  elevation?: import("./physical-document.interface.js").SectionElevation;
60
- categoryId?: import("./physical-document.interface.js").UUID | null;
61
- id: import("./physical-document.interface.js").UUID;
71
+ categoryId?: UUID | null;
72
+ id: UUID;
62
73
  label: string;
63
74
  displayLabel?: string;
64
75
  outlineRole?: SectionOutlineRole;
@@ -41,9 +41,11 @@ export type SectionFillPlan = {
41
41
  recipe: Pick<StraightRows["recipe"], "seatPitchM" | "rowPitchM">;
42
42
  rows: SectionFillRow[];
43
43
  };
44
- export type SectionFillInterval = {
44
+ export type SectionFillSpan = {
45
45
  start: number;
46
46
  end: number;
47
+ };
48
+ export type SectionFillInterval = SectionFillSpan & {
47
49
  capacity: number;
48
50
  };
49
51
  export type SectionFillBand = {
@@ -57,6 +59,7 @@ export type SectionFillEdge = {
57
59
  slope: number;
58
60
  };
59
61
  export type SectionFillGrid = {
62
+ earlier: readonly PreparedBoundary[];
60
63
  angle: number;
61
64
  seatPitchM: number;
62
65
  rowPitchM: number;
@@ -64,6 +67,7 @@ export type SectionFillGrid = {
64
67
  capacity: number;
65
68
  };
66
69
  export type SectionFillBend = {
70
+ earlier: readonly PreparedBoundary[];
67
71
  focalPoint: PointM;
68
72
  boundary: PreparedBoundary;
69
73
  normal: PointM;
@@ -1,9 +1,9 @@
1
1
  import { z } from "zod";
2
2
  import { authoredFloorFocalPoint, DefaultFloorFocalPoint } from "./floors.js";
3
- import { BoundaryLocation, classifyBoundary, prepareBoundary } from "./geometry/boundary.js";
3
+ import { BoundaryLocation, BoundaryToleranceM, classifyBoundary, prepareBoundary, } from "./geometry/boundary.js";
4
4
  import { normalizeAngle } from "./geometry/geometry.js";
5
5
  import { sectionOutlineSampleContour, sectionOutlineSamplingScale } from "./section-outline-refit.js";
6
- import { pointsBounds } from "./geometry/primitives.js";
6
+ import { intersects, pointsBounds } from "./geometry/primitives.js";
7
7
  import { rowSeatGeometry } from "./geometry/seating-layout.js";
8
8
  import { LayoutUnitM } from "./geometry/units.js";
9
9
  import { LabelDirection, SeatingKind, SectionOutlineRole, } from "./physical-document.interface.js";
@@ -21,6 +21,8 @@ const MinimumPitchM = 20.7 * LayoutUnitM;
21
21
  const DegreesPerRadian = 180 / Math.PI;
22
22
  const GeometryToleranceM = 1e-9;
23
23
  const fillGrids = new WeakMap();
24
+ const sectionBoundaries = new WeakMap();
25
+ const NoEarlierBoundaries = [];
24
26
  export const sectionFillDefaults = {
25
27
  direction: SectionFillDirection.Straight,
26
28
  numbering: SectionFillNumbering.Snake,
@@ -49,6 +51,41 @@ export function sectionFillFocalPoint(document, section) {
49
51
  const zone = document.zones?.find(({ id }) => id === section.zoneId);
50
52
  return zone?.focalPoint ?? authoredFloorFocalPoint(document, section.floorId ?? null) ?? DefaultFloorFocalPoint;
51
53
  }
54
+ /**
55
+ * @method planFillForSection
56
+ * @description Plan rows in the part of the section available under the document's inventory ownership order.
57
+ * @param {PhysicalDocumentV1} document - Current physical document.
58
+ * @param {Section & { outline: PolygonM }} section - Section with an authored outline.
59
+ * @param {SectionFillInput} request - Capacity, spacing and orientation settings.
60
+ * @returns {SectionFillPlan} Preview and capacity for the selected section.
61
+ */
62
+ export function planFillForSection(document, section, request) {
63
+ const contour = sectionOutlineSampleContour(section.outline, sectionOutlineSamplingScale(section));
64
+ return planFill(contour, request, sectionFillFocalPoint(document, section), earlierSectionBoundaries(document, section));
65
+ }
66
+ // The section catalogue assigns spatial inventory to the first containing boundary on the same floor.
67
+ function earlierSectionBoundaries(document, section) {
68
+ let cached = sectionBoundaries.get(document);
69
+ if (!cached) {
70
+ cached = new Map();
71
+ sectionBoundaries.set(document, cached);
72
+ }
73
+ const previous = cached.get(section.id);
74
+ if (previous)
75
+ return previous;
76
+ const earlier = [];
77
+ for (const current of document.sections) {
78
+ if (current.id === section.id)
79
+ break;
80
+ if (!current.outline || current.outlineRole === SectionOutlineRole.Overview)
81
+ continue;
82
+ if ((current.floorId ?? null) !== (section.floorId ?? null))
83
+ continue;
84
+ earlier.push(prepareBoundary(current.outline));
85
+ }
86
+ cached.set(section.id, earlier);
87
+ return earlier;
88
+ }
52
89
  export function planSectionGrowth(document, { sectionId, fill }) {
53
90
  const section = document.sections.find(({ id }) => id === sectionId);
54
91
  if (!section?.outline || section.outlineRole === SectionOutlineRole.Overview)
@@ -72,12 +109,10 @@ function scanEdges(rings) {
72
109
  }
73
110
  return edges.sort((a, b) => a.low.y - b.low.y);
74
111
  }
75
- function scanBands(edges, top, bottom, { rowPitchM, seatPitchM }) {
112
+ function scanSpans(edges) {
76
113
  let cursor = 0;
77
114
  let active = [];
78
- const bands = [];
79
- for (let index = 0; top + index * rowPitchM <= bottom + GeometryToleranceM; index++) {
80
- const y = top + index * rowPitchM;
115
+ return (y) => {
81
116
  active = active.filter((edge) => edge.high.y > y);
82
117
  while (cursor < edges.length && edges[cursor].low.y <= y) {
83
118
  const edge = edges[cursor++];
@@ -85,11 +120,50 @@ function scanBands(edges, top, bottom, { rowPitchM, seatPitchM }) {
85
120
  active.push(edge);
86
121
  }
87
122
  const crossings = active.map(({ low, slope }) => low.x + (y - low.y) * slope).sort((a, b) => a - b);
123
+ const spans = [];
124
+ for (let i = 0; i + 1 < crossings.length; i += 2) {
125
+ spans.push({ start: crossings[i], end: crossings[i + 1] });
126
+ }
127
+ return spans;
128
+ };
129
+ }
130
+ function subtractSpans(spans, blocked) {
131
+ return spans.flatMap(({ start, end }) => {
132
+ const available = [];
133
+ for (const span of blocked) {
134
+ if (span.end <= start)
135
+ continue;
136
+ if (span.start >= end)
137
+ break;
138
+ if (span.start > start)
139
+ available.push({ start, end: span.start });
140
+ start = span.end;
141
+ if (start >= end)
142
+ break;
143
+ }
144
+ if (start < end)
145
+ available.push({ start, end });
146
+ return available;
147
+ });
148
+ }
149
+ function scanBands(edges, exclusions, top, bottom, { rowPitchM, seatPitchM }) {
150
+ const scanOutline = scanSpans(edges);
151
+ // Sample both sides so a track on the closed edge of an earlier section is excluded too.
152
+ const scanExclusions = exclusions.map((edges) => {
153
+ const below = scanSpans(edges);
154
+ const at = scanSpans(edges);
155
+ const above = scanSpans(edges);
156
+ return (y) => [...below(y - BoundaryToleranceM), ...at(y), ...above(y + BoundaryToleranceM)];
157
+ });
158
+ const bands = [];
159
+ for (let index = 0; top + index * rowPitchM <= bottom + GeometryToleranceM; index++) {
160
+ const y = top + index * rowPitchM;
161
+ const blocked = scanExclusions.flatMap((scan) => scan(y)).sort((first, second) => first.start - second.start);
88
162
  const intervals = [];
89
163
  let capacity = 0;
90
- for (let i = 0; i + 1 < crossings.length; i += 2) {
91
- const start = crossings[i] + ClearanceM;
92
- const end = crossings[i + 1] - ClearanceM;
164
+ for (const span of subtractSpans(scanOutline(y), blocked)) {
165
+ const start = span.start + ClearanceM;
166
+ const end = span.end - ClearanceM;
93
167
  if (end < start - GeometryToleranceM)
94
168
  continue;
95
169
  const seats = 1 + Math.floor((end - start + GeometryToleranceM) / seatPitchM);
@@ -130,18 +204,25 @@ function allocateRows(total, capacities) {
130
204
  }
131
205
  return counts;
132
206
  }
133
- function fillGrid(contour, angle, input, project) {
207
+ function fillGrid(contour, angle, input, project, earlier) {
134
208
  const cached = fillGrids.get(contour);
135
- if (cached?.angle === angle && cached.seatPitchM === input.seatPitchM && cached.rowPitchM === input.rowPitchM)
209
+ if (cached?.angle === angle &&
210
+ cached.earlier === earlier &&
211
+ cached.seatPitchM === input.seatPitchM &&
212
+ cached.rowPitchM === input.rowPitchM)
136
213
  return cached;
137
214
  const outer = contour.outer.map(project);
138
215
  const { minY, maxY } = pointsBounds(outer);
139
216
  const edges = scanEdges([outer, ...contour.holes.map((ring) => ring.map(project))]);
217
+ const bounds = pointsBounds(contour.outer);
218
+ const exclusions = earlier
219
+ .filter((boundary) => intersects(bounds, boundary.bounds))
220
+ .map(({ polygon }) => scanEdges([polygon.outer, ...polygon.holes].map((ring) => ring.map(project))));
140
221
  let best = [];
141
222
  let maximum = 0;
142
223
  for (let phase = 0; phase < GridPhases; phase++) {
143
224
  const top = minY + ClearanceM + (phase * input.rowPitchM) / GridPhases;
144
- const bands = scanBands(edges, top, maxY - ClearanceM, input)
225
+ const bands = scanBands(edges, exclusions, top, maxY - ClearanceM, input)
145
226
  .sort((first, second) => second.capacity - first.capacity)
146
227
  .slice(0, SectionFillLimits.rows.max);
147
228
  const capacity = bands.reduce((sum, band) => sum + band.capacity, 0);
@@ -152,6 +233,7 @@ function fillGrid(contour, angle, input, project) {
152
233
  }
153
234
  const grid = {
154
235
  angle,
236
+ earlier,
155
237
  seatPitchM: input.seatPitchM,
156
238
  rowPitchM: input.rowPitchM,
157
239
  bands: best,
@@ -161,7 +243,7 @@ function fillGrid(contour, angle, input, project) {
161
243
  return grid;
162
244
  }
163
245
  function bendPart(layout, midpoint, seats, bend) {
164
- const { focalPoint, boundary, normal, clearanceM } = bend;
246
+ const { focalPoint, boundary, normal, clearanceM, earlier } = bend;
165
247
  const dx = midpoint.x - focalPoint.x;
166
248
  const dy = midpoint.y - focalPoint.y;
167
249
  const radiusM = Math.hypot(dx, dy);
@@ -195,14 +277,18 @@ function bendPart(layout, midpoint, seats, bend) {
195
277
  ...(facing < 0 && { seatRotationOffsetDeg: -180 }),
196
278
  };
197
279
  let seat = 0;
280
+ const anchor = { x: 0, y: 0 };
198
281
  for (; seat < seats; seat++) {
199
282
  const { position } = rowSeatGeometry(geometry, 0, seat, seats, seats, candidate);
200
283
  const acrossTrack = (position.x - midpoint.x) * normal.x + (position.y - midpoint.y) * normal.y;
201
284
  if (Math.abs(acrossTrack) > clearanceM + GeometryToleranceM ||
202
- classifyBoundary(boundary, position) === BoundaryLocation.Outside)
285
+ classifyBoundary(boundary, position) === BoundaryLocation.Outside ||
286
+ earlier.some((other) => classifyBoundary(other, position) !== BoundaryLocation.Outside))
203
287
  break;
288
+ anchor.x += position.x / seats;
289
+ anchor.y += position.y / seats;
204
290
  }
205
- if (seat === seats)
291
+ if (seat === seats && earlier.every((other) => classifyBoundary(other, anchor) === BoundaryLocation.Outside))
206
292
  return candidate;
207
293
  }
208
294
  return layout;
@@ -217,8 +303,10 @@ function outlineCenter(outer) {
217
303
  }
218
304
  /** Preview a section fill without allocating inventory identities or editing the outline. */
219
305
  export function planSectionFill(outline, request, focalPoint, sampleScale = 1) {
306
+ return planFill(sectionOutlineSampleContour(outline, sampleScale), request, focalPoint, NoEarlierBoundaries);
307
+ }
308
+ function planFill(contour, request, focalPoint, earlier) {
220
309
  const input = sectionFillInputSchema.parse(request);
221
- const contour = sectionOutlineSampleContour(outline, sampleScale);
222
310
  const recipe = {
223
311
  seatPitchM: Math.max(input.seatPitchM, MinimumPitchM),
224
312
  rowPitchM: Math.max(input.rowPitchM, MinimumPitchM),
@@ -233,7 +321,7 @@ export function planSectionFill(outline, request, focalPoint, sampleScale = 1) {
233
321
  x: (x - center.x) * cos + (y - center.y) * sin,
234
322
  y: (y - center.y) * cos - (x - center.x) * sin,
235
323
  });
236
- const grid = fillGrid(contour, angle, recipe, project);
324
+ const grid = fillGrid(contour, angle, recipe, project, earlier);
237
325
  const selected = grid.bands.slice(0, input.rowCount ?? input.targetSeats).sort((a, b) => a.y - b.y);
238
326
  const maximumSeats = input.rowCount === undefined ? grid.capacity : selected.reduce((sum, band) => sum + band.capacity, 0);
239
327
  const limits = { maximumRows: grid.bands.length, maximumSeats, recipe };
@@ -245,7 +333,13 @@ export function planSectionFill(outline, request, focalPoint, sampleScale = 1) {
245
333
  const rotationDeg = normalizeAngle(angle * DegreesPerRadian);
246
334
  const clearanceM = recipe.rowPitchM - MinimumPitchM;
247
335
  const bend = input.direction === SectionFillDirection.Focal && clearanceM > 0
248
- ? { focalPoint, clearanceM, boundary: prepareBoundary(contour), normal: { x: -sin, y: cos } }
336
+ ? {
337
+ focalPoint,
338
+ clearanceM,
339
+ boundary: prepareBoundary(contour),
340
+ normal: { x: -sin, y: cos },
341
+ earlier: earlier.filter((other) => intersects(prepareBoundary(contour).bounds, other.bounds)),
342
+ }
249
343
  : null;
250
344
  const world = (x, y) => ({
251
345
  x: center.x + x * cos - y * sin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seatmap-fyi/map-domain",
3
- "version": "0.1.0-alpha.55",
3
+ "version": "0.1.0-alpha.56",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "sideEffects": false,