Fixed //center not working in some cases.

Due to odd rounding and math issues, using //center on a region with an edge of even
length in quadrants with negative coordinates would only fill one of the two center blocks.

Thanks to Griffrez and up201406036 for the original PR.

Fixes WORDLEDIT-2986.
Dieser Commit ist enthalten in:
wizjany 2017-05-24 20:59:00 -04:00
Ursprung a4f1f57c9d
Commit b2fb73582f
2 geänderte Dateien mit 16 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -59,6 +59,7 @@ import com.sk89q.worldedit.history.changeset.ChangeSet;
import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.internal.expression.runtime.RValue; import com.sk89q.worldedit.internal.expression.runtime.RValue;
import com.sk89q.worldedit.math.MathUtils;
import com.sk89q.worldedit.math.interpolation.Interpolation; import com.sk89q.worldedit.math.interpolation.Interpolation;
import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation; import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation;
import com.sk89q.worldedit.math.interpolation.Node; import com.sk89q.worldedit.math.interpolation.Node;
@ -963,8 +964,9 @@ public class EditSession implements Extent {
Vector center = region.getCenter(); Vector center = region.getCenter();
Region centerRegion = new CuboidRegion( Region centerRegion = new CuboidRegion(
getWorld(), // Causes clamping of Y range getWorld(), // Causes clamping of Y range
new Vector((int) center.getX(), (int) center.getY(), (int) center.getZ()), new Vector(((int) center.getX()), ((int) center.getY()), ((int) center.getZ())),
center.toBlockVector()); new Vector(MathUtils.roundHalfUp(center.getX()),
center.getY(), MathUtils.roundHalfUp(center.getZ())));
return setBlocks(centerRegion, pattern); return setBlocks(centerRegion, pattern);
} }

Datei anzeigen

@ -105,4 +105,16 @@ public final class MathUtils {
return Math.sin(Math.toRadians(degrees)); return Math.sin(Math.toRadians(degrees));
} }
/**
* Returns the rounded double of the given value, rounding to the
* nearest integer value away from zero on ties.
*
* This behavior is the same as {@link java.math.RoundingMode#HALF_UP}.
*
* @param value the value
* @return the rounded value
*/
public static double roundHalfUp(double value) {
return Math.signum(value) * Math.round(Math.abs(value));
}
} }