#gamedev #hexagon #shape #module #partial-eq #utility

hexagon_tiles

A utility library that allows working with the hexagon shape and related math

3 unstable releases

0.2.1 Mar 9, 2024
0.2.0 Mar 25, 2023
0.1.0 Apr 12, 2021

#376 in Math

Download history 20/week @ 2024-02-26 139/week @ 2024-03-04 29/week @ 2024-03-11 62/week @ 2024-04-01

63 downloads per month

Custom license

26KB
677 lines

Hexagon Utility Library

This is a utility library written in Rust that eases development modules that require working with the hexagon shape and related math.

This library is heavily based on Red Blob Games auto generated Rust implementation. Other implementations I looked at are messy and complicated. The auto generated code actually was quite simple, but as such it was not implemented with Rust idiom in mind.

This implementation is different in few ways:

  • Both Hex and FractionalHex implement PartialEq.
    This means you can do assert_eq!(hex1, hex2) or hex1 == hex2.
  • Point also have PartialEq implementation for f64 using float_eq.
  • I implemented some of the function as traits of Hex and FractionalHex and this means you can do hex1.add(hex2) or hex1.round().
  • Other functionality is implemented as static functions in their own objects HexDirection, HexOffset, HexDoubled.
  • Tests cover everything, and implemented in Rust way.
  • The auto-generated code split into several file modules.

This packages is distributed under the zlib License.

Feel free to improve and contribute using github. I would really like to see a tile-map manager at some point.

This library was developed in mind to be used as part of a BEVY game engine plugin. However BEVY implementation is not in the scope of this repository.

Dependencies

~1.5MB
~38K SLoC