[whatwg] Canvas isPointInPath() coordinate space

David Flanagan david at davidflanagan.com
Thu Jul 15 10:55:38 PDT 2010


Oliver Hunt wrote:
> On Jul 14, 2010, at 10:58 PM, David Flanagan wrote:

>> So here's my question: if I want to do hit-testing as described above, do I need to take the mouse coordinates from the event, subtract the offset of the canvas, and then divide by 2?  As the spec is written, I think I do have to do that division manually.  Is that what is intended?  What if the user has zoomed in?  Is it even possible to use isPointInPath() correctly in that case?
> 
> isPointInPath works in the context of the canvas -- if you have coordinates from an event you will need to transform those from screen coordinates to the base coordinate space used by the canvas.  In other words:
> 1. adjust for the offset of the canvas element relative to the event coordinate space
> 2. adjust for the scale factor between the canvas element and the canvas element's context
> 

Thanks for the clarification, Oliver.  Now that getBoundingClientRect() 
is widely implemented and is being standardized, those calculations are 
no longer difficult!

	David



More information about the whatwg mailing list