flauwekeul / honeycomb

Create hex grids easily, in node or the browser.
https://abbekeultjes.nl/honeycomb
MIT License
630 stars 57 forks source link

Why is Grid.get so slow? #55

Closed eranimo closed 4 years ago

eranimo commented 4 years ago

Calling Grid.get in a loop seems to be extremely slow. It appears that its looping over the entire grid. Why? Seems unnecessary.

flauwekeul commented 4 years ago

When you call get() with a number (the index of a hex in the grid) it should be very fast (same as grid[index]). When you call it with anything that can be converted to a Point (e.g. [1, 2], { x: 1, y: 2 }) it does indeed loop over the grid until it finds the hex with those cartesian coordinates.

I'm working on a rewrite of the project where these kinds of operations (finding 1 or more hexes in a grid) can be fine-tuned way more easily. I hope to release an alpha version in a month or so.

eranimo commented 4 years ago

Sounds great, thanks!

flauwekeul commented 4 years ago

Closing this because it seems your question was answered satisfactory.

flauwekeul commented 3 years ago

Just to let you know: I've released an alpha version with a new API! Please check out the next branch.