-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix transforms in clip() by using shape system for primitives using manual method #8236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev-2.0
Are you sure you want to change the base?
Conversation
|
@davepagurek I've implemented the manual fix for the ellipse() method and it's working correctly now! |
perminder-17
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function setup() {
createCanvas(400, 200);
pixelDensity(1);
noLoop();
}
function draw() {
background(240);
translate(200, 0);
clip(() => {
scale(-1,1);
ellipse(50, 100, 100, 100);
});
fill(0, 0, 255, 120);
ellipse(100, 100, 300, 300);
}what you get when you use this sketch? I think transformation is not correctly applied?
perminder-17
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, your current solution applies to ellipse only? Do you think we need to add this solution in other shapes as well? arc/quad/line etc?
btw, thanks for working on this one.
|
@perminder-17 yes it is only applicable for ellipse now I need to change for all too |
|
@perminder-17 I also have another idea class based approach also just want to discuss which one is better. I think This approach is temporary we need to find a perfect solution for that |
it shows this @perminder-17
|
I saw @davepagurek's comment about the shape-system approach. It would be great long-term and would also unlock future tasks, but it feels like a fairly large refactor right now with higher regression risk. Since we already have the alternative approach working, how about we stick with that for now and plan to migrate the primitives into the shape drawing system later? |
I think this is not the expected behavior. I think you're storing inverse of initial clip transform into inside Since, in the 1.x versions, it works something like: https://editor.p5js.org/aman12345/sketches/Csnrbz9BX , so would be great to test that too. CC: @davepagurek for the confirmation on the approach as well as the bug if it's exist? |
|
@perminder-17 i think When we using scale(-1,1) inside clip(), the negative scale breaks the matrix calculations and makes the clipping region invisible. Basic clipping are working fine, but it give issue with complex transformations. |
@perminder-17 Now it work as expected it can handle -ve values also and i add condition and use absolute values to find the original position |



Resolves #7903
Changes:
Modified ellipse() method in p5.Renderer2D to apply transforms during clipping
Used existing this.initialClipTransform (inverse of initial transform) stored in beginClip()
Applied correct matrix multiplication order: initialClipTransform.multiply(currentTransform)
Screenshots of the change:
PR Checklist
npm run lintpasses