jonobr1 / two.js

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

How to check if an object is currently being hovered by the mouse whilst taking rotation into account? #697

Closed Jamzy01 closed 1 year ago

Jamzy01 commented 1 year ago

How to check if an object is currently being hovered by the mouse whilst taking rotation into account?

I have tried the Two.Path.getBoundingClientRect api, which works flawlessly for rectangular unrotated objects, although for rotated objects as this only returns an unrotated rect it does not work perfectly. Is there an api that will be able to check if any point is within a Two.path (including convex and concave shapes) that also takes rotation into account, or how easy would this be to implement myself?

Environment (please select one):


If applicable:

Desktop (please complete the following information):

jonobr1 commented 1 year ago

Thanks for reporting! This branch should fix those issues: https://github.com/jonobr1/two.js/tree/issue-697-bounding-box

I still need to do some additional performance testing before merging into the main branch however.

jonobr1 commented 1 year ago

This example uses the aforementioned branch: https://codepen.io/jonobr1/pen/YzJGNOq

Jamzy01 commented 1 year ago

Thanks, this should work perfectly.