grid_space 1.0.0 copy "grid_space: ^1.0.0" to clipboard
grid_space: ^1.0.0 copied to clipboard

Common classes to convert between square grids and hexagonal grids.

Common classes to create and convert between square grids and hexagonal grids.

Conversion is achieved with a bidirectional function which takes a point and transforms it using either gridToWorldSpace( point ) or worldToGridSpace( point ).

final grid = Grid.square(
    4,                // 4 tiles in each "row" in world space
    zero: Point(0, 0) // Grid origin in world space
    size: Point(4, 4) // Grid size in world space
);

// Alternatives with hexagonal grid
Grid.hexagonal(4, horizontal: true);
Grid.hexagonal(4, horizontal: false);

// Examples: Grid -> World space
grid.gridToWorldSpace( Point(0.5, 0.5) ); // Blue dot in figure
grid.gridToWorldSpace( Point(1,   2  ) ); // Green
grid.gridToWorldSpace( Point(2.5, 1.5) ); // Pink
grid.gridToWorldSpace( Point(1.5, 3.5) ); // Orange

The following figure exemplifies the correlation between grid space and world space for each available grid type. Figure showing how grid space and world space correlate in square grids and horizontal or vertical hex grids Transformations in a square grid, horizontal hex grid and vertical hex grid.

0
likes
130
pub points
0%
popularity

Publisher

verified publishertheoretically.online

Common classes to convert between square grids and hexagonal grids.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on grid_space