Skip to content
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

canvas.Clip translation doesn't follow coordSystem #314

Open
davidjb opened this issue Oct 4, 2024 · 3 comments
Open

canvas.Clip translation doesn't follow coordSystem #314

davidjb opened this issue Oct 4, 2024 · 3 comments

Comments

@davidjb
Copy link

davidjb commented Oct 4, 2024

In the current implementation of Clip:

canvas/canvas.go

Lines 771 to 775 in f7585e3

func (c *Canvas) Clip(rect Rect) {
c.Transform(Identity.Translate(-rect.X, -rect.Y))
c.W = rect.W
c.H = rect.H
}

the canvas is transformed in negative x and y. However, since my canvas is set to use canvas.CartesianIV, with the origin at the top-left, I'd expected that when I requested a translation of 5, 5, then the translation would move 5 units right and 5 units down, towards the bottom-right. Instead, the canvas moves left and up instead, moving -5, -5. To achieve my intended result, I currently negate my translations before running Clip.

Is this expected behaviour?

@tdewolff
Copy link
Owner

tdewolff commented Oct 4, 2024

Hi David, it kind of is expected, but not ideal. All internal operations are in the regular coordinate system (ie. Cartesian I) while we allow a cosmetic change of coordinate system towards Cartesian IV, the one used mostly for imaging. Since the coordinate system change is set in the Context, the underlying Canvas is unaware. Not sure how we could improve this situation.

@davidjb
Copy link
Author

davidjb commented Oct 4, 2024

Thanks for the info, that makes sense. As a solution, would adding a wrapper method like ResizeCanvas to the Context be feasible? It could call Clip under the hood, deciding which direction to translate based on the Cartesian system set. This is pretty much what I’ve implemented in my own struct that has a canvas field on it.

@tdewolff
Copy link
Owner

tdewolff commented Oct 4, 2024

That's a great idea, but it would need to work for all renderers. Currently only the Canvas renderer has a Clip method because we can still transform the drawn objects. For other renderers it has already been rendered and we have no way of changing the view I'm afraid...

Repository owner deleted a comment Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants