Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hex light construction #4979

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading