PAIR-code/megaplot

Making HitTestParameters.sprites readonly

GradySimon opened this issue · 2 comments

I'm using Scene.hitTest to implement detection of clicks and mouse hovers on Sprites that I'm managing directly (as opposed to managing through a Selection). I'm keeping the Sprites in a data structure that keeps them indexed with some metadata, but that can provide a readonly Sprite[], which is its underlying store of the Sprites, without copying the potentially very large array.

From briefly reviewing the implementation of Scene.hitTest, it seems like HitTestParameters.sprites is never mutated, so changing it to take a readonly array should work.

If this sounds good to the maintainers, I can try to make this change.

Would this impose a constraint on the caller to somehow freeze the property on the object being passed in? That would be my only concern. I don't want to make it harder on the caller to call hitTest() if it requires more setup. I agree that since the parameters are never modified they may as well be readonly, so long as it doesn't unduly complicate using the API.

I don't think it will. From testing it in my local environment, it looks like a Sprite[] can be used where the required type is readonly Sprite[] with no modification on the part of the caller.