@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.
- package/dist/arc-fan-rebuild.d.ts +13 -0
- package/dist/arc-fan-rebuild.js +163 -0
- package/dist/arc-fan.d.ts +27 -0
- package/dist/arc-fan.interface.d.ts +83 -0
- package/dist/arc-fan.interface.js +30 -0
- package/dist/arc-fan.js +182 -0
- package/dist/catalog.d.ts +6 -4
- package/dist/catalog.js +31 -17
- package/dist/categories.d.ts +5 -3
- package/dist/categories.js +104 -25
- package/dist/editor-state.d.ts +4 -1
- package/dist/editor-state.js +53 -30
- package/dist/floors.d.ts +22 -0
- package/dist/floors.js +77 -0
- package/dist/geometry/boundary.d.ts +1 -1
- package/dist/geometry/boundary.js +16 -12
- package/dist/geometry/curve-warnings.d.ts +1 -1
- package/dist/geometry/curve-warnings.js +3 -5
- package/dist/geometry/decoration-bounds.d.ts +4 -0
- package/dist/geometry/decoration-bounds.js +42 -0
- package/dist/geometry/ellipse.js +4 -12
- package/dist/geometry/geometry.d.ts +6 -3
- package/dist/geometry/geometry.js +28 -30
- package/dist/geometry/layout-transform.d.ts +10 -0
- package/dist/geometry/layout-transform.interface.d.ts +6 -0
- package/dist/geometry/layout-transform.interface.js +1 -0
- package/dist/geometry/layout-transform.js +206 -0
- package/dist/geometry/polygon-curves.d.ts +17 -0
- package/dist/geometry/polygon-curves.interface.d.ts +21 -0
- package/dist/geometry/polygon-curves.interface.js +5 -0
- package/dist/geometry/polygon-curves.js +169 -0
- package/dist/geometry/primitives.d.ts +1 -1
- package/dist/geometry/primitives.js +2 -3
- package/dist/geometry/seat-shape.d.ts +1 -1
- package/dist/geometry/seat-shape.js +1 -1
- package/dist/geometry/seating-layout.d.ts +9 -1
- package/dist/geometry/seating-layout.js +66 -57
- package/dist/geometry/units.d.ts +8 -0
- package/dist/geometry/units.js +13 -0
- package/dist/geometry/venue-outline.d.ts +4 -18
- package/dist/geometry/venue-outline.interface.d.ts +23 -0
- package/dist/geometry/venue-outline.interface.js +7 -0
- package/dist/geometry/venue-outline.js +107 -49
- package/dist/identity.d.ts +3 -1
- package/dist/identity.js +32 -17
- package/dist/issues.d.ts +15 -2
- package/dist/issues.js +16 -6
- package/dist/labels.d.ts +6 -1
- package/dist/labels.js +20 -18
- package/dist/layers.d.ts +26 -0
- package/dist/layers.js +86 -0
- package/dist/media.d.ts +27 -0
- package/dist/media.js +89 -0
- package/dist/{types.d.ts → physical-document.interface.d.ts} +117 -4
- package/dist/{types.js → physical-document.interface.js} +17 -0
- package/dist/preview.d.ts +1 -1
- package/dist/preview.js +39 -29
- package/dist/reference.js +1 -1
- package/dist/row-segments.d.ts +5 -1
- package/dist/row-segments.js +10 -9
- package/dist/schema.d.ts +591 -14
- package/dist/schema.js +238 -102
- package/dist/seat-proximity.d.ts +4 -0
- package/dist/seat-proximity.js +119 -0
- package/dist/section-elevation.d.ts +5 -0
- package/dist/section-elevation.interface.d.ts +26 -0
- package/dist/section-elevation.interface.js +8 -0
- package/dist/section-elevation.js +53 -0
- package/dist/section-fill-rebuild.d.ts +10 -0
- package/dist/section-fill-rebuild.js +64 -0
- package/dist/section-fill.d.ts +84 -0
- package/dist/section-fill.interface.d.ts +94 -0
- package/dist/section-fill.interface.js +22 -0
- package/dist/section-fill.js +306 -0
- package/dist/section-growth.d.ts +11 -0
- package/dist/section-growth.interface.d.ts +12 -0
- package/dist/section-growth.interface.js +1 -0
- package/dist/section-growth.js +198 -0
- package/dist/section-layout.d.ts +95 -0
- package/dist/section-layout.interface.d.ts +8 -0
- package/dist/section-layout.interface.js +5 -0
- package/dist/section-layout.js +70 -0
- package/dist/section-outline-refit.d.ts +8 -0
- package/dist/section-outline-refit.js +246 -0
- package/dist/section-refit.d.ts +22 -0
- package/dist/section-refit.interface.d.ts +49 -0
- package/dist/section-refit.interface.js +6 -0
- package/dist/section-refit.js +179 -0
- package/dist/section-scale.d.ts +2 -0
- package/dist/section-scale.js +128 -0
- package/dist/sections.d.ts +23 -0
- package/dist/sections.js +144 -0
- package/dist/selling.d.ts +1 -1
- package/dist/selling.js +11 -26
- package/dist/spacing-repairs.d.ts +31 -0
- package/dist/spacing-repairs.js +168 -0
- package/dist/table-layout.d.ts +1 -2
- package/dist/table-layout.js +14 -22
- package/dist/validation.d.ts +7 -2
- package/dist/validation.interface.d.ts +20 -0
- package/dist/validation.interface.js +9 -0
- package/dist/validation.js +221 -85
- package/dist/wayfinding.d.ts +10 -0
- package/dist/wayfinding.interface.d.ts +52 -0
- package/dist/wayfinding.interface.js +28 -0
- package/dist/wayfinding.js +63 -0
- package/package.json +89 -4
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { pointsBounds } from "./geometry/primitives.js";
|
|
3
|
+
import { polygonCornerFillets } from "./geometry/polygon-curves.js";
|
|
4
|
+
import { compactRowTargets, sectionOutlinePivot, transformLayout } from "./geometry/layout-transform.js";
|
|
5
|
+
import { SectionRotation, SectionScale } from "./physical-document.interface.js";
|
|
6
|
+
import { sectionInventoryGrowthInputSchema } from "./section-growth.js";
|
|
7
|
+
import { sectionGrowInputSchema } from "./section-fill.js";
|
|
8
|
+
import { sectionRefitInputSchema } from "./section-refit.js";
|
|
9
|
+
import { sectionOutlineSampleCenter, sectionOutlineSamplingScale } from "./section-outline-refit.js";
|
|
10
|
+
import { SectionLayoutSaveKind } from "./section-layout.interface.js";
|
|
11
|
+
import { sectionCatalog } from "./sections.js";
|
|
12
|
+
import { scaleSectionLayout } from "./section-scale.js";
|
|
13
|
+
export { SectionLayoutSaveKind, } from "./section-layout.interface.js";
|
|
14
|
+
export const sectionRotationInputSchema = z.strictObject({
|
|
15
|
+
sectionId: z.uuid(),
|
|
16
|
+
rotationDeg: z.number().int().min(SectionRotation.min).max(SectionRotation.max),
|
|
17
|
+
});
|
|
18
|
+
const sectionScaleInputSchema = z.strictObject({
|
|
19
|
+
sectionId: z.uuid(),
|
|
20
|
+
scalePercent: z.number().min(SectionScale.min).max(SectionScale.max),
|
|
21
|
+
});
|
|
22
|
+
export const sectionTransformInputSchema = z.union([sectionRotationInputSchema, sectionScaleInputSchema]);
|
|
23
|
+
export const sectionLayoutInputSchema = z.union([
|
|
24
|
+
sectionRefitInputSchema,
|
|
25
|
+
sectionTransformInputSchema,
|
|
26
|
+
sectionGrowInputSchema,
|
|
27
|
+
sectionInventoryGrowthInputSchema,
|
|
28
|
+
]);
|
|
29
|
+
export const sectionLayoutSaveSchema = z.discriminatedUnion("kind", [
|
|
30
|
+
z.strictObject({ kind: z.literal(SectionLayoutSaveKind.Apply), input: sectionLayoutInputSchema }),
|
|
31
|
+
z.strictObject({
|
|
32
|
+
kind: z.literal(SectionLayoutSaveKind.Undo),
|
|
33
|
+
input: sectionLayoutInputSchema,
|
|
34
|
+
beforeRevision: z.number().int().positive(),
|
|
35
|
+
}),
|
|
36
|
+
]);
|
|
37
|
+
/** Apply the change in the numeric control to the existing geometry. */
|
|
38
|
+
export function transformSection(document, input) {
|
|
39
|
+
const { sectionId } = input;
|
|
40
|
+
const section = document.sections.find(({ id }) => id === sectionId);
|
|
41
|
+
if (!section?.outline)
|
|
42
|
+
return;
|
|
43
|
+
const { outline } = section;
|
|
44
|
+
const currentScale = section.scalePercent ?? SectionScale.initial;
|
|
45
|
+
const currentRotation = section.rotationDeg ?? SectionRotation.initial;
|
|
46
|
+
const scaling = "scalePercent" in input;
|
|
47
|
+
if (scaling ? input.scalePercent === currentScale : input.rotationDeg === currentRotation)
|
|
48
|
+
return document;
|
|
49
|
+
const entry = sectionCatalog(document).entries.get(sectionId);
|
|
50
|
+
const curved = outline.edgeCurvature?.some(Boolean) || polygonCornerFillets(outline).some(Boolean);
|
|
51
|
+
const sampleCenter = curved ? sectionOutlineSampleCenter(outline, sectionOutlineSamplingScale(section)) : undefined;
|
|
52
|
+
if (scaling) {
|
|
53
|
+
const { scalePercent } = input;
|
|
54
|
+
const factor = scalePercent / currentScale;
|
|
55
|
+
const { minX, minY, maxX, maxY } = pointsBounds(outline.outer);
|
|
56
|
+
const pivot = sampleCenter ?? { x: (minX + maxX) / 2, y: (minY + maxY) / 2 };
|
|
57
|
+
return scaleSectionLayout(document, sectionId, entry.editableObjects, pivot, scalePercent, factor);
|
|
58
|
+
}
|
|
59
|
+
const { rotationDeg } = input;
|
|
60
|
+
const delta = rotationDeg - currentRotation;
|
|
61
|
+
const rotated = transformLayout(document, {
|
|
62
|
+
sections: [sectionId],
|
|
63
|
+
objects: [...compactRowTargets(document, entry.editableObjects)],
|
|
64
|
+
pivot: sampleCenter ?? sectionOutlinePivot(outline),
|
|
65
|
+
}, { x: 0, y: 0 }, delta);
|
|
66
|
+
return {
|
|
67
|
+
...rotated,
|
|
68
|
+
sections: rotated.sections.map((item) => (item.id === sectionId ? { ...item, rotationDeg } : item)),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PointM, type PolygonM, type Section } from "./physical-document.interface.js";
|
|
2
|
+
export declare function sectionOutlineSamplingScale(section: Section): number;
|
|
3
|
+
/** Fill and Grow use the same authored boundary samples as the reference planner. */
|
|
4
|
+
export declare function sectionOutlineSampleContour(outline: PolygonM, currentScale: number): PolygonM;
|
|
5
|
+
/** Scale the sampling pitch with the section to retain the authored sample count. */
|
|
6
|
+
export declare function sectionOutlineSampleCenter(outline: PolygonM, currentScale: number): PointM;
|
|
7
|
+
/** Fit an algebraic circle to the authored boundary spans and their corner fillets. */
|
|
8
|
+
export declare function sectionOutlineRefitPoint(outline: PolygonM, currentScale: number): PointM;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { PolygonVertexLimit, polygonContour, polygonCornerFillets, polygonCornerSamples, sideCurvePoint, } from "./geometry/polygon-curves.js";
|
|
2
|
+
import { PolygonCornerKind } from "./geometry/polygon-curves.interface.js";
|
|
3
|
+
import { LayoutUnitM } from "./geometry/units.js";
|
|
4
|
+
import { SectionScale } from "./physical-document.interface.js";
|
|
5
|
+
const SamplePitchM = 2 * LayoutUnitM;
|
|
6
|
+
const ShallowCornerSweepRad = 1e-3;
|
|
7
|
+
const sampleContours = new WeakMap();
|
|
8
|
+
const fittedPoints = new WeakMap();
|
|
9
|
+
function sumEvenProducts(first, second, moments) {
|
|
10
|
+
let sum = 0;
|
|
11
|
+
for (let left = 0; left < first.length; left++) {
|
|
12
|
+
for (let right = left % 2; right < second.length; right += 2) {
|
|
13
|
+
sum += first[left] * second[right] * moments[(left + right) / 2];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return sum;
|
|
17
|
+
}
|
|
18
|
+
function includePolynomialSamples(sums, x, y, steps) {
|
|
19
|
+
if (steps < 2)
|
|
20
|
+
return;
|
|
21
|
+
// The evenly spaced interior samples are symmetric in u = 2t − 1.
|
|
22
|
+
const inverseSteps = 1 / steps;
|
|
23
|
+
const inverseCubed = inverseSteps ** 3;
|
|
24
|
+
const moments = [
|
|
25
|
+
steps - 1,
|
|
26
|
+
steps / 3 - 1 + (2 * inverseSteps) / 3,
|
|
27
|
+
steps / 5 - 1 + (4 * inverseSteps) / 3 - (8 * inverseCubed) / 15,
|
|
28
|
+
steps / 7 - 1 + 2 * inverseSteps - (8 * inverseCubed) / 3 + (32 * inverseSteps ** 5) / 21,
|
|
29
|
+
steps / 9 -
|
|
30
|
+
1 +
|
|
31
|
+
(8 * inverseSteps) / 3 -
|
|
32
|
+
(112 * inverseCubed) / 15 +
|
|
33
|
+
(128 * inverseSteps ** 5) / 9 -
|
|
34
|
+
(128 * inverseSteps ** 7) / 15,
|
|
35
|
+
];
|
|
36
|
+
const radiusSquared = Array(2 * x.length - 1).fill(0);
|
|
37
|
+
for (let left = 0; left < x.length; left++) {
|
|
38
|
+
for (let right = 0; right < x.length; right++) {
|
|
39
|
+
radiusSquared[left + right] += x[left] * x[right] + y[left] * y[right];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
sums.count += moments[0];
|
|
43
|
+
sums.x += x[0] * moments[0] + x[2] * moments[1];
|
|
44
|
+
sums.y += y[0] * moments[0] + y[2] * moments[1];
|
|
45
|
+
sums.xx += sumEvenProducts(x, x, moments);
|
|
46
|
+
sums.xy += sumEvenProducts(x, y, moments);
|
|
47
|
+
sums.yy += sumEvenProducts(y, y, moments);
|
|
48
|
+
sums.xr += sumEvenProducts(x, radiusSquared, moments);
|
|
49
|
+
sums.yr += sumEvenProducts(y, radiusSquared, moments);
|
|
50
|
+
}
|
|
51
|
+
function includeQuadraticSamples(sums, start, end, bowX, bowY, steps, origin) {
|
|
52
|
+
const halfX = (end.x - start.x) / 2;
|
|
53
|
+
const halfY = (end.y - start.y) / 2;
|
|
54
|
+
includePolynomialSamples(sums, [start.x + halfX - bowX - origin.x, halfX, bowX], [start.y + halfY - bowY - origin.y, halfY, bowY], steps);
|
|
55
|
+
}
|
|
56
|
+
function cubicCoefficients(start, first, second, end, origin) {
|
|
57
|
+
const a = first - start;
|
|
58
|
+
const b = second - first;
|
|
59
|
+
const c = end - second;
|
|
60
|
+
return [start - origin + (7 * a + 4 * b + c) / 8, (3 * (a + 2 * b + c)) / 8, (3 * (c - a)) / 8, (a - 2 * b + c) / 8];
|
|
61
|
+
}
|
|
62
|
+
function includePoint(sums, point, origin) {
|
|
63
|
+
const x = point.x - origin.x;
|
|
64
|
+
const y = point.y - origin.y;
|
|
65
|
+
const radiusSquared = x * x + y * y;
|
|
66
|
+
sums.count++;
|
|
67
|
+
sums.x += x;
|
|
68
|
+
sums.y += y;
|
|
69
|
+
sums.xx += x * x;
|
|
70
|
+
sums.xy += x * y;
|
|
71
|
+
sums.yy += y * y;
|
|
72
|
+
sums.xr += x * radiusSquared;
|
|
73
|
+
sums.yr += y * radiusSquared;
|
|
74
|
+
}
|
|
75
|
+
function cornerSampleSteps(corner, samplePitchM) {
|
|
76
|
+
if (corner.kind === PolygonCornerKind.Cubic) {
|
|
77
|
+
const { before, control1, control2, after } = corner;
|
|
78
|
+
const length = Math.hypot(control1.x - before.x, control1.y - before.y) +
|
|
79
|
+
Math.hypot(control2.x - control1.x, control2.y - control1.y) +
|
|
80
|
+
Math.hypot(after.x - control2.x, after.y - control2.y);
|
|
81
|
+
return Math.max(2, Math.ceil(length / samplePitchM));
|
|
82
|
+
}
|
|
83
|
+
const { before, after, radius, sweep } = corner;
|
|
84
|
+
const chord = Math.hypot(after.x - before.x, after.y - before.y);
|
|
85
|
+
const trim = radius * Math.tan(Math.abs(sweep) / 2);
|
|
86
|
+
return Math.max(2, Math.round((chord + 4 * trim) / (3 * samplePitchM)));
|
|
87
|
+
}
|
|
88
|
+
function sideSampleSteps(start, end, bowX, bowY, pitchM) {
|
|
89
|
+
const chord = Math.hypot(end.x - start.x, end.y - start.y);
|
|
90
|
+
const controlLength = Math.hypot(chord, 4 * Math.hypot(bowX, bowY));
|
|
91
|
+
return Math.max(2, Math.ceil((chord + 2 * controlLength) / (3 * pitchM)));
|
|
92
|
+
}
|
|
93
|
+
function includeCorner(sums, corner, origin, samplePitchM) {
|
|
94
|
+
if (corner.kind === PolygonCornerKind.Cubic) {
|
|
95
|
+
const { before, control1, control2, after } = corner;
|
|
96
|
+
includePoint(sums, before, origin);
|
|
97
|
+
includePolynomialSamples(sums, cubicCoefficients(before.x, control1.x, control2.x, after.x, origin.x), cubicCoefficients(before.y, control1.y, control2.y, after.y, origin.y), cornerSampleSteps(corner, samplePitchM));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const { before, after, center, radius, sweep } = corner;
|
|
101
|
+
const dx = after.x - before.x;
|
|
102
|
+
const dy = after.y - before.y;
|
|
103
|
+
const count = cornerSampleSteps(corner, samplePitchM);
|
|
104
|
+
if (Math.abs(sweep) < ShallowCornerSweepRad) {
|
|
105
|
+
// For a shallow turn, use the same midpoint sagitta without subtracting a distant circle center.
|
|
106
|
+
const bowPerChord = Math.tan(sweep / 4) / 2;
|
|
107
|
+
includePoint(sums, before, origin);
|
|
108
|
+
includeQuadraticSamples(sums, before, after, -dy * bowPerChord, dx * bowPerChord, count, origin);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const startAngle = Math.atan2(before.y - center.y, before.x - center.x);
|
|
112
|
+
const step = sweep / count;
|
|
113
|
+
const middleAngle = startAngle + ((count - 1) * step) / 2;
|
|
114
|
+
// Sum the equally spaced directions and their second moments without allocating samples.
|
|
115
|
+
const first = Math.sin(sweep / 2) / Math.sin(step / 2);
|
|
116
|
+
const second = Math.sin(sweep) / Math.sin(step);
|
|
117
|
+
const ux = first * Math.cos(middleAngle);
|
|
118
|
+
const uy = first * Math.sin(middleAngle);
|
|
119
|
+
const uxx = (count + second * Math.cos(2 * middleAngle)) / 2;
|
|
120
|
+
const uxy = (second * Math.sin(2 * middleAngle)) / 2;
|
|
121
|
+
const uyy = count - uxx;
|
|
122
|
+
const x = center.x - origin.x;
|
|
123
|
+
const y = center.y - origin.y;
|
|
124
|
+
const radiusSquared = radius * radius;
|
|
125
|
+
const squaredLength = x * x + y * y + radiusSquared;
|
|
126
|
+
const sumSquaredLengths = count * squaredLength + 2 * radius * (x * ux + y * uy);
|
|
127
|
+
sums.count += count;
|
|
128
|
+
sums.x += count * x + radius * ux;
|
|
129
|
+
sums.y += count * y + radius * uy;
|
|
130
|
+
sums.xx += count * x * x + 2 * radius * x * ux + radiusSquared * uxx;
|
|
131
|
+
sums.xy += count * x * y + radius * (x * uy + y * ux) + radiusSquared * uxy;
|
|
132
|
+
sums.yy += count * y * y + 2 * radius * y * uy + radiusSquared * uyy;
|
|
133
|
+
sums.xr += x * sumSquaredLengths + radius * squaredLength * ux + 2 * radiusSquared * (x * uxx + y * uxy);
|
|
134
|
+
sums.yr += y * sumSquaredLengths + radius * squaredLength * uy + 2 * radiusSquared * (x * uxy + y * uyy);
|
|
135
|
+
}
|
|
136
|
+
function outlineSampleMoments(outline, samplePitchM) {
|
|
137
|
+
const { outer, edgeCurvature } = outline;
|
|
138
|
+
const origin = { x: 0, y: 0 };
|
|
139
|
+
for (const point of outer) {
|
|
140
|
+
origin.x += point.x / outer.length;
|
|
141
|
+
origin.y += point.y / outer.length;
|
|
142
|
+
}
|
|
143
|
+
const corners = polygonCornerFillets(outline);
|
|
144
|
+
const sums = { count: 0, x: 0, y: 0, xx: 0, xy: 0, yy: 0, xr: 0, yr: 0 };
|
|
145
|
+
outer.forEach((point, index) => {
|
|
146
|
+
const nextIndex = (index + 1) % outer.length;
|
|
147
|
+
const next = outer[nextIndex];
|
|
148
|
+
const corner = corners[index];
|
|
149
|
+
if (corner)
|
|
150
|
+
includeCorner(sums, corner, origin, samplePitchM);
|
|
151
|
+
const start = corner?.after ?? point;
|
|
152
|
+
const end = corners[nextIndex]?.before ?? next;
|
|
153
|
+
includePoint(sums, start, origin);
|
|
154
|
+
const curvature = edgeCurvature?.[index];
|
|
155
|
+
if (curvature) {
|
|
156
|
+
const middle = sideCurvePoint(point, next, curvature, 0.5);
|
|
157
|
+
const bowX = (point.x + next.x) / 2 - middle.x;
|
|
158
|
+
const bowY = (point.y + next.y) / 2 - middle.y;
|
|
159
|
+
const steps = sideSampleSteps(start, end, bowX, bowY, samplePitchM);
|
|
160
|
+
includeQuadraticSamples(sums, start, end, bowX, bowY, steps, origin);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return { origin, sums };
|
|
164
|
+
}
|
|
165
|
+
export function sectionOutlineSamplingScale(section) {
|
|
166
|
+
return ((section.scalePercent ?? SectionScale.initial) / SectionScale.initial) * (section.outlineGrowthFactor ?? 1);
|
|
167
|
+
}
|
|
168
|
+
/** Fill and Grow use the same authored boundary samples as the reference planner. */
|
|
169
|
+
export function sectionOutlineSampleContour(outline, currentScale) {
|
|
170
|
+
const curved = outline.edgeCurvature?.some(Boolean);
|
|
171
|
+
const corners = polygonCornerFillets(outline);
|
|
172
|
+
if (!curved && !corners.some(Boolean))
|
|
173
|
+
return outline;
|
|
174
|
+
const cached = sampleContours.get(outline);
|
|
175
|
+
if (cached?.scale === currentScale)
|
|
176
|
+
return cached.contour;
|
|
177
|
+
const pitchM = SamplePitchM * currentScale;
|
|
178
|
+
const spans = outline.outer.map((point, side) => {
|
|
179
|
+
const nextIndex = (side + 1) % outline.outer.length;
|
|
180
|
+
const next = outline.outer[nextIndex];
|
|
181
|
+
const corner = corners[side];
|
|
182
|
+
const start = corner?.after ?? point;
|
|
183
|
+
const end = corners[nextIndex]?.before ?? next;
|
|
184
|
+
const curvature = outline.edgeCurvature?.[side] ?? 0;
|
|
185
|
+
const midpoint = sideCurvePoint(point, next, curvature, 0.5);
|
|
186
|
+
const bowX = (point.x + next.x) / 2 - midpoint.x;
|
|
187
|
+
const bowY = (point.y + next.y) / 2 - midpoint.y;
|
|
188
|
+
return {
|
|
189
|
+
start,
|
|
190
|
+
end,
|
|
191
|
+
corner,
|
|
192
|
+
bowX,
|
|
193
|
+
bowY,
|
|
194
|
+
cornerSteps: corner ? cornerSampleSteps(corner, pitchM) : 0,
|
|
195
|
+
sideSteps: curvature ? sideSampleSteps(start, end, bowX, bowY, pitchM) : 1,
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
const vertices = spans.reduce((count, span) => count + span.cornerSteps + span.sideSteps, 0);
|
|
199
|
+
const contour = vertices > PolygonVertexLimit
|
|
200
|
+
? polygonContour(outline)
|
|
201
|
+
: {
|
|
202
|
+
outer: spans.flatMap(({ start, end, corner, bowX, bowY, cornerSteps, sideSteps }) => {
|
|
203
|
+
const points = corner ? polygonCornerSamples(corner, cornerSteps) : [];
|
|
204
|
+
for (let i = 0; i < sideSteps; i++) {
|
|
205
|
+
const t = i / sideSteps;
|
|
206
|
+
const bow = 4 * t * (1 - t);
|
|
207
|
+
points.push({
|
|
208
|
+
x: start.x + (end.x - start.x) * t - bow * bowX,
|
|
209
|
+
y: start.y + (end.y - start.y) * t - bow * bowY,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return points;
|
|
213
|
+
}),
|
|
214
|
+
holes: outline.holes,
|
|
215
|
+
};
|
|
216
|
+
sampleContours.set(outline, { scale: currentScale, contour });
|
|
217
|
+
return contour;
|
|
218
|
+
}
|
|
219
|
+
/** Scale the sampling pitch with the section to retain the authored sample count. */
|
|
220
|
+
export function sectionOutlineSampleCenter(outline, currentScale) {
|
|
221
|
+
const { origin, sums } = outlineSampleMoments(outline, SamplePitchM * currentScale);
|
|
222
|
+
return { x: origin.x + sums.x / sums.count, y: origin.y + sums.y / sums.count };
|
|
223
|
+
}
|
|
224
|
+
/** Fit an algebraic circle to the authored boundary spans and their corner fillets. */
|
|
225
|
+
export function sectionOutlineRefitPoint(outline, currentScale) {
|
|
226
|
+
const cached = fittedPoints.get(outline);
|
|
227
|
+
if (cached?.scale === currentScale)
|
|
228
|
+
return cached.point;
|
|
229
|
+
const { origin, sums } = outlineSampleMoments(outline, SamplePitchM * currentScale);
|
|
230
|
+
const centerX = sums.x / sums.count;
|
|
231
|
+
const centerY = sums.y / sums.count;
|
|
232
|
+
const xx = sums.xx - sums.x * centerX;
|
|
233
|
+
const xy = sums.xy - sums.x * centerY;
|
|
234
|
+
const yy = sums.yy - sums.y * centerY;
|
|
235
|
+
const radiusSquaredSum = sums.xx + sums.yy;
|
|
236
|
+
const xr = sums.xr - centerX * radiusSquaredSum - 2 * (centerX * xx + centerY * xy);
|
|
237
|
+
const yr = sums.yr - centerY * radiusSquaredSum - 2 * (centerX * xy + centerY * yy);
|
|
238
|
+
const determinant = xx * yy - xy * xy;
|
|
239
|
+
const fit = { x: origin.x + centerX, y: origin.y + centerY };
|
|
240
|
+
if (determinant > Number.EPSILON * xx * yy) {
|
|
241
|
+
fit.x += (xr * yy - yr * xy) / (2 * determinant);
|
|
242
|
+
fit.y += (yr * xx - xr * xy) / (2 * determinant);
|
|
243
|
+
}
|
|
244
|
+
fittedPoints.set(outline, { scale: currentScale, point: fit });
|
|
245
|
+
return fit;
|
|
246
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type PhysicalDocumentV1, type Section, type UUID } from "./physical-document.interface.js";
|
|
3
|
+
import { RefitFollow, type RefitMeasuredRow, type RefitLayoutChange, type RefitRow } from "./section-refit.interface.js";
|
|
4
|
+
export { RefitFollow, type SectionRefitInput } from "./section-refit.interface.js";
|
|
5
|
+
export declare const sectionRefitInputSchema: z.ZodObject<{
|
|
6
|
+
sectionId: z.ZodUUID;
|
|
7
|
+
follow: z.ZodEnum<typeof RefitFollow>;
|
|
8
|
+
strength: z.ZodNumber;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
/** Preview entry follows active seat contact. The fit itself uses physical row membership. */
|
|
11
|
+
export declare function sectionRefitPreviewAvailable(document: PhysicalDocumentV1, section: Section): boolean;
|
|
12
|
+
export declare function sectionRefitRows(document: PhysicalDocumentV1, section: Section, follow: RefitFollow, protectedOwner: (id: UUID) => UUID | undefined): {
|
|
13
|
+
rows: RefitRow[];
|
|
14
|
+
kept: number;
|
|
15
|
+
};
|
|
16
|
+
/** Compute the row updates from current geometry without measuring per-seat preview distances. */
|
|
17
|
+
export declare function sectionRefitLayoutChanges(rows: readonly RefitRow[], strength: number): RefitLayoutChange[];
|
|
18
|
+
export declare function measureSectionRefit(rows: readonly RefitRow[], strength: number): {
|
|
19
|
+
measured: RefitMeasuredRow[];
|
|
20
|
+
averageMoveM: number;
|
|
21
|
+
largestMoveM: number;
|
|
22
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { sectionRefitInputSchema } from "./section-refit.js";
|
|
3
|
+
import { type PointM, type RowInventory, type RowLayout, type RowSlot, type UUID } from "./physical-document.interface.js";
|
|
4
|
+
export declare enum RefitFollow {
|
|
5
|
+
Floor = "floor",
|
|
6
|
+
Outline = "outline"
|
|
7
|
+
}
|
|
8
|
+
export type SectionRefitInput = z.infer<typeof sectionRefitInputSchema>;
|
|
9
|
+
export interface RefitLayoutChange {
|
|
10
|
+
groupId: UUID;
|
|
11
|
+
rowId: UUID;
|
|
12
|
+
layout: RowLayout;
|
|
13
|
+
}
|
|
14
|
+
export interface RefitTarget {
|
|
15
|
+
curveDeg: number;
|
|
16
|
+
facingDeg: number;
|
|
17
|
+
reflected: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface RefitRow {
|
|
20
|
+
group: RowInventory;
|
|
21
|
+
row: RowSlot;
|
|
22
|
+
index: number;
|
|
23
|
+
current: RowLayout;
|
|
24
|
+
target: RefitTarget;
|
|
25
|
+
}
|
|
26
|
+
export interface RefitMeasuredRow {
|
|
27
|
+
id: UUID;
|
|
28
|
+
label: string;
|
|
29
|
+
beforeCurveDeg: number;
|
|
30
|
+
layout: RowLayout;
|
|
31
|
+
largestMoveM: number;
|
|
32
|
+
}
|
|
33
|
+
export interface RefitTargetInput {
|
|
34
|
+
pitchM: number;
|
|
35
|
+
anchor: PointM;
|
|
36
|
+
point: PointM;
|
|
37
|
+
intervals: number;
|
|
38
|
+
pathRotationDeg: number;
|
|
39
|
+
}
|
|
40
|
+
export interface OutlineRefitSums {
|
|
41
|
+
count: number;
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
xx: number;
|
|
45
|
+
xy: number;
|
|
46
|
+
yy: number;
|
|
47
|
+
xr: number;
|
|
48
|
+
yr: number;
|
|
49
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { generatedSeats, inverse, normalizeAngle, project, worldMatrices } from "./geometry/geometry.js";
|
|
3
|
+
import { BoundaryLocation, classifyBoundary, prepareBoundary } from "./geometry/boundary.js";
|
|
4
|
+
import { rowPlacementOffset, resolveRowLayout, rowSeatGeometry } from "./geometry/seating-layout.js";
|
|
5
|
+
import { rowDisplayLabel } from "./labels.js";
|
|
6
|
+
import { sectionCatalog } from "./sections.js";
|
|
7
|
+
import { RowRefitStrength, SectionOutlineRole, } from "./physical-document.interface.js";
|
|
8
|
+
import { authoredFloorFocalPoint, DefaultFloorFocalPoint } from "./floors.js";
|
|
9
|
+
import { sectionOutlineRefitPoint, sectionOutlineSamplingScale } from "./section-outline-refit.js";
|
|
10
|
+
import { RefitFollow, } from "./section-refit.interface.js";
|
|
11
|
+
export { RefitFollow } from "./section-refit.interface.js";
|
|
12
|
+
export const sectionRefitInputSchema = z.strictObject({
|
|
13
|
+
sectionId: z.uuid(),
|
|
14
|
+
follow: z.enum(RefitFollow),
|
|
15
|
+
strength: z.number().int().min(RowRefitStrength.min).max(RowRefitStrength.max),
|
|
16
|
+
});
|
|
17
|
+
const DegreesPerRadian = 180 / Math.PI;
|
|
18
|
+
const FullTurn = 360;
|
|
19
|
+
function targetSweep(pitch, intervals, radius) {
|
|
20
|
+
if (radius < pitch / 2)
|
|
21
|
+
return null;
|
|
22
|
+
const step = 2 * Math.asin(pitch / (2 * radius));
|
|
23
|
+
return Math.min(FullTurn, step * intervals * DegreesPerRadian);
|
|
24
|
+
}
|
|
25
|
+
function rowRefitTarget({ pitchM, anchor, point, intervals, pathRotationDeg }, matrix, local) {
|
|
26
|
+
const origin = project(matrix, anchor);
|
|
27
|
+
const x = point.x - origin.x;
|
|
28
|
+
const y = point.y - origin.y;
|
|
29
|
+
const sweep = targetSweep(pitchM, intervals, Math.hypot(x, y));
|
|
30
|
+
if (sweep === null)
|
|
31
|
+
return null;
|
|
32
|
+
const tangent = Math.atan2(local.b * -y + local.d * x, local.a * -y + local.c * x) * DegreesPerRadian;
|
|
33
|
+
// Choose the tangent direction closest to the row's existing seat path.
|
|
34
|
+
const reversed = Math.abs(normalizeAngle(pathRotationDeg - tangent)) > 90;
|
|
35
|
+
const reflected = matrix.a * matrix.d - matrix.b * matrix.c < 0;
|
|
36
|
+
return {
|
|
37
|
+
curveDeg: reversed !== reflected ? -sweep : sweep,
|
|
38
|
+
facingDeg: tangent,
|
|
39
|
+
reflected,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Preview entry follows active seat contact. The fit itself uses physical row membership. */
|
|
43
|
+
export function sectionRefitPreviewAvailable(document, section) {
|
|
44
|
+
if (!section.outline || section.outlineRole === SectionOutlineRole.Overview) {
|
|
45
|
+
const inventory = sectionCatalog(document).entries.get(section.id)?.inventory;
|
|
46
|
+
return document.seatingGroups.some((group) => "rows" in group && group.rows.some((row) => inventory?.has(row.id) && row.seats.some((seat) => !seat.gap)));
|
|
47
|
+
}
|
|
48
|
+
const boundary = prepareBoundary(section.outline);
|
|
49
|
+
const earlier = [];
|
|
50
|
+
for (const candidate of document.sections) {
|
|
51
|
+
if (candidate.id === section.id)
|
|
52
|
+
break;
|
|
53
|
+
if (candidate.floorId === section.floorId &&
|
|
54
|
+
candidate.outline &&
|
|
55
|
+
candidate.outlineRole !== SectionOutlineRole.Overview)
|
|
56
|
+
earlier.push(prepareBoundary(candidate.outline));
|
|
57
|
+
}
|
|
58
|
+
const matrices = worldMatrices(document);
|
|
59
|
+
return document.seatingGroups.some((group) => {
|
|
60
|
+
if (!("rows" in group) || group.floorId !== section.floorId)
|
|
61
|
+
return false;
|
|
62
|
+
const matrix = matrices.get(group.id);
|
|
63
|
+
return generatedSeats(group).some((seat) => {
|
|
64
|
+
if (seat.slot.gap)
|
|
65
|
+
return false;
|
|
66
|
+
const point = project(matrix, seat.position);
|
|
67
|
+
return (classifyBoundary(boundary, point) !== BoundaryLocation.Outside &&
|
|
68
|
+
earlier.every((target) => classifyBoundary(target, point) === BoundaryLocation.Outside));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export function sectionRefitRows(document, section, follow, protectedOwner) {
|
|
73
|
+
const entry = sectionCatalog(document).entries.get(section.id);
|
|
74
|
+
const point = follow === RefitFollow.Outline
|
|
75
|
+
? section.outline && sectionOutlineRefitPoint(section.outline, sectionOutlineSamplingScale(section))
|
|
76
|
+
: (authoredFloorFocalPoint(document, section.floorId ?? null) ?? DefaultFloorFocalPoint);
|
|
77
|
+
if (!point)
|
|
78
|
+
return { rows: [], kept: 0 };
|
|
79
|
+
const matrices = worldMatrices(document);
|
|
80
|
+
const rows = [];
|
|
81
|
+
let kept = 0;
|
|
82
|
+
for (const group of document.seatingGroups) {
|
|
83
|
+
if (!("rows" in group) || !entry?.renderMembers.has(group.id))
|
|
84
|
+
continue;
|
|
85
|
+
const matrix = matrices.get(group.id);
|
|
86
|
+
const local = inverse(matrix);
|
|
87
|
+
group.rows.forEach((row, index) => {
|
|
88
|
+
if (!entry.editableObjects.has(row.id))
|
|
89
|
+
return;
|
|
90
|
+
const intervals = row.seats.length - 1;
|
|
91
|
+
if (intervals < 1)
|
|
92
|
+
return;
|
|
93
|
+
const current = resolveRowLayout(group, index);
|
|
94
|
+
if (!current || protectedOwner(row.id)) {
|
|
95
|
+
kept++;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const offset = rowPlacementOffset(group, index, row.offsetM);
|
|
99
|
+
const targetInput = {
|
|
100
|
+
pitchM: current.seatPitchM,
|
|
101
|
+
pathRotationDeg: current.rotationDeg,
|
|
102
|
+
anchor: {
|
|
103
|
+
x: current.originM.x + offset.x,
|
|
104
|
+
y: current.originM.y + offset.y,
|
|
105
|
+
},
|
|
106
|
+
point,
|
|
107
|
+
intervals,
|
|
108
|
+
};
|
|
109
|
+
const target = rowRefitTarget(targetInput, matrix, local);
|
|
110
|
+
if (target)
|
|
111
|
+
rows.push({ group, row, index, current, target });
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return { rows, kept };
|
|
115
|
+
}
|
|
116
|
+
function fittedLayout(current, target, fraction) {
|
|
117
|
+
if (!fraction)
|
|
118
|
+
return current;
|
|
119
|
+
const curveDeg = current.curveDeg + (target.curveDeg - current.curveDeg) * fraction;
|
|
120
|
+
const interpolateAngle = (from, to) => normalizeAngle(from + normalizeAngle(to - from) * fraction);
|
|
121
|
+
// Blend the facing angle before converting a negative bend to a reversed seat path.
|
|
122
|
+
const currentOffset = current.seatRotationOffsetDeg ?? 0;
|
|
123
|
+
const facing = interpolateAngle(current.rotationDeg + currentOffset, target.facingDeg);
|
|
124
|
+
const seatRotationOffsetDeg = curveDeg * (target.reflected ? -1 : 1) < 0 ? -180 : 0;
|
|
125
|
+
return {
|
|
126
|
+
...current,
|
|
127
|
+
curveDeg,
|
|
128
|
+
rotationDeg: normalizeAngle(facing - seatRotationOffsetDeg),
|
|
129
|
+
...(currentOffset !== seatRotationOffsetDeg && { seatRotationOffsetDeg }),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** Compute the row updates from current geometry without measuring per-seat preview distances. */
|
|
133
|
+
export function sectionRefitLayoutChanges(rows, strength) {
|
|
134
|
+
const fraction = strength / RowRefitStrength.max;
|
|
135
|
+
const changes = [];
|
|
136
|
+
for (const { group, row, current, target } of rows) {
|
|
137
|
+
const layout = fittedLayout(current, target, fraction);
|
|
138
|
+
if (layout.curveDeg !== current.curveDeg ||
|
|
139
|
+
layout.rotationDeg !== current.rotationDeg ||
|
|
140
|
+
layout.seatRotationOffsetDeg !== current.seatRotationOffsetDeg) {
|
|
141
|
+
changes.push({ groupId: group.id, rowId: row.id, layout });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return changes;
|
|
145
|
+
}
|
|
146
|
+
export function measureSectionRefit(rows, strength) {
|
|
147
|
+
const fraction = strength / RowRefitStrength.max;
|
|
148
|
+
const measured = [];
|
|
149
|
+
let rowRmsSumM = 0;
|
|
150
|
+
let largestMoveM = 0;
|
|
151
|
+
for (const { group, row, index, current, target } of rows) {
|
|
152
|
+
const layout = fittedLayout(current, target, fraction);
|
|
153
|
+
let seatCount = 0;
|
|
154
|
+
let squaredMoveSum = 0;
|
|
155
|
+
let largestSquaredMove = 0;
|
|
156
|
+
row.seats.forEach((seat, seatIndex) => {
|
|
157
|
+
if (seat.gap)
|
|
158
|
+
return;
|
|
159
|
+
const before = rowSeatGeometry(group, index, seatIndex, row.seats.length, row.seats.length, current).position;
|
|
160
|
+
const after = rowSeatGeometry(group, index, seatIndex, row.seats.length, row.seats.length, layout).position;
|
|
161
|
+
const squaredMove = (after.x - before.x) ** 2 + (after.y - before.y) ** 2;
|
|
162
|
+
squaredMoveSum += squaredMove;
|
|
163
|
+
largestSquaredMove = Math.max(largestSquaredMove, squaredMove);
|
|
164
|
+
seatCount++;
|
|
165
|
+
});
|
|
166
|
+
// A fully gapped row still fits. Its empty set of seat movements has no mean or maximum.
|
|
167
|
+
rowRmsSumM += Math.sqrt(squaredMoveSum / seatCount);
|
|
168
|
+
const rowLargestMoveM = seatCount ? Math.sqrt(largestSquaredMove) : Number.NEGATIVE_INFINITY;
|
|
169
|
+
largestMoveM = Math.max(largestMoveM, rowLargestMoveM);
|
|
170
|
+
measured.push({
|
|
171
|
+
id: row.id,
|
|
172
|
+
label: rowDisplayLabel(group, index),
|
|
173
|
+
beforeCurveDeg: current.curveDeg,
|
|
174
|
+
layout,
|
|
175
|
+
largestMoveM: rowLargestMoveM,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return { measured, averageMoveM: rows.length ? rowRmsSumM / rows.length : 0, largestMoveM };
|
|
179
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { type PhysicalDocumentV1, type PointM, type UUID } from "./physical-document.interface.js";
|
|
2
|
+
export declare function scaleSectionLayout(document: PhysicalDocumentV1, sectionId: UUID, targets: ReadonlySet<UUID>, pivot: PointM, scalePercent: number, factor: number): PhysicalDocumentV1;
|