flauwekeul / honeycomb

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

center method is not working #11

Closed shallwefootball closed 6 years ago

shallwefootball commented 6 years ago

I want to know the center point of each hexagon, but only one hexagon center point is output.

Let's look at the code below.

const Hex = Honeycomb.extendHex({size: 11})
const Grid = Honeycomb.defineGrid(Hex)
Grid.hexagon({radius: 15}).forEach(hex => {
  console.log(hex.toPoint()); // each hexagon points..
  console.log(hex.center()); // just one hexagon points..
});

Am I misunderstanding?

shallwefootball commented 6 years ago

I think it is because of below.

https://github.com/flauwekeul/honeycomb/blob/4f57685051742d52875af967edd4c402ce19815c/src/hex/prototype.js#L251-L252

Then, Is there any way to know the center point of each hexagon?

flauwekeul commented 6 years ago

I can imagine you expect a hexagon's center() method returns the center position of the hexagon you called it on relative to Hex(0, 0). But unfortunately Hex#center() returns the same point for all hexagons in the grid. I have an item on my backlog (see item 4) to fix this, but I haven't come around to it...

You can get around it by adding the hex's point, like so:

const Hex = Honeycomb.extendHex({size: 11})
const Grid = Honeycomb.defineGrid(Hex)

Grid.hexagon({radius: 15}).forEach(hex => {
  console.log(hex.center().add(hex.toPoint()));
});