[fix] masked bounds calculation (#2197)

This PR fixes a bug where frames with children that have identical
dimensions would not be able to export as images.

When calculating masked page bounds, identical shapes would produce a
zero width/height masked page bounds.

### Change Type

- [x] `patch` — Bug fix

### Test Plan

1. Create a frame.
2. Create an image that is a child of the frame and the exact dimensions
of the frame (possibly using the console)
3. Export the image

### Release Notes

- Fix bug with getmaskedpagebounds calculation for identical parent /
child sizes
pull/1734/head^2
Steve Ruiz 2023-11-11 13:50:48 +00:00 zatwierdzone przez GitHub
rodzic 957fced41d
commit 3c768867f2
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 10 dodań i 4 usunięć

Wyświetl plik

@ -3938,13 +3938,13 @@ export class Editor extends EventEmitter<TLEventMap> {
return this.store.createComputedCache<string, TLShape>('clipPathCache', (shape) => {
const pageMask = this._shapeMaskCache.get(shape.id)
if (!pageMask) return undefined
const pageTransform = this._shapePageTransformCache.get(shape.id)
if (!pageTransform) return undefined
if (pageMask.length === 0) {
return `polygon(0px 0px, 0px 0px, 0px 0px)`
}
const pageTransform = this._shapePageTransformCache.get(shape.id)
if (!pageTransform) return undefined
const localMask = Matrix2d.applyToPoints(Matrix2d.Inverse(pageTransform), pageMask)
return `polygon(${localMask.map((p) => `${p.x}px ${p.y}px`).join(',')})`
@ -4040,7 +4040,13 @@ export class Editor extends EventEmitter<TLEventMap> {
if (!pageBounds) return
const pageMask = this._shapeMaskCache.get(shape)
if (pageMask) {
const intersection = intersectPolygonPolygon(pageMask, pageBounds.corners)
if (pageMask.length === 0) return undefined
const { corners } = pageBounds
if (corners.every((p, i) => Vec2d.Equals(p, pageMask[i]))) return pageBounds.clone()
// todo: find out why intersect polygon polygon for identical polygons produces zero w/h intersections
const intersection = intersectPolygonPolygon(pageMask, corners)
if (!intersection) return
return Box2d.FromPoints(intersection)
}