@seatmap-fyi/map-domain 0.1.0-alpha.48 → 0.1.0-alpha.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,13 +3,13 @@ import { polygonContour } from "./geometry/polygon-curves.js";
3
3
  import { objectFloorId } from "./floors.js";
4
4
  import { sectionCatalog } from "./sections.js";
5
5
  import { uuidSchema, coordinateSchema } from "./schema.js";
6
- import { footprintInBoundary, prepareBoundary } from "./geometry/boundary.js";
6
+ import { BoundaryLocation, classifyBoundary, footprintInBoundary, prepareBoundary, } from "./geometry/boundary.js";
7
7
  import { LayoutUnitM } from "./geometry/units.js";
8
- import { emptyBounds, extend, footprint, generatedSeats, pointsBounds, multiply, transformMatrix, project, tableBodyBounds, worldMatrices, } from "./geometry/geometry.js";
8
+ import { emptyBounds, extend, footprint, generatedSeats, intersects, inverse, pointsBounds, multiply, transformMatrix, project, tableBodyBounds, worldMatrices, } from "./geometry/geometry.js";
9
9
  import { SectionOutlineRole, ShapeKind, AreaKind, } from "./physical-document.interface.js";
10
10
  export const sectionInventoryGrowthInputSchema = z.strictObject({
11
11
  inventory: z.array(uuidSchema).nonempty(),
12
- createdInSection: uuidSchema.nullable(),
12
+ workspaceSectionId: uuidSchema.nullable(),
13
13
  });
14
14
  const growthPaddingM = 5 * LayoutUnitM;
15
15
  const growthStep = 1.15;
@@ -23,39 +23,72 @@ function corners(bounds) {
23
23
  { x: bounds.minX, y: bounds.maxY },
24
24
  ];
25
25
  }
26
- function groupBounds(group, matrix) {
27
- const bounds = new Map();
26
+ function extendByBounds(bounds, other) {
27
+ extend(bounds, { x: other.minX, y: other.minY });
28
+ extend(bounds, { x: other.maxX, y: other.maxY });
29
+ }
30
+ function groupFootprints(group, matrix) {
31
+ const footprints = new Map();
28
32
  for (const seat of generatedSeats(group)) {
29
33
  const id = seat.rowId ?? group.id;
30
- const box = bounds.get(id) ?? emptyBounds();
31
- const marker = {
32
- ...seat,
33
- size: {
34
- width: Math.max(seat.size.width, minimumSeatBoundsM),
35
- height: Math.max(seat.size.height, minimumSeatBoundsM),
36
- },
34
+ const layout = footprints.get(id) ?? { bounds: emptyBounds() };
35
+ const markerSize = {
36
+ width: Math.max(seat.size.width, minimumSeatBoundsM),
37
+ height: Math.max(seat.size.height, minimumSeatBoundsM),
37
38
  };
38
39
  if (seat.rowId !== null) {
39
40
  const seatMatrix = multiply(matrix, transformMatrix({ positionM: seat.position, rotationDeg: seat.rotationDeg }));
40
- const radiusX = Math.hypot(seatMatrix.a * marker.size.width, seatMatrix.c * marker.size.height) / 2;
41
- const radiusY = Math.hypot(seatMatrix.b * marker.size.width, seatMatrix.d * marker.size.height) / 2;
42
- extend(box, { x: seatMatrix.tx - radiusX, y: seatMatrix.ty - radiusY });
43
- extend(box, { x: seatMatrix.tx + radiusX, y: seatMatrix.ty + radiusY });
41
+ const { a, b, c, d, tx, ty } = seatMatrix;
42
+ const radiusX = Math.hypot(a * markerSize.width, c * markerSize.height) / 2;
43
+ const radiusY = Math.hypot(b * markerSize.width, d * markerSize.height) / 2;
44
+ extend(layout.bounds, { x: tx - radiusX, y: ty - radiusY });
45
+ extend(layout.bounds, { x: tx + radiusX, y: ty + radiusY });
46
+ // The minimum marker size pads the affine envelope. Containment uses the actual seat ellipse.
47
+ (layout.rowMarkers ??= []).push({
48
+ a: (a * seat.size.width) / 2,
49
+ b: (b * seat.size.width) / 2,
50
+ c: (c * seat.size.height) / 2,
51
+ d: (d * seat.size.height) / 2,
52
+ tx,
53
+ ty,
54
+ });
44
55
  }
45
56
  else {
46
- for (const point of footprint(marker, matrix))
47
- extend(box, point);
57
+ for (const point of footprint({ ...seat, size: markerSize }, matrix))
58
+ extend(layout.bounds, point);
48
59
  }
49
- bounds.set(id, box);
60
+ footprints.set(id, layout);
50
61
  }
51
62
  const body = tableBodyBounds(group, matrix);
52
63
  if (body) {
53
- const box = bounds.get(group.id) ?? emptyBounds();
54
- extend(box, { x: body.minX, y: body.minY });
55
- extend(box, { x: body.maxX, y: body.maxY });
56
- bounds.set(group.id, box);
64
+ const layout = footprints.get(group.id) ?? { bounds: emptyBounds() };
65
+ extendByBounds(layout.bounds, body);
66
+ footprints.set(group.id, layout);
57
67
  }
58
- return bounds;
68
+ return footprints;
69
+ }
70
+ function rowMarkerInBoundary(boundary, marker) {
71
+ const { tx, ty } = marker;
72
+ if (classifyBoundary(boundary, { x: tx, y: ty }) === BoundaryLocation.Outside)
73
+ return false;
74
+ const radiusX = Math.hypot(marker.a, marker.c);
75
+ const radiusY = Math.hypot(marker.b, marker.d);
76
+ const bounds = { minX: tx - radiusX, maxX: tx + radiusX, minY: ty - radiusY, maxY: ty + radiusY };
77
+ const normalize = inverse(marker);
78
+ // Transform each edge into the marker's unit circle and test its nearest point.
79
+ return boundary.edges.every((edge) => {
80
+ if (!intersects(bounds, edge.bounds))
81
+ return true;
82
+ const start = project(normalize, edge.a);
83
+ const end = project(normalize, edge.b);
84
+ const dx = end.x - start.x;
85
+ const dy = end.y - start.y;
86
+ const lengthSquared = dx * dx + dy * dy;
87
+ const t = lengthSquared ? Math.max(0, Math.min(1, -(start.x * dx + start.y * dy) / lengthSquared)) : 0;
88
+ const x = start.x + t * dx;
89
+ const y = start.y + t * dy;
90
+ return x * x + y * y >= 1;
91
+ });
59
92
  }
60
93
  function areaBounds(area, matrix) {
61
94
  const shape = area.shape;
@@ -94,8 +127,8 @@ function affectedInventory(document, changed) {
94
127
  for (const group of document.seatingGroups)
95
128
  if (changedAncestor(group.id)) {
96
129
  const floorId = objectFloorId(document, group.id);
97
- for (const [id, bounds] of groupBounds(group, matrices.get(group.id)))
98
- layouts.set(id, { bounds, floorId });
130
+ for (const [id, layout] of groupFootprints(group, matrices.get(group.id)))
131
+ layouts.set(id, { ...layout, floorId });
99
132
  }
100
133
  for (const area of document.areas)
101
134
  if (changedAncestor(area.id))
@@ -105,8 +138,8 @@ function affectedInventory(document, changed) {
105
138
  });
106
139
  return layouts;
107
140
  }
108
- /** Expand boundaries atomically for moved/resized inventory and rows drawn in the active section. */
109
- export function expandedInventorySections(before, after, changed, createdInSection) {
141
+ /** Grow the entered workspace for its edited inventory, or the primary boundary for chart-wide edits. */
142
+ export function expandedInventorySections(before, after, changed, workspaceSectionId) {
110
143
  const result = new Map();
111
144
  if (!changed.size || !before.sections.length)
112
145
  return result;
@@ -117,7 +150,8 @@ export function expandedInventorySections(before, after, changed, createdInSecti
117
150
  return (next && next.outline !== section.outline && JSON.stringify(section.outline) !== JSON.stringify(next.outline));
118
151
  }))
119
152
  return result;
120
- const owners = sectionCatalog(before).owners;
153
+ const { entries, owners } = sectionCatalog(before);
154
+ const workspace = workspaceSectionId ? entries.get(workspaceSectionId) : undefined;
121
155
  const oldBounds = affectedInventory(before, changed);
122
156
  const nextBounds = affectedInventory(after, changed);
123
157
  const requested = new Map();
@@ -134,7 +168,7 @@ export function expandedInventorySections(before, after, changed, createdInSecti
134
168
  oldBox.maxY === nextBox.maxY)
135
169
  continue;
136
170
  }
137
- const owner = oldLayout ? owners.get(id) : createdInSection;
171
+ const owner = oldLayout && !workspace?.editableObjects.has(id) ? owners.get(id) : workspaceSectionId;
138
172
  if (!owner)
139
173
  continue;
140
174
  const nextBox = nextLayout.bounds;
@@ -143,16 +177,29 @@ export function expandedInventorySections(before, after, changed, createdInSecti
143
177
  continue;
144
178
  if (nextLayout.floorId !== (section.floorId ?? null))
145
179
  continue;
146
- const box = requested.get(owner) ?? emptyBounds();
147
- extend(box, { x: nextBox.minX, y: nextBox.minY });
148
- extend(box, { x: nextBox.maxX, y: nextBox.maxY });
149
- requested.set(owner, box);
180
+ const request = requested.get(owner) ?? { bounds: emptyBounds(), rowMarkers: [] };
181
+ extendByBounds(request.bounds, nextBox);
182
+ if (nextLayout.rowMarkers) {
183
+ for (const marker of nextLayout.rowMarkers)
184
+ request.rowMarkers.push(marker);
185
+ }
186
+ else {
187
+ extendByBounds((request.otherBounds ??= emptyBounds()), nextBox);
188
+ }
189
+ requested.set(owner, request);
150
190
  }
151
- for (const [id, box] of requested) {
191
+ for (const [id, { bounds: box, rowMarkers, otherBounds }] of requested) {
152
192
  const section = sections.get(id);
153
193
  const outline = section.outline;
154
194
  const target = corners(box);
155
- const contains = (outer) => footprintInBoundary(prepareBoundary({ ...outline, outer, holes: [] }), target);
195
+ const otherFootprint = otherBounds ? corners(otherBounds) : null;
196
+ const contains = (outer) => {
197
+ const boundary = prepareBoundary({ ...outline, outer, holes: [] });
198
+ return (footprintInBoundary(boundary, target) ||
199
+ (rowMarkers.length > 0 &&
200
+ (!otherFootprint || footprintInBoundary(boundary, otherFootprint)) &&
201
+ rowMarkers.every((marker) => rowMarkerInBoundary(boundary, marker))));
202
+ };
156
203
  if (contains(outline.outer))
157
204
  continue;
158
205
  const oldBox = pointsBounds(outline.outer);
@@ -35,7 +35,9 @@ export declare const sectionLayoutInputSchema: z.ZodUnion<readonly [z.ZodObject<
35
35
  }, z.core.$strict>;
36
36
  }, z.core.$strict>, z.ZodObject<{
37
37
  inventory: z.ZodArray<z.ZodString>;
38
- createdInSection: z.ZodNullable<z.ZodString>;
38
+ workspaceSectionId: z.ZodNullable<z.ZodString>;
39
+ }, z.core.$strict>, z.ZodObject<{
40
+ arcFanGroupId: z.ZodString;
39
41
  }, z.core.$strict>]>;
40
42
  export declare const sectionLayoutSaveSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
41
43
  kind: z.ZodLiteral<SectionLayoutSaveKind.Apply>;
@@ -61,7 +63,9 @@ export declare const sectionLayoutSaveSchema: z.ZodDiscriminatedUnion<[z.ZodObje
61
63
  }, z.core.$strict>;
62
64
  }, z.core.$strict>, z.ZodObject<{
63
65
  inventory: z.ZodArray<z.ZodString>;
64
- createdInSection: z.ZodNullable<z.ZodString>;
66
+ workspaceSectionId: z.ZodNullable<z.ZodString>;
67
+ }, z.core.$strict>, z.ZodObject<{
68
+ arcFanGroupId: z.ZodString;
65
69
  }, z.core.$strict>]>;
66
70
  }, z.core.$strict>, z.ZodObject<{
67
71
  kind: z.ZodLiteral<SectionLayoutSaveKind.Undo>;
@@ -87,7 +91,9 @@ export declare const sectionLayoutSaveSchema: z.ZodDiscriminatedUnion<[z.ZodObje
87
91
  }, z.core.$strict>;
88
92
  }, z.core.$strict>, z.ZodObject<{
89
93
  inventory: z.ZodArray<z.ZodString>;
90
- createdInSection: z.ZodNullable<z.ZodString>;
94
+ workspaceSectionId: z.ZodNullable<z.ZodString>;
95
+ }, z.core.$strict>, z.ZodObject<{
96
+ arcFanGroupId: z.ZodString;
91
97
  }, z.core.$strict>]>;
92
98
  beforeRevision: z.ZodNumber;
93
99
  }, z.core.$strict>], "kind">;
@@ -3,6 +3,7 @@ import { pointsBounds } from "./geometry/primitives.js";
3
3
  import { polygonCornerFillets } from "./geometry/polygon-curves.js";
4
4
  import { compactRowTargets, sectionOutlinePivot, transformLayout } from "./geometry/layout-transform.js";
5
5
  import { SectionRotation, SectionScale } from "./physical-document.interface.js";
6
+ import { arcFanSectionRebuildInputSchema } from "./arc-fan-section-layout.js";
6
7
  import { sectionInventoryGrowthInputSchema } from "./section-growth.js";
7
8
  import { sectionGrowInputSchema } from "./section-fill.js";
8
9
  import { sectionRefitInputSchema } from "./section-refit.js";
@@ -25,6 +26,7 @@ export const sectionLayoutInputSchema = z.union([
25
26
  sectionTransformInputSchema,
26
27
  sectionGrowInputSchema,
27
28
  sectionInventoryGrowthInputSchema,
29
+ arcFanSectionRebuildInputSchema,
28
30
  ]);
29
31
  export const sectionLayoutSaveSchema = z.discriminatedUnion("kind", [
30
32
  z.strictObject({ kind: z.literal(SectionLayoutSaveKind.Apply), input: sectionLayoutInputSchema }),
@@ -17,7 +17,7 @@ export declare const TableLayoutLimits: {
17
17
  };
18
18
  export declare const TableChairSides: readonly ["top", "bottom", "left", "right"];
19
19
  export declare function defaultRoundTableRecipe(): RoundTableRecipe;
20
- export declare function defaultLongTableLayout(): LongTableLayout;
20
+ export declare function defaultLongTableLayout(): Required<LongTableLayout>;
21
21
  /** Shared by committed count reconciliation and placement previews. */
22
22
  export declare function automaticTableRadiusM(count: number, arcDeg: number): number;
23
23
  export declare function resizeRoundTable(table: RoundTable): RoundTable;
@@ -25,5 +25,6 @@ export declare function setRoundTableAutomaticSize(table: RoundTable, automaticS
25
25
  export declare function setRoundTableArc(table: RoundTable, requested: number): RoundTable;
26
26
  export declare function setRoundTableRadius(table: RoundTable, requested: number): RoundTable;
27
27
  export declare function setLongTableDimensions(table: RectangularTable, widthM: number, depthM: number): RectangularTable;
28
+ export declare function rememberTableSideEdits(previous: RectangularTable, updated: RectangularTable): RectangularTable;
28
29
  /** Shape changes retain inventory identity, personal overrides and the inactive shape settings. */
29
30
  export declare function changeTableShape(table: TableInventory, kind: SeatingKind.Round | SeatingKind.Rectangular): TableInventory;
@@ -83,12 +83,26 @@ export function setLongTableDimensions(table, widthM, depthM) {
83
83
  };
84
84
  return recipe.widthM === table.recipe.widthM && recipe.depthM === table.recipe.depthM ? table : { ...table, recipe };
85
85
  }
86
+ export function rememberTableSideEdits(previous, updated) {
87
+ if (!TableChairSides.some((side) => previous.chairsBySide[side].length !== updated.chairsBySide[side].length))
88
+ return updated;
89
+ const { top, bottom, left, right } = updated.chairsBySide;
90
+ return {
91
+ ...updated,
92
+ conversionSides: {
93
+ top: top.length > 0,
94
+ bottom: bottom.length > 0,
95
+ left: left.length > 0,
96
+ right: right.length > 0,
97
+ },
98
+ };
99
+ }
86
100
  /** Shape changes retain inventory identity, personal overrides and the inactive shape settings. */
87
101
  export function changeTableShape(table, kind) {
88
102
  if (table.kind === kind)
89
103
  return table;
90
104
  if (table.kind === SeatingKind.Rectangular) {
91
- const { recipe, chairsBySide, roundLayout, ...base } = table;
105
+ const { recipe, chairsBySide, roundLayout, conversionSides, ...base } = table;
92
106
  const chairs = TableChairSides.flatMap((side) => chairsBySide[side]);
93
107
  return resizeRoundTable({
94
108
  ...base,
@@ -98,20 +112,13 @@ export function changeTableShape(table, kind) {
98
112
  ...(roundLayout ?? defaultRoundTableRecipe()),
99
113
  automaticSize: true,
100
114
  },
101
- longLayout: {
102
- recipe,
103
- sides: {
104
- top: !!chairsBySide.top.length,
105
- bottom: !!chairsBySide.bottom.length,
106
- left: !!chairsBySide.left.length,
107
- right: !!chairsBySide.right.length,
108
- },
109
- },
115
+ longLayout: { recipe, ...(conversionSides && { sides: conversionSides }) },
110
116
  });
111
117
  }
112
118
  const { recipe, chairs, longLayout, ...base } = table;
113
- const layout = longLayout ?? defaultLongTableLayout();
114
- const sides = TableChairSides.filter((side) => layout.sides[side]);
119
+ const defaults = defaultLongTableLayout();
120
+ const preferredSides = longLayout?.sides ?? defaults.sides;
121
+ const sides = TableChairSides.filter((side) => preferredSides[side]);
115
122
  let offset = 0;
116
123
  const chairsBySide = {
117
124
  top: [],
@@ -127,8 +134,9 @@ export function changeTableShape(table, kind) {
127
134
  return {
128
135
  ...base,
129
136
  kind: SeatingKind.Rectangular,
130
- recipe: layout.recipe,
137
+ recipe: longLayout?.recipe ?? defaults.recipe,
131
138
  chairsBySide,
132
139
  roundLayout: recipe,
140
+ ...(longLayout?.sides && { conversionSides: longLayout.sides }),
133
141
  };
134
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seatmap-fyi/map-domain",
3
- "version": "0.1.0-alpha.48",
3
+ "version": "0.1.0-alpha.50",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -184,6 +184,14 @@
184
184
  "./section-growth/types": {
185
185
  "types": "./dist/section-growth.interface.d.ts",
186
186
  "import": "./dist/section-growth.interface.js"
187
+ },
188
+ "./geometry/inventory-outline": {
189
+ "types": "./dist/geometry/inventory-outline.d.ts",
190
+ "import": "./dist/geometry/inventory-outline.js"
191
+ },
192
+ "./arc-fan/section-layout": {
193
+ "types": "./dist/arc-fan-section-layout.d.ts",
194
+ "import": "./dist/arc-fan-section-layout.js"
187
195
  }
188
196
  },
189
197
  "scripts": {