flauwekeul / honeycomb

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

Spiral Traverser not working as expected #117

Closed exp111 closed 1 month ago

exp111 commented 1 month ago

Describe the bug The spiral traverser does not work as expected. Lets take the example from the docs:

const Hex = defineHex({ dimensions: 30 });
const grid = new Grid(Hex, rectangle({
  width: 5,
  height: 5
}));
const spiralTraverser = spiral(
  {
    start: [0, 2],
    radius: 1
  });

for (let h of grid.traverse(spiralTraverser)) {
  console.log(`col: ${h.col}, row: ${h.row}`);
}

I'd expect it to print out the hexes in this order:

However it prints out:

col: 1, row: 2
col: 1, row: 1
col: 2, row: 2
col: 1, row: 3
col: 0, row: 3
col: 0, row: 2 
col: 0, row: 1

Meaning it made a spiral with its center at 1,2. If I start it at 1,2 it does a spiral at 2,2. The offset isnt always one as on a 10x10 grid with a start at 1,7 it will do a spiral at 4,7

Environment (please complete the following information):

Screenshots 0,2 to 1,2 offset visualized: grafik

1,7 to 4,7 visualized: grafik

exp111 commented 1 month ago

Okay yea I got it. The HexCoordiantes [0,2] aren't {col: 0, row: 2} but {q: 0, r: 2}.

flauwekeul commented 1 month ago

Sorry for answering so late, but good that you figured it out yourself 👍

Pretty textures btw.