ManevilleF / hexx

Hexagonal tools lib in rust
Apache License 2.0
276 stars 22 forks source link

Feat/new directions #156

Closed ManevilleF closed 4 months ago

ManevilleF commented 4 months ago

Closes #115

Problem

The direction enums, Direction and DiagonalDirection were confusing users, because their variants had orientation based names.

For example Direction::Top made sense in flat orientation, but in pointy orientation with the 30 degrees shift, it lost its meaning. Multiple users thought directions were related to HexOrientation when they are not, due to this unfortunate naming.

Solution

First the Direction enum was renamed to EdgeDirection , and DiagonalDirection to VertexDirection. This naming is more consistent on what those directions actually represent.

           ___
          /   \
      +--+  1  +--+
     /  2 \___/ 0  \
     \    /   \    /
      +--+     +--+
     /  3 \___/ 5  \
     \    /   \    /
      +--+  4  +--+  
          \___/
          \___/
     \ 2  /   \ 1  /
      +--+     +--+
   __/    \___/    \__
     \    /   \    /
   3  +--+     +--+  0
   __/    \___/    \__
     \    /   \    /
      +--+     +--+ 
     / 4  \___/  5 \

Then, instead of an enum, which forced me to name the directions, they are now structs storing a u8 index between 0 and 5, 6 possibilities. The enum way was also repr(u8) mimicking this index way

To keep the ability to use directions directly with orientation based names I added a bunch of const values for both flat and pointy orientation

Notes

If this PR is a huge breaking change, there should not be any lost feature, I kept all methods available before to both direction enums, and all the tests were adapted

The idea for the renaming comes from #154 , where I realized that directions are edge related, and diagonals vertex related

alice-i-cecile commented 4 months ago

Oh I like that rename: I think it's much clearer!