Skip to content

Commit

Permalink
Merge pull request #4979 from kwvanderlinde/bugfix/4978-hex-light-cen…
Browse files Browse the repository at this point in the history
…ter-and-scale

Fix hex light construction
  • Loading branch information
cwisniew authored Oct 9, 2024
2 parents bdb58b6 + d64e074 commit 7ca4c40
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/main/java/net/rptools/maptool/model/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,7 @@ public void setSize(int size) {
visibleArea.add(new Area(footprintPart));
}
case HEX -> {
double x = footprint.getCenterX();
double y = footprint.getCenterY();

double footprintWidth = footprint.getWidth();
double footprintHeight = footprint.getHeight();
double adjustment = Math.min(footprintWidth, footprintHeight);
x -= adjustment / 2;
y -= adjustment / 2;

visibleArea = createHex(x, y, visionRange, 0);
visibleArea = createHex(visionRange);
}
default -> {
log.error("Unhandled shape {}; treating as a circle", shape);
Expand Down Expand Up @@ -527,25 +518,19 @@ public double cellDistance(CellPoint cellA, CellPoint cellB, WalkerMetric wmetri
return distance;
}

protected Area createHex(double x, double y, double radius, double rotation) {
GeneralPath hexPath = new GeneralPath();
protected Area createHex(double inRadius) {
double radius = inRadius * 2 / Math.sqrt(3);

for (int i = 0; i < 6; i++) {
if (i == 0) {
hexPath.moveTo(
x + radius * Math.cos(i * 2 * Math.PI / 6), y + radius * Math.sin(i * 2 * Math.PI / 6));
} else {
hexPath.lineTo(
x + radius * Math.cos(i * 2 * Math.PI / 6), y + radius * Math.sin(i * 2 * Math.PI / 6));
}
}
var hexPath = new Path2D.Double();
hexPath.moveTo(radius, 0);
hexPath.lineTo(radius * 0.5, inRadius);
hexPath.lineTo(-radius * 0.5, inRadius);
hexPath.lineTo(-radius, 0);
hexPath.lineTo(-radius * 0.5, -inRadius);
hexPath.lineTo(radius * 0.5, -inRadius);
hexPath.closePath();

if (rotation != 0) {
AffineTransform atArea = AffineTransform.getRotateInstance(rotation);
return new Area(atArea.createTransformedShape(hexPath));
} else {
return new Area(hexPath);
}
return new Area(hexPath);
}

private void fireGridChanged() {
Expand Down

0 comments on commit 7ca4c40

Please sign in to comment.