Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas events for path shapes #153

Open
1 of 2 tasks
techniq opened this issue May 2, 2024 · 0 comments
Open
1 of 2 tasks

Canvas events for path shapes #153

techniq opened this issue May 2, 2024 · 0 comments

Comments

@techniq
Copy link
Owner

techniq commented May 2, 2024

While a voronoi or quadtree can be used as a technique for single point events (i.e. tooltips), hit detection for paths/rects/etc (ex. GeoPath or Pie arcs) are more challenging.

Using the r-tree algorithm such as is available with Flatbush provides fast boundary box lookups, although you can get multiple results for overlapping boxes and will need to do a deeper compare (using something like geoContains())

Another technique is to draw a second (hidden) canvas with distinct colors and register data for each color in a lookup, and then use context.getImageData() to get the color for the pointer coordinates, and return the data. This has some challenges with canvas anti-aliasing on the edges, but is simpler (especially without needing a deeper comparison)

@techniq techniq changed the title Canvas events Canvas events for path shapes Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant