Visualize Your Ideas With Code
fix: restrict size of cache canvas (#544)
Jacob49ec55490718
diff --git a/packages/2d/src/components/Node.ts b/packages/2d/src/components/Node.tsindex 6a6bb8db..4fdb6f90 100644--- a/packages/2d/src/components/Node.ts+++ b/packages/2d/src/components/Node.ts@@ -1080,9 +1080,14 @@ export class Node implements Promisable<Node> {*/@computed()protected worldSpaceCacheBBox(): BBox {- return BBox.fromPoints(+ const viewBBox = BBox.fromSizeCentered(this.view().size());+ const canvasBBox = BBox.fromPoints(+ ...viewBBox.transformCorners(this.view().localToWorld()),+ );+ const cacheBBox = BBox.fromPoints(...this.cacheBBox().transformCorners(this.localToWorld()),- ).pixelPerfect;+ );+ return canvasBBox.intersection(cacheBBox).pixelPerfect;}/**@@ -1154,7 +1159,15 @@ export class Node implements Promisable<Node> {this.setupDrawFromCache(context);const cacheContext = this.cachedCanvas();const compositeOverride = this.compositeOverride();- context.resetTransform();+ const matrix = this.worldToLocal();+ context.transform(+ matrix.a,+ matrix.b,+ matrix.c,+ matrix.d,+ matrix.e,+ matrix.f,+ );context.drawImage(cacheContext.canvas, offset.x, offset.y);if (compositeOverride > 0) {context.save();diff --git a/packages/core/src/types/BBox.ts b/packages/core/src/types/BBox.tsindex 1c38b68e..8c7cdd26 100644--- a/packages/core/src/types/BBox.ts+++ b/packages/core/src/types/BBox.ts@@ -320,6 +320,19 @@ export class BBox implements Type {);}+ public intersection(other: BBox): BBox {+ const bbox = new BBox();++ if (this.intersects(other)) {+ bbox.left = Math.max(this.left, other.left);+ bbox.top = Math.max(this.top, other.top);+ bbox.right = Math.min(this.right, other.right);+ bbox.bottom = Math.min(this.bottom, other.bottom);+ }++ return bbox;+ }+public toSymbol(): symbol {return BBox.symbol;}