Skip to content

Commit

Permalink
Merge pull request #13 from DigitalSmile/development
Browse files Browse the repository at this point in the history
Interface to work with operations
Tests and demo
Documentation
  • Loading branch information
DigitalSmile authored Oct 24, 2022
2 parents 5814260 + d3c0574 commit e7ec9b6
Show file tree
Hide file tree
Showing 52 changed files with 2,288 additions and 641 deletions.
60 changes: 31 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

Small and pure Java library to deal with hexagons math and operations with zero dependencies. The library provides an abstract level of hexagon manipulation and is render engine agnostic, so it can be used with any type of visual libraries (AWT, JavaFX, libGDX, etc.)

The code and the library itself are highly inspired by blog posts by @redblobgames (https://www.redblobgames.com/grids/hexagons/)
Documentation can be found in [wiki](https://github.com/DigitalSmile/hexagon/wiki).

The code and the library itself are highly inspired by blog posts by @redblobgames (https://www.redblobgames.com/grids/hexagons/).

## Features
- Pure Java 17+ library
Expand All @@ -20,46 +22,46 @@ The code and the library itself are highly inspired by blog posts by @redblobgam
- Supports grid with rectangle and hexagonal shape

## Usage
Add dependency to your project.
Add dependency to your project. Latest version can be found at the jitpack badge.

Gradle:

```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.DigitalSmile:hexagon:0.1.2'
}
dependencies {
implementation 'com.github.DigitalSmile:hexagon:{version}'
}
```
Maven:
```
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
...
<dependency>
<groupId>com.github.DigitalSmile</groupId>
<artifactId>hexagon</artifactId>
<version>0.1.2</version>
</dependency>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
...
<dependency>
<groupId>com.github.DigitalSmile</groupId>
<artifactId>hexagon</artifactId>
<version>{version}</version>
</dependency>
```
Use a `HexagonGridBuilder` to create a grid or use `Hexagon` and `Operations` classes directly:
```
var hexagonGrid = new HexagonGrid.HexagonGridBuilder()
.hexagonShape(new HexagonalBounds(5))
.orientation(Orientation.FLAT)
.hexagonWidth(150)
.build();
hexagonGrid.generateHexagons();
var hexagonList = hexagonGrid.getHexagons();
var hexagonGrid = new HexagonGrid.HexagonGridBuilder<>()
.shape(new HexagonalShape(5), Orientation.FLAT) // hexagonal shape with radius of 5 hexagons and flat orientation
.hexagonWidth(150) // width of hexagon in physical units
.build();
hexagonGrid.generateHexagons();
var hexagonList = hexagonGrid.getHexagons(); // returns all generated hexagons
var lineHexagonList = HexagonOperations.hexagonLinePath(new Hexagon(0,0,0), new Hexagon(0, -3, 3)); // returns hexagons, that are in line between two hexagons
```

## Next milestone - [Mercury](https://github.com/DigitalSmile/hexagon/milestone/1) ![GitHub milestone](https://img.shields.io/github/milestones/progress-percent/DigitalSmile/hexagon/1)
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'jacoco'
id "org.sonarqube" version "3.4.0.2513"
id "me.champeau.jmh" version "0.6.8"
id 'maven-publish'
}

Expand All @@ -18,7 +19,7 @@ repositories {
dependencies {

testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
testImplementation 'org.openjdk.jol:jol-core:0.16'
}

publishing {
Expand All @@ -38,7 +39,7 @@ test {
useJUnitPlatform {
includeTags("HexagonTest", "LayoutTest", "FractionalHexagonTest",
"HexagonDirectionTest", "OrientationTest", "DoubledCoordinatesTest", "OffsetCoordinatesTest",
"ShapeTest", "StorageTest", "HexagonGridTest")
"ShapeTest", "StorageTest", "HexagonGridTest", "HexagonOperationsTest", "RangeOperationsTest")
}
finalizedBy jacocoTestReport
}
Expand All @@ -59,3 +60,8 @@ sonarqube {
}
}

jmh {
warmupIterations = 3
iterations = 3
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.digitalsmile.hexgrid.operations;

import org.digitalsmile.hexgrid.hexagon.Hexagon;
import org.digitalsmile.hexgrid.operations.RangeOperations;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;

public class RangeOperationsTest {

@State(Scope.Thread)
public static class Input {
public Hexagon hexagon = new Hexagon(0,0,0);
public int range = 100;
}

//@Benchmark
public void testGetRangeNoParallelStream(Input i, Blackhole blackhole) {
var list = RangeOperations.getRange(i.hexagon, i.range);
blackhole.consume(list);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.digitalsmile.hexgrid.storage;

import org.digitalsmile.hexgrid.HexagonGrid;
import org.digitalsmile.hexgrid.coordinates.OffsetCoordinates;
import org.digitalsmile.hexgrid.hexagon.Hexagon;
import org.digitalsmile.hexgrid.layout.Orientation;
import org.digitalsmile.hexgrid.shapes.rectangle.RectangleShape;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@State(Scope.Thread)
public class HexagonStorageTest {
private HexagonGrid<?> grid;
private Hexagon hexagonToFind;

@Setup
public void setup() {
grid = new HexagonGrid.HexagonGridBuilder<>()
.hexagonWidth(150)
.shape(new RectangleShape(1000, 1000), Orientation.FLAT)
.hexagonDataObjectHook(Hexagon::toString)
.build();
grid.generateHexagons();
var randomX = new Random().nextInt(1000);
var randomY = new Random().nextInt(1000);
hexagonToFind = OffsetCoordinates.toCube(Orientation.FLAT, new OffsetCoordinates(randomX, randomY));
}


@Benchmark
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void testStorageGetMetaObjectByIndex(Blackhole blackhole) {
var object = grid.getStorage().getHexagonDataObject(hexagonToFind);
blackhole.consume(object);
}

}
9 changes: 9 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
module hexgrids {
exports org.digitalsmile.hexgrid;
exports org.digitalsmile.hexgrid.hexagon;
exports org.digitalsmile.hexgrid.shapes.hexagonal;
exports org.digitalsmile.hexgrid.shapes.rectangle;
exports org.digitalsmile.hexgrid.storage;
exports org.digitalsmile.hexgrid.operations;
exports org.digitalsmile.hexgrid.coordinates;
exports org.digitalsmile.hexgrid.layout;
exports org.digitalsmile.hexgrid.shapes;
exports org.digitalsmile.hexgrid.operations.pole;
}
Loading

0 comments on commit e7ec9b6

Please sign in to comment.