jonobr1 / two.js

A renderer agnostic two-dimensional drawing api for the web.
https://two.js.org
MIT License
8.29k stars 454 forks source link

In ZUI, surfaceToClient calculation does not take translateSurface into account. #659

Open alper-batioglu opened 2 years ago

alper-batioglu commented 2 years ago

Describe the bug surfaceToClient of ZUI does not get affected by prior translateSurface (aka. panning)

To Reproduce Steps to reproduce the behavior:

  1. Go to https://codepen.io/jonobr1/pen/PobMKwb
  2. Write console.log(JSON.stringify(zui.surfaceToClient({x:10, y:10}))) on line 62 (below zui.translateSurface(dx, dy);)
  3. Pan the surface with mouse
  4. Observe surfaceToClient calculation of x:10, y:10 is not affected by translateSurface on the new x, y coordinates on console
  5. Also observe how zoom-in and zoom-out by mouse wheel affects surfaceToClient calculation. (zoom-in and then pan the surface)

Expected behavior surfaceToClient calculation should be affected by translateSurface (aka. panning)

Environment (please select one):

Desktop (please complete the following information):

jonobr1 commented 2 years ago

Thanks for posting. This fixes that issue: https://github.com/jonobr1/two.js/pull/661

If you're using an NPM version of Two.js. An interim fix you can make on your end (until the latest version is published to NPM) is to also pass a z component where z = 1.

E.g: console.log(JSON.stringify(zui.surfaceToClient({ x: 10, y: 10, z: 1 })));

alper-batioglu commented 2 years ago

omg, how did I not try that. Thanks. :)