Hexworks / mixite

A GUI agnostic hexagonal grid library. Supports a multitude of grid layouts including hexagonal, triangular, rectangular and more.
Apache License 2.0
191 stars 31 forks source link

External Bounding Box has incorrect Y value #59

Open tazdevil78 opened 4 years ago

tazdevil78 commented 4 years ago

Height of a pointy top hex of radius is 2*138 = 276. When the centerY of a hex is 138 the y value of the bounding box should be zero. This is not the value returned by getExternalBoundingBox() .

``
@Test public void yValue() { HexagonalGridBuilder builder = new HexagonalGridBuilder() .setGridHeight(3) .setGridWidth(3) .setGridLayout(HexagonalGridLayout.HEXAGONAL) .setOrientation(HexagonOrientation.POINTY_TOP) .setRadius(138); HexagonalGrid grid = builder.build(); Hexagon hex = (Hexagon) grid.getHexagons().iterator().next(); Rectangle rect = hex.getExternalBoundingBox(); double ctrY = hex.getCenterY(); // 138 double ht = 2*138; assertEquals(ctrY - ht/2, rect.getY(), 0.01f); // expected 0, actual 207 }

tazdevil78 commented 4 years ago

In the pointy orientation, a hexagon has width w = sqrt(3) size and height h = 2 size. https://www.redblobgames.com/grids/hexagons/#size-and-spacing