Skip to content

Commit 8a74c80

Browse files
authored
Fix //cone command generating weird shapes (#3477)
1 parent 4ed147a commit 8a74c80

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,56 +2397,55 @@ public int makeCone(
23972397

23982398
final int ceilRadiusX = (int) Math.ceil(radiusX);
23992399
final int ceilRadiusZ = (int) Math.ceil(radiusZ);
2400-
2401-
final double rx2 = Math.pow(radiusX, 2);
2402-
final double ry2 = Math.pow(radiusZ, 2);
2403-
final double rz2 = Math.pow(height, 2);
2400+
final double radiusXPow = Math.pow(radiusX, 2);
2401+
final double radiusZPow = Math.pow(radiusZ, 2);
2402+
final double heightPow = Math.pow(height, 2);
24042403
final int layers = Math.abs(height);
24052404

24062405
int cx = pos.x();
24072406
int cy = pos.y();
24082407
int cz = pos.z();
24092408

24102409
for (int y = 0; y < layers; ++y) {
2411-
double ySquaredMinusHeightOverHeightSquared = Math.pow(y - layers, 2) / ry2;
2410+
double ySquaredMinusHeightOverHeightSquared = Math.pow(y - layers, 2) / heightPow;
24122411
int yy = height < 0 ? cy - y : cy + y;
2412+
24132413
forX:
24142414
for (int x = 0; x <= ceilRadiusX; ++x) {
2415-
double xSquaredOverRadiusX = Math.pow(x, 2) / rx2;
2416-
int xx = cx + x;
2417-
forZ:
2415+
double xSquaredOverRadiusX = Math.pow(x, 2) / radiusXPow;
2416+
24182417
for (int z = 0; z <= ceilRadiusZ; ++z) {
2419-
int zz = cz + z;
2420-
double zSquaredOverRadiusZ = Math.pow(z, 2) / rz2;
2418+
double zSquaredOverRadiusZ = Math.pow(z, 2) / radiusZPow;
24212419
double distanceFromOriginMinusHeightSquared = xSquaredOverRadiusX + zSquaredOverRadiusZ - ySquaredMinusHeightOverHeightSquared;
24222420

24232421
if (distanceFromOriginMinusHeightSquared > 1) {
24242422
if (z == 0) {
24252423
break forX;
24262424
}
2427-
break forZ;
2425+
break;
24282426
}
24292427

24302428
if (!filled) {
2431-
double xNext = Math.pow(x + thickness, 2) / rx2 + zSquaredOverRadiusZ - ySquaredMinusHeightOverHeightSquared;
2432-
double yNext = xSquaredOverRadiusX + zSquaredOverRadiusZ - Math.pow(y + thickness - height, 2) / ry2;
2433-
double zNext = xSquaredOverRadiusX + Math.pow(z + thickness, 2) / rz2 - ySquaredMinusHeightOverHeightSquared;
2429+
double xNext = Math.pow(x + thickness, 2) / radiusXPow + zSquaredOverRadiusZ - ySquaredMinusHeightOverHeightSquared;
2430+
double yNext =
2431+
xSquaredOverRadiusX + zSquaredOverRadiusZ - Math.pow(y + thickness - layers, 2) / radiusZPow;
2432+
double zNext = xSquaredOverRadiusX + Math.pow(z + thickness, 2) / heightPow - ySquaredMinusHeightOverHeightSquared;
24342433
if (xNext <= 0 && zNext <= 0 && (yNext <= 0 && y + thickness != layers)) {
24352434
continue;
24362435
}
24372436
}
24382437

24392438
if (distanceFromOriginMinusHeightSquared <= 0) {
2440-
if (setBlock(xx, yy, zz, block)) {
2439+
if (setBlock(cx + x, yy, cz + z, block)) {
24412440
++affected;
24422441
}
2443-
if (setBlock(xx, yy, zz, block)) {
2442+
if (setBlock(cx - x, yy, cz + z, block)) {
24442443
++affected;
24452444
}
2446-
if (setBlock(xx, yy, zz, block)) {
2445+
if (setBlock(cx + x, yy, cz - z, block)) {
24472446
++affected;
24482447
}
2449-
if (setBlock(xx, yy, zz, block)) {
2448+
if (setBlock(cx - x, yy, cz - z, block)) {
24502449
++affected;
24512450
}
24522451
}

0 commit comments

Comments
 (0)