fix: aggregate large ink groups safely
This commit is contained in:
@@ -623,7 +623,7 @@ function parseInk(
|
||||
id: exGuidKey(object.id),
|
||||
strokes: [],
|
||||
children,
|
||||
boundingBox: unionBoundingBoxes(
|
||||
boundingBox: unionInkBoundingBoxes(
|
||||
children.map((child) => child.boundingBox)
|
||||
),
|
||||
layout: parseLayout(object),
|
||||
@@ -915,18 +915,24 @@ function boundingBoxFromStrokes(
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function unionBoundingBoxes(
|
||||
/** @internal Exported so the bounded aggregation path can be stress-tested. */
|
||||
export function unionInkBoundingBoxes(
|
||||
boxes: readonly (OneNoteInkBoundingBox | undefined)[]
|
||||
): OneNoteInkBoundingBox | undefined {
|
||||
const present = boxes.filter(
|
||||
(box): box is OneNoteInkBoundingBox => box !== undefined
|
||||
);
|
||||
if (present.length === 0) return undefined;
|
||||
const x = Math.min(...present.map((box) => box.x));
|
||||
const y = Math.min(...present.map((box) => box.y));
|
||||
const x2 = Math.max(...present.map((box) => box.x + box.width));
|
||||
const y2 = Math.max(...present.map((box) => box.y + box.height));
|
||||
return { x, y, width: x2 - x, height: y2 - y };
|
||||
let x = Infinity;
|
||||
let y = Infinity;
|
||||
let x2 = -Infinity;
|
||||
let y2 = -Infinity;
|
||||
for (const box of boxes) {
|
||||
if (!box) continue;
|
||||
x = Math.min(x, box.x);
|
||||
y = Math.min(y, box.y);
|
||||
x2 = Math.max(x2, box.x + box.width);
|
||||
y2 = Math.max(y2, box.y + box.height);
|
||||
}
|
||||
return Number.isFinite(x)
|
||||
? { x, y, width: x2 - x, height: y2 - y }
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function parseLayout(object: StoreObject): OneNoteLayout {
|
||||
|
||||
Reference in New Issue
Block a user