jonobr1 / two.js

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

clientToSurface & surfaceToClient signatures #658

Closed alper-batioglu closed 2 years ago

alper-batioglu commented 2 years ago

Added clientToSurface and surfaceToClient signatures.

surfaceToClient has x, y and z optional, but if none of them is provided, it strangely returns a Matrix, which I did not understand, but did not try to understand as well 😁. Line with an empty object parameter on top of real signature is for intellisense of the ReturnType.

same thing is also true for clientToSurface with missing arguments.

jonobr1 commented 2 years ago

The return type is a symptom of underlying matrix math. To get these calculations I use matrices. matrix.multiply is overloaded with many different types of multiplying. If there are 2 or 3 arguments it returns a vector, but if there are 1 or >3 than it returns a matrix.

jonobr1 commented 2 years ago

This looks god, though in a future release I will be removing Two.ZUI (any extras) from the default types declarations. I would love your feedback on good ways to add types declarations to more "external" files in the repo. If you have any thoughts, please share them here: https://github.com/jonobr1/two.js/issues/660