hexagonal_grid 1.0.5

hexagonal_grid #

A hexagonal grid library for Dart 2 that uses axial coordinates and contains algorithms to build hex layouts. Inspired and implemented from https://www.redblobgames.com/grids/hexagons/implementation.html

[1.0.5] - 03/01/2019

  • Bug fix for toSpiralHexLayout with a null or empty list

[1.0.4] - 01/16/2019

  • General clean up and make package available for Dart projects, not just Flutter

[1.0.0] - 01/16/2019

  • Packagized this hex grid code that I have been using in my own projects so other projects and packages can use it. Contains implementations for Hex via axial coordinates as well as layouts and an algorithm to create a spiral out layout given a list.

example/example.dart

import 'dart:math';

import 'package:hexagonal_grid/hexagonal_grid.dart';

class Example {
  void createOriginHexWithLayout() {
    //Origin hex where q = 0, and r = 0 (axial coordinates)
    final Hex originHex = Hex(0, 0);

    //Arbitrary sizes and layout origins to help construct the HexLayout
    final Point size = Point(2, 2);
    final Point hexLayoutOrigin = Point(5, 5);

    //Create a flat HexLayout
    final HexLayout hexLayout = HexLayout.orientFlat(size, hexLayoutOrigin);

    //Transpose the axial coordinate Hex onto the HexLayout to get a pixel
    // representation of that Hex
    final Point hexToPixel = originHex.toPixel(hexLayout);
  }

  void createNeighbors() {
    //Origin hex where q = 0, and r = 0 (axial coordinates)
    final Hex originHex = Hex(0, 0);

    //Iterate through each possible direction of a hex (six of them) and get the
    // neighbor for each. Then print them out.
    for (int d = 0; d < Hex.directions.length; d++) {
      Hex neighborHex = originHex.neighbor(d);
      print(neighborHex);
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  hexagonal_grid: ^1.0.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:hexagonal_grid/hexagonal_grid.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
39
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Aug 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:hexagonal_grid/hexagonal_grid.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
Dev dependencies
test ^1.5.1