Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF committed Jan 17, 2024
1 parent 6498478 commit 916ac24
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
79 changes: 44 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,67 @@
This lib allows you to:

- Manipulate hexagon coordinates
- Generate hexagonal maps with custom layouts and orientation
- Generate hexagon meshes (planes or columns)
- Manipulate hexagon coordinates
- Generate hexagonal maps with custom layouts and orientation
- Generate hexagon meshes (planes or columns)

I made the choice to use *Axial Coordinates* for performance and utility
reasons, but the [`Hex`] type has conversion utilities with *cubic*,
*doubled* and *offset* coordinates.

> See the [hexagonal coordinate systems](https://www.redblobgames.com/grids/hexagons/#coordinates)
## Installation
## Installation

Run `cargo add hexx` in your project or add the following line to your
`Cargo.toml`:

- `hexx = "0.12"`
- `hexx = "0.12"`

### Cargo features
### Cargo features

`hexx` supports serialization and deserialization of most types using [serde](https://github.com/serde-rs/serde),
through the `serde` feature gate. To enable it add the following line to
your `Cargo.toml`:

- `hexx = { version = "0.12", features = ["serde"] }`
- `hexx = { version = "0.12", features = ["serde"] }`

By default `Hex` uses rust classic memory layout, if you want to use `hexx`
through the FFI or have `Hex` be stored without any memory padding, the
`packed` feature will make `Hex` `repr(C)`. To enable this behaviour add the
following line to your `Cargo.toml`:

- `hexx = { version = "0.12", features = ["packed"] }`
- `hexx = { version = "0.12", features = ["packed"] }`

`hexx` supports [Bevy Reflection](https://docs.rs/bevy_reflect/latest/bevy_reflect) through the
`bevy_reflect` feature. To enable it add the following line to your
`Cargo.toml`:

- `hexx = { version = "0.12", features = ["bevy_reflect"] }`
- `hexx = { version = "0.12", features = ["bevy_reflect"] }`

## Features
## Features

`hexx` provides the [`Hex`] coordinates with:

- Distances
- Neighbors and directions
- Lines
- Ranges
- Rings
- Edges
- Wedges
- Spirals
- Rotation
- Symmetry
- Vector operations
- Conversions to other coordinate systems:
- Cubic coordinates
- Offset coordinates
- Doubled coordinates
- Hexmod coordinates
- Multiple hex resolution

## Basic usage
- Distances
- Neighbors and directions
- Lines
- Ranges
- Rings
- Edges
- Wedges
- Spirals
- Rotation
- Symmetry
- Vector operations
- Conversions to other coordinate systems:
- Cubic coordinates
- Offset coordinates
- Doubled coordinates
- Hexmod coordinates
- Multiple hex resolution

## Basic usage

```rust
use hexx::*;
Expand All @@ -104,7 +104,7 @@
let avg = wedge.average();
```

## Layout usage
## Layout usage

[`HexLayout`] is the bridge between your world/screen/pixel coordinate
system and the hexagonal coordinates system.
Expand All @@ -126,7 +126,7 @@
let world_pos = layout.hex_to_world_pos(point);
```

## Wrapping
## Wrapping

[`HexBounds`] defines a bounding hexagon around a center coordinate.
It can be used for boundary and interesection checks but also for wrapping
Expand All @@ -146,13 +146,14 @@
assert!(bounds.is_in_bounds(wrapped_coord));
```

## Resolutions and chunks
## Resolutions and chunks

[`Hex`] support multi-resolution coordinates.
In practice this means that you may convert a coordinate to a different
resolution:
- To a lower resolution, meaning retrieving a *parent* coordinate
- to a higher resolution, meaning retrieving the center *child* coordinate

- To a lower resolution, meaning retrieving a *parent* coordinate
- to a higher resolution, meaning retrieving the center *child* coordinate

Resolutions are abstract, the only useful information is the resolution
**radius**.
Expand Down Expand Up @@ -197,7 +198,7 @@
An other usage could be to draw an infinite hex grid, with different
resolutions displayed, dynamically changing according to user zoom level.

## Usage in [Bevy](https://bevyengine.org/)
## Usage in [Bevy](https://bevyengine.org/)

If you want to generate 3D hexagonal mesh and use it in
[bevy](bevyengine.org) you may do it this way:
Expand Down Expand Up @@ -314,3 +315,11 @@ This example showcases hex ranges, rings, wedges, rotation, and lines
This example showcases how to build a simple hex chunk system with each chunk
being a single mesh

### Sprite Sheet

![sprite_sheet](docs/sprite_sheet.png "Sprite Sheet example")

> `cargo run --example sprite_sheet`
This example showcases how to use hexx with 2D sprite sheet.
Binary file added docs/sprite_sheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 916ac24

Please sign in to comment.