diff --git a/packages/editor/src/lib/editor/Editor.ts b/packages/editor/src/lib/editor/Editor.ts index fdaba114d..de43e3bc5 100644 --- a/packages/editor/src/lib/editor/Editor.ts +++ b/packages/editor/src/lib/editor/Editor.ts @@ -1647,19 +1647,24 @@ export class Editor extends EventEmitter { */ @computed getSelectionRotation(): number { const selectedShapeIds = this.getSelectedShapeIds() - if (selectedShapeIds.length === 0) { - return 0 - } - if (selectedShapeIds.length === 1) { - return this.getShapePageTransform(this.getSelectedShapeIds()[0])!.rotation() + let foundFirst = false // annoying but we can't use an i===0 check because we need to skip over undefineds + let rotation = 0 + for (let i = 0, n = selectedShapeIds.length; i < n; i++) { + const pageTransform = this.getShapePageTransform(selectedShapeIds[i]) + if (!pageTransform) continue + if (foundFirst) { + if (pageTransform.rotation() !== rotation) { + // There are at least 2 different rotations, so the common rotation is zero + return 0 + } + } else { + // First rotation found + foundFirst = true + rotation = pageTransform.rotation() + } } - const allRotations = selectedShapeIds.map((id) => this.getShapePageTransform(id)!.rotation()) - // if the rotations are all compatible with each other, return the rotation of any one of them - if (allRotations.every((rotation) => Math.abs(rotation - allRotations[0]) < Math.PI / 180)) { - return this.getShapePageTransform(selectedShapeIds[0])!.rotation() - } - return 0 + return rotation } /** @@ -1693,9 +1698,9 @@ export class Editor extends EventEmitter { .flatMap((id) => { const pageTransform = this.getShapePageTransform(id) if (!pageTransform) return [] - return pageTransform.applyToPoints(this.getShapeGeometry(id).vertices) + return pageTransform.applyToPoints(this.getShapeGeometry(id).bounds.corners) }) - .map((p) => Vec.Rot(p, -selectionRotation)) + .map((p) => p.rot(-selectionRotation)) ) // now position box so that it's top-left corner is in the right place boxFromRotatedVertices.point = boxFromRotatedVertices.point.rot(selectionRotation)