@pascal-app/editor 1.0.0-beta.3 → 1.0.0-beta.5
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/package.json +7 -6
- package/src/components/editor/alignment-3d-guide-layer.tsx +12 -3
- package/src/components/editor/editor-layout-v2.tsx +8 -3
- package/src/components/editor/elevation-3d-guide-layer.tsx +3 -2
- package/src/components/editor/first-person-controls.tsx +2 -45
- package/src/components/editor/floating-action-menu.tsx +13 -4
- package/src/components/editor/floorplan-background-selection.test.ts +31 -4
- package/src/components/editor/floorplan-background-selection.ts +27 -7
- package/src/components/editor/floorplan-panel.tsx +5 -45
- package/src/components/editor/group-floating-action-menu.tsx +30 -15
- package/src/components/editor/index.tsx +112 -25
- package/src/components/editor/measurement-pill.tsx +12 -12
- package/src/components/editor/node-action-menu.tsx +29 -1
- package/src/components/editor/opening-guides-3d-layer.tsx +13 -4
- package/src/components/editor/selection-manager.tsx +28 -5
- package/src/components/editor/site-edge-labels.tsx +2 -1
- package/src/components/editor/snapshot-capture-overlay.tsx +11 -2
- package/src/components/editor/thumbnail-generator.tsx +27 -11
- package/src/components/editor/wall-measurement-label.tsx +3 -2
- package/src/components/editor-2d/floorplan-group-action-menu.tsx +23 -16
- package/src/components/editor-2d/renderers/floorplan-registry-layer.tsx +26 -84
- package/src/components/tools/item/placement-strategies.test.ts +167 -0
- package/src/components/tools/item/placement-strategies.ts +57 -22
- package/src/components/tools/item/use-placement-coordinator.tsx +19 -27
- package/src/components/tools/shared/placement-box.tsx +9 -4
- package/src/components/tools/site/terrain-brush-cursor.tsx +2 -1
- package/src/components/tools/wall/wall-drafting.test.ts +207 -2
- package/src/components/tools/wall/wall-drafting.ts +84 -400
- package/src/components/ui/command-palette/editor-commands.tsx +3 -1
- package/src/components/ui/floating-level-selector.tsx +1 -1
- package/src/components/ui/panels/multi-selection-panel.tsx +54 -13
- package/src/components/ui/panels/panel-wrapper.tsx +228 -12
- package/src/components/ui/sidebar/panels/items-panel/function-tree-panel.tsx +7 -2
- package/src/components/ui/sidebar/panels/settings-panel/keyboard-shortcuts-dialog.tsx +11 -0
- package/src/components/ui/sidebar/panels/site-panel/index.tsx +12 -0
- package/src/components/ui/sidebar/panels/site-panel/tree-node.tsx +8 -1
- package/src/components/ui/sidebar/tab-bar.tsx +7 -1
- package/src/components/viewer/floorplan-compass-button.tsx +50 -0
- package/src/components/viewer/floorplan-preview-geometry.test.ts +107 -0
- package/src/components/viewer/floorplan-preview-geometry.ts +281 -0
- package/src/components/viewer/floorplan-preview-navigation.test.ts +43 -0
- package/src/components/viewer/floorplan-preview-navigation.ts +62 -0
- package/src/components/viewer/floorplan-preview.tsx +1069 -0
- package/src/components/viewer/use-viewer-camera-navigation-sync.ts +140 -0
- package/src/components/viewer/viewer-stage-modes.test.ts +38 -0
- package/src/components/viewer/viewer-stage-modes.ts +49 -0
- package/src/components/viewer/viewer-stage-switcher.tsx +95 -0
- package/src/components/viewer/viewer-stage.test.tsx +47 -0
- package/src/components/viewer/viewer-stage.tsx +218 -0
- package/src/components/viewer-overlay.tsx +12 -8
- package/src/hooks/use-auto-save.test.ts +50 -1
- package/src/hooks/use-auto-save.ts +44 -9
- package/src/hooks/use-keyboard.ts +35 -1
- package/src/index.tsx +27 -0
- package/src/lib/contextual-help.test.ts +8 -0
- package/src/lib/contextual-help.ts +8 -0
- package/src/lib/floorplan/floorplan-readonly.test.ts +47 -0
- package/src/lib/floorplan/floorplan-readonly.ts +84 -0
- package/src/lib/history.test.ts +75 -10
- package/src/lib/history.ts +58 -13
- package/src/lib/inspector-card-mode.test.ts +92 -0
- package/src/lib/inspector-card-mode.ts +60 -0
- package/src/lib/measurement-parser.ts +3 -0
- package/src/lib/measurements.test.ts +4 -0
- package/src/lib/paint-scope.test.ts +58 -2
- package/src/lib/paint-scope.ts +8 -2
- package/src/lib/selection-routing.test.ts +20 -5
- package/src/lib/selection-routing.ts +15 -1
- package/src/lib/session-groups.test.ts +88 -0
- package/src/lib/session-groups.ts +201 -0
- package/src/lib/structured-clone-fallback.test.ts +45 -0
- package/src/lib/structured-clone-fallback.ts +24 -0
- package/src/store/use-session-groups.ts +103 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import type { FloorplanGeometry, FloorplanPoint } from '@pascal-app/core'
|
|
2
|
+
|
|
3
|
+
export type FloorplanBounds = {
|
|
4
|
+
minX: number
|
|
5
|
+
minY: number
|
|
6
|
+
maxX: number
|
|
7
|
+
maxY: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type FloorplanViewBox = { x: number; y: number; width: number; height: number }
|
|
11
|
+
|
|
12
|
+
export type FloorplanViewport = {
|
|
13
|
+
left: number
|
|
14
|
+
top: number
|
|
15
|
+
width: number
|
|
16
|
+
height: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type PlanTransform = { tx: number; ty: number; rotation: number }
|
|
20
|
+
|
|
21
|
+
const IDENTITY: PlanTransform = { tx: 0, ty: 0, rotation: 0 }
|
|
22
|
+
const MIN_VIEWBOX_SIZE = 0.25
|
|
23
|
+
const MAX_VIEWBOX_SIZE = 500
|
|
24
|
+
|
|
25
|
+
function clientToViewBoxFraction(
|
|
26
|
+
viewBox: FloorplanViewBox,
|
|
27
|
+
viewport: FloorplanViewport,
|
|
28
|
+
clientX: number,
|
|
29
|
+
clientY: number,
|
|
30
|
+
): FloorplanPoint {
|
|
31
|
+
const viewportWidth = Math.max(viewport.width, 1)
|
|
32
|
+
const viewportHeight = Math.max(viewport.height, 1)
|
|
33
|
+
const scale = Math.min(viewportWidth / viewBox.width, viewportHeight / viewBox.height)
|
|
34
|
+
const renderedWidth = viewBox.width * scale
|
|
35
|
+
const renderedHeight = viewBox.height * scale
|
|
36
|
+
const renderedLeft = viewport.left + (viewportWidth - renderedWidth) / 2
|
|
37
|
+
const renderedTop = viewport.top + (viewportHeight - renderedHeight) / 2
|
|
38
|
+
return [(clientX - renderedLeft) / renderedWidth, (clientY - renderedTop) / renderedHeight]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function clientToFloorplanPoint(
|
|
42
|
+
viewBox: FloorplanViewBox,
|
|
43
|
+
viewport: FloorplanViewport,
|
|
44
|
+
clientX: number,
|
|
45
|
+
clientY: number,
|
|
46
|
+
): FloorplanPoint {
|
|
47
|
+
const [fractionX, fractionY] = clientToViewBoxFraction(viewBox, viewport, clientX, clientY)
|
|
48
|
+
return [viewBox.x + fractionX * viewBox.width, viewBox.y + fractionY * viewBox.height]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function scaleFloorplanViewBox(
|
|
52
|
+
viewBox: FloorplanViewBox,
|
|
53
|
+
factor: number,
|
|
54
|
+
anchorX = 0.5,
|
|
55
|
+
anchorY = 0.5,
|
|
56
|
+
): FloorplanViewBox {
|
|
57
|
+
const minFactor = Math.max(MIN_VIEWBOX_SIZE / viewBox.width, MIN_VIEWBOX_SIZE / viewBox.height)
|
|
58
|
+
const maxFactor = Math.min(MAX_VIEWBOX_SIZE / viewBox.width, MAX_VIEWBOX_SIZE / viewBox.height)
|
|
59
|
+
const clampedFactor = Math.min(Math.max(factor, minFactor), maxFactor)
|
|
60
|
+
const width = viewBox.width * clampedFactor
|
|
61
|
+
const height = viewBox.height * clampedFactor
|
|
62
|
+
return {
|
|
63
|
+
x: viewBox.x + (viewBox.width - width) * anchorX,
|
|
64
|
+
y: viewBox.y + (viewBox.height - height) * anchorY,
|
|
65
|
+
width,
|
|
66
|
+
height,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function scaleFloorplanViewBoxBetweenClients(
|
|
71
|
+
viewBox: FloorplanViewBox,
|
|
72
|
+
factor: number,
|
|
73
|
+
viewport: FloorplanViewport,
|
|
74
|
+
sourceClient: FloorplanPoint,
|
|
75
|
+
targetClient: FloorplanPoint,
|
|
76
|
+
): FloorplanViewBox {
|
|
77
|
+
const sourcePoint = clientToFloorplanPoint(viewBox, viewport, sourceClient[0], sourceClient[1])
|
|
78
|
+
const [targetX, targetY] = clientToViewBoxFraction(
|
|
79
|
+
viewBox,
|
|
80
|
+
viewport,
|
|
81
|
+
targetClient[0],
|
|
82
|
+
targetClient[1],
|
|
83
|
+
)
|
|
84
|
+
const scaled = scaleFloorplanViewBox(viewBox, factor, 0, 0)
|
|
85
|
+
return {
|
|
86
|
+
...scaled,
|
|
87
|
+
x: sourcePoint[0] - targetX * scaled.width,
|
|
88
|
+
y: sourcePoint[1] - targetY * scaled.height,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function panFloorplanViewBox(
|
|
93
|
+
viewBox: FloorplanViewBox,
|
|
94
|
+
viewport: FloorplanViewport,
|
|
95
|
+
sourceClient: FloorplanPoint,
|
|
96
|
+
targetClient: FloorplanPoint,
|
|
97
|
+
): FloorplanViewBox {
|
|
98
|
+
const sourcePoint = clientToFloorplanPoint(viewBox, viewport, sourceClient[0], sourceClient[1])
|
|
99
|
+
const targetPoint = clientToFloorplanPoint(viewBox, viewport, targetClient[0], targetClient[1])
|
|
100
|
+
return {
|
|
101
|
+
...viewBox,
|
|
102
|
+
x: viewBox.x + sourcePoint[0] - targetPoint[0],
|
|
103
|
+
y: viewBox.y + sourcePoint[1] - targetPoint[1],
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function applyTransform(point: FloorplanPoint, transform: PlanTransform): FloorplanPoint {
|
|
108
|
+
const cos = Math.cos(transform.rotation)
|
|
109
|
+
const sin = Math.sin(transform.rotation)
|
|
110
|
+
return [
|
|
111
|
+
point[0] * cos - point[1] * sin + transform.tx,
|
|
112
|
+
point[0] * sin + point[1] * cos + transform.ty,
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function composeTransform(
|
|
117
|
+
parent: PlanTransform,
|
|
118
|
+
child: NonNullable<Extract<FloorplanGeometry, { kind: 'group' }>['transform']>,
|
|
119
|
+
): PlanTransform {
|
|
120
|
+
const translated = applyTransform(child.translate ?? [0, 0], parent)
|
|
121
|
+
return {
|
|
122
|
+
tx: translated[0],
|
|
123
|
+
ty: translated[1],
|
|
124
|
+
rotation: parent.rotation + (child.rotate ?? 0),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function includePoint(bounds: FloorplanBounds | null, point: FloorplanPoint): FloorplanBounds {
|
|
129
|
+
if (!bounds) return { minX: point[0], minY: point[1], maxX: point[0], maxY: point[1] }
|
|
130
|
+
return {
|
|
131
|
+
minX: Math.min(bounds.minX, point[0]),
|
|
132
|
+
minY: Math.min(bounds.minY, point[1]),
|
|
133
|
+
maxX: Math.max(bounds.maxX, point[0]),
|
|
134
|
+
maxY: Math.max(bounds.maxY, point[1]),
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function includePoints(
|
|
139
|
+
bounds: FloorplanBounds | null,
|
|
140
|
+
points: readonly FloorplanPoint[],
|
|
141
|
+
transform: PlanTransform,
|
|
142
|
+
): FloorplanBounds | null {
|
|
143
|
+
let next = bounds
|
|
144
|
+
for (const point of points) next = includePoint(next, applyTransform(point, transform))
|
|
145
|
+
return next
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function geometryBounds(
|
|
149
|
+
geometry: FloorplanGeometry,
|
|
150
|
+
transform: PlanTransform,
|
|
151
|
+
bounds: FloorplanBounds | null,
|
|
152
|
+
): FloorplanBounds | null {
|
|
153
|
+
switch (geometry.kind) {
|
|
154
|
+
case 'group': {
|
|
155
|
+
const nextTransform = geometry.transform
|
|
156
|
+
? composeTransform(transform, geometry.transform)
|
|
157
|
+
: transform
|
|
158
|
+
return geometry.children.reduce(
|
|
159
|
+
(next, child) => geometryBounds(child, nextTransform, next),
|
|
160
|
+
bounds,
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
case 'polygon':
|
|
164
|
+
case 'polyline':
|
|
165
|
+
case 'hatch':
|
|
166
|
+
return includePoints(bounds, geometry.points, transform)
|
|
167
|
+
case 'rect':
|
|
168
|
+
return includePoints(
|
|
169
|
+
bounds,
|
|
170
|
+
[
|
|
171
|
+
[geometry.x, geometry.y],
|
|
172
|
+
[geometry.x + geometry.width, geometry.y],
|
|
173
|
+
[geometry.x + geometry.width, geometry.y + geometry.height],
|
|
174
|
+
[geometry.x, geometry.y + geometry.height],
|
|
175
|
+
],
|
|
176
|
+
transform,
|
|
177
|
+
)
|
|
178
|
+
case 'circle': {
|
|
179
|
+
const center = applyTransform([geometry.cx, geometry.cy], transform)
|
|
180
|
+
return includePoints(
|
|
181
|
+
bounds,
|
|
182
|
+
[
|
|
183
|
+
[center[0] - geometry.r, center[1] - geometry.r],
|
|
184
|
+
[center[0] + geometry.r, center[1] + geometry.r],
|
|
185
|
+
],
|
|
186
|
+
IDENTITY,
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
case 'line':
|
|
190
|
+
case 'hit-line':
|
|
191
|
+
case 'edge-handle':
|
|
192
|
+
return includePoints(
|
|
193
|
+
bounds,
|
|
194
|
+
[
|
|
195
|
+
[geometry.x1, geometry.y1],
|
|
196
|
+
[geometry.x2, geometry.y2],
|
|
197
|
+
],
|
|
198
|
+
transform,
|
|
199
|
+
)
|
|
200
|
+
case 'text':
|
|
201
|
+
return includePoint(bounds, applyTransform([geometry.x, geometry.y], transform))
|
|
202
|
+
case 'image': {
|
|
203
|
+
const halfWidth = geometry.width / 2
|
|
204
|
+
const halfHeight = geometry.height / 2
|
|
205
|
+
const imageTransform = composeTransform(transform, {
|
|
206
|
+
translate: geometry.center,
|
|
207
|
+
rotate: geometry.rotation,
|
|
208
|
+
})
|
|
209
|
+
return includePoints(
|
|
210
|
+
bounds,
|
|
211
|
+
[
|
|
212
|
+
[-halfWidth, -halfHeight],
|
|
213
|
+
[halfWidth, -halfHeight],
|
|
214
|
+
[halfWidth, halfHeight],
|
|
215
|
+
[-halfWidth, halfHeight],
|
|
216
|
+
],
|
|
217
|
+
imageTransform,
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
case 'endpoint-handle':
|
|
221
|
+
case 'midpoint-handle':
|
|
222
|
+
case 'move-handle':
|
|
223
|
+
case 'move-arrow':
|
|
224
|
+
case 'rotate-arrow':
|
|
225
|
+
case 'equal-spacing-badge':
|
|
226
|
+
return includePoint(bounds, applyTransform(geometry.point, transform))
|
|
227
|
+
case 'dimension-label':
|
|
228
|
+
return includePoint(bounds, applyTransform([geometry.cx, geometry.cy], transform))
|
|
229
|
+
case 'dimension':
|
|
230
|
+
return includePoints(
|
|
231
|
+
bounds,
|
|
232
|
+
[
|
|
233
|
+
geometry.start,
|
|
234
|
+
geometry.end,
|
|
235
|
+
geometry.dimensionStart ?? geometry.start,
|
|
236
|
+
geometry.dimensionEnd ?? geometry.end,
|
|
237
|
+
],
|
|
238
|
+
transform,
|
|
239
|
+
)
|
|
240
|
+
case 'dimension-string':
|
|
241
|
+
return geometry.segments.reduce(
|
|
242
|
+
(next, segment) =>
|
|
243
|
+
includePoints(
|
|
244
|
+
next,
|
|
245
|
+
[
|
|
246
|
+
segment.start,
|
|
247
|
+
segment.end,
|
|
248
|
+
segment.dimensionStart ?? segment.start,
|
|
249
|
+
segment.dimensionEnd ?? segment.end,
|
|
250
|
+
],
|
|
251
|
+
transform,
|
|
252
|
+
),
|
|
253
|
+
bounds,
|
|
254
|
+
)
|
|
255
|
+
case 'path':
|
|
256
|
+
return bounds
|
|
257
|
+
default:
|
|
258
|
+
return bounds
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function getFloorplanBounds(
|
|
263
|
+
geometries: readonly FloorplanGeometry[],
|
|
264
|
+
): FloorplanBounds | null {
|
|
265
|
+
return geometries.reduce(
|
|
266
|
+
(bounds, geometry) => geometryBounds(geometry, IDENTITY, bounds),
|
|
267
|
+
null as FloorplanBounds | null,
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function padFloorplanBounds(bounds: FloorplanBounds, ratio = 0.12): FloorplanBounds {
|
|
272
|
+
const width = Math.max(bounds.maxX - bounds.minX, 1)
|
|
273
|
+
const height = Math.max(bounds.maxY - bounds.minY, 1)
|
|
274
|
+
const padding = Math.max(Math.max(width, height) * ratio, 0.75)
|
|
275
|
+
return {
|
|
276
|
+
minX: bounds.minX - padding,
|
|
277
|
+
minY: bounds.minY - padding,
|
|
278
|
+
maxX: bounds.maxX + padding,
|
|
279
|
+
maxY: bounds.maxY + padding,
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
cameraAzimuthFromFloorplanRotation,
|
|
4
|
+
floorplanRotationFromCameraAzimuth,
|
|
5
|
+
floorplanViewBoxFromNavigationPose,
|
|
6
|
+
nearestEquivalentDegrees,
|
|
7
|
+
visibleFloorplanViewWidth,
|
|
8
|
+
} from './floorplan-preview-navigation'
|
|
9
|
+
|
|
10
|
+
describe('floorplan preview navigation', () => {
|
|
11
|
+
test('keeps continuous compass rotations across the angle seam', () => {
|
|
12
|
+
expect(nearestEquivalentDegrees(-179, 179)).toBe(181)
|
|
13
|
+
expect(floorplanRotationFromCameraAzimuth((-179 * Math.PI) / 180, 179)).toBeCloseTo(181)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test('uses the same north-up azimuth convention as the editor', () => {
|
|
17
|
+
expect(cameraAzimuthFromFloorplanRotation(0)).toBe(0)
|
|
18
|
+
expect(cameraAzimuthFromFloorplanRotation(90)).toBeCloseTo(Math.PI / 2)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('maps a camera pose to an aspect-correct centered view box', () => {
|
|
22
|
+
expect(
|
|
23
|
+
floorplanViewBoxFromNavigationPose(
|
|
24
|
+
{
|
|
25
|
+
source: '3d',
|
|
26
|
+
revision: 1,
|
|
27
|
+
target: [0, 0, 0],
|
|
28
|
+
azimuth: 0,
|
|
29
|
+
viewWidth: 20,
|
|
30
|
+
},
|
|
31
|
+
{ x: 4, y: 3 },
|
|
32
|
+
0,
|
|
33
|
+
{ width: 1000, height: 500 },
|
|
34
|
+
),
|
|
35
|
+
).toEqual({ x: -6, y: -2, width: 20, height: 10 })
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('reports the actual horizontal span for meet-preserved SVG view boxes', () => {
|
|
39
|
+
expect(
|
|
40
|
+
visibleFloorplanViewWidth({ x: 0, y: 0, width: 10, height: 10 }, { width: 200, height: 100 }),
|
|
41
|
+
).toBe(20)
|
|
42
|
+
})
|
|
43
|
+
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { NavigationSyncPose } from '../../store/use-editor'
|
|
2
|
+
import type { FloorplanViewBox } from './floorplan-preview-geometry'
|
|
3
|
+
|
|
4
|
+
export type FloorplanPreviewViewportSize = {
|
|
5
|
+
width: number
|
|
6
|
+
height: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function nearestEquivalentDegrees(angle: number, reference: number) {
|
|
10
|
+
let next = angle
|
|
11
|
+
while (next - reference > 180) next -= 360
|
|
12
|
+
while (next - reference < -180) next += 360
|
|
13
|
+
return next
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function floorplanRotationFromCameraAzimuth(azimuth: number, reference: number) {
|
|
17
|
+
return nearestEquivalentDegrees((azimuth * 180) / Math.PI, reference)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function cameraAzimuthFromFloorplanRotation(rotationDeg: number) {
|
|
21
|
+
return (rotationDeg * Math.PI) / 180
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function rotateFloorplanPoint(
|
|
25
|
+
point: { x: number; y: number },
|
|
26
|
+
rotationDeg: number,
|
|
27
|
+
): { x: number; y: number } {
|
|
28
|
+
if (rotationDeg === 0) return point
|
|
29
|
+
const radians = (rotationDeg * Math.PI) / 180
|
|
30
|
+
const cos = Math.cos(radians)
|
|
31
|
+
const sin = Math.sin(radians)
|
|
32
|
+
return {
|
|
33
|
+
x: point.x * cos - point.y * sin,
|
|
34
|
+
y: point.x * sin + point.y * cos,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function visibleFloorplanViewWidth(
|
|
39
|
+
viewBox: FloorplanViewBox,
|
|
40
|
+
viewport: FloorplanPreviewViewportSize,
|
|
41
|
+
) {
|
|
42
|
+
const aspect = Math.max(viewport.width, 1) / Math.max(viewport.height, 1)
|
|
43
|
+
return Math.max(viewBox.width, viewBox.height * aspect)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function floorplanViewBoxFromNavigationPose(
|
|
47
|
+
pose: NavigationSyncPose,
|
|
48
|
+
localCenter: { x: number; y: number },
|
|
49
|
+
sceneRotationDeg: number,
|
|
50
|
+
viewport: FloorplanPreviewViewportSize,
|
|
51
|
+
): FloorplanViewBox {
|
|
52
|
+
const center = rotateFloorplanPoint(localCenter, sceneRotationDeg)
|
|
53
|
+
const aspect = Math.max(viewport.width, 1) / Math.max(viewport.height, 1)
|
|
54
|
+
const width = Math.max(pose.viewWidth, 0.001)
|
|
55
|
+
const height = width / aspect
|
|
56
|
+
return {
|
|
57
|
+
x: center.x - width / 2,
|
|
58
|
+
y: center.y - height / 2,
|
|
59
|
+
width,
|
|
60
|
+
height,
|
|
61
|
+
}
|
|
62
|
+
}
|