`canvas.Clip` translation doesn't follow `coordSystem`
In the current implementation of Clip:
https://github.com/tdewolff/canvas/blob/f7585e35bd6a4634edbe35735c215b1159272d7e/canvas.go#L771-L775
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?
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.
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.
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...