Skip to content

Commit cc98f19

Browse files
committed
Handle negative scales in clipping by using absolute values for scale components
1 parent c4b5ca5 commit cc98f19

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/core/p5.Renderer2D.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,19 @@ class Renderer2D extends Renderer {
732732

733733
const currentTransform = this.drawingContext.getTransform();
734734
const initialClip = this.initialClipTransform;
735-
const relativeTransform = initialClip.multiply(currentTransform);
736-
this.clipPath.addPath(tempPath, relativeTransform);
735+
if (currentTransform.a < 0 || currentTransform.d < 0) {
736+
const fixedTransform = new DOMMatrix([
737+
Math.abs(currentTransform.a), currentTransform.b,
738+
currentTransform.c, Math.abs(currentTransform.d),
739+
currentTransform.e, currentTransform.f
740+
]);
741+
const relativeTransform = initialClip.multiply(fixedTransform);
742+
this.clipPath.addPath(tempPath, relativeTransform);
743+
} else {
744+
// Normal case
745+
const relativeTransform = initialClip.multiply(currentTransform);
746+
this.clipPath.addPath(tempPath, relativeTransform);
747+
}
737748
} else {
738749
// Normal drawing (existing code)
739750
ctx.beginPath();

0 commit comments

Comments
 (0)