[whatwg] isPointInPath v. set of pixels in canvas hit regions

Ian Hickson ian at hixie.ch
Thu Jul 5 22:06:47 PDT 2012


On Thu, 5 Jul 2012, Simon Fraser wrote:
> On Jul 5, 2012, at 2:25 PM, Ian Hickson <ian at hixie.ch> wrote:
> > On Thu, 5 Jul 2012, Edward O'Connor wrote:
> >> 
> >> As things currently stand in the spec, implementations basically need 
> >> to keep N+1 bitmaps per canvas, where N is the number of hit regions. 
> >> I doubt any implementors would be enthusiastic to implement hit 
> >> regions like this. From a WebKit perspective, we'd much prefer 
> >> keeping a Path for each hit region, and then simply using 
> >> isPointInPath for hit testing. This also implies that the current 
> >> piggybacking of "Clear regions that cover the pixels" in clearRect() 
> >> could go away. Yay! :)
> > 
> > You only need one bitmap to implement the hit testing.
> > 
> > (Or you can do it using paths, sure. The effect is the same, but it's 
> > probably quicker to use a bitmap.)
> 
> I don't think the spec should be written with a particular 
> implementation in mind, nor should it dictate one.

I agree it shouldn't (and doesn't) dictate one. But it's crazy to not 
consider implementations at all when writing a spec. That way lies madness 
like requiring O(N^2) algorithms and solving the halting problem and all 
kinds of other disasters (all of which I've seen in real proposals).
 

> I also strongly object to having to update this hit testing bitmap 
> and/or path set on drawing operations like clearRect(). That will 
> potentially hurt performance.

How so? If it's a path set, you just add a rectangle (you can keep the 
list of shapes down by occasionally running pruning algorithms to remove 
shapes entirely contained by later ones). If it's a bitmap, it's even 
easier; you just wipe the rectangle in the bitmap.


> I think its up to the author to manage their set of paths appropriately, 
> independently from the drawing operations.

Having the drawing mechanism work in a tightly integrated fashion with the 
region code IMHO helps authors avoid bugs. You don't have to track which 
regions you've defined, you just make sure to draw the regions while 
you're drawing the paths and it all Just Works. Not having to track the 
regions is the entire point of how this API was designed -- it's also the 
main differentiating factor between this API's design and the design of 
hit testing in retained-mode APIs such as SVG.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list