moagrius/MapView

Polygons as hotspots

Closed this issue · 6 comments

Would it be possible to set a polygon as a hotspot instead of a rectangle?

No, the hotspot implementation is tightly coupled to the Rect class, and just uses Rect.contains for hit testing.

I've created a class Poly which should make it really easy to replace the Rect class.
It has a constructor which accepts a list of Point vertices and one that accepts a Rect object for compatibility reasons. The methods you have used (equals and contains) are already implemented.
I hope it'll be added to this project, as having polygons instead of rectangles can be very useful in many cases. Thanks for the good work!

https://gist.github.com/fcapano/5565052

I'll check it out - thanks

If I was to include it (probably as an alternative signature, rather than a full replacement so it doesn't break existing API), would attribution in comments be sufficient if it was included in the core package?

Of course.
I also just fixed a small error and updated the gist.

cool - as soon as i get some time i'll run some tests with the intention of including it in the next release

thanks

I'd hoped to have your class extend Rect, to keep the API intact and not have to add a new signature, but Rect is final. That said, I do agree that polygons are more useful than Rects, and will include that in the new major upgrade when the project changes name and repo #57. Will close for now, to be taken up then. Thanks for the contribution - I'll credit you in the new project when it's included.