Add and apply .editorconfig from P2 (#1195)

* Consistenty use javax annotations.
 - Unfortunately jetbrains annotations seem to be exposed transitively via core somewhere, but with the correct IDE settings, annotations can be defaulted to javax
 - Cleaning up of import order in #1195
 - Must be merged before #1195

* Add and apply .editorconfig from P2
 - Does not rearrange entries

* Address some comments

* add back some javadoc comments

* Address final comments

Co-authored-by: NotMyFault <mc.cache@web.de>
This commit is contained in:
dordsor21
2021-07-24 16:34:05 +01:00
committed by GitHub
parent 3b4beba7d6
commit 8c0195970b
1143 changed files with 143599 additions and 9952 deletions

View File

@ -53,7 +53,7 @@ public class BlockVector2 {
* </pre>
*/
public static final Comparator<BlockVector2> COMPARING_GRID_ARRANGEMENT =
Comparator.comparingInt(BlockVector2::getZ).thenComparingInt(BlockVector2::getX);
Comparator.comparingInt(BlockVector2::getZ).thenComparingInt(BlockVector2::getX);
public static BlockVector2 at(double x, double z) {
return at((int) Math.floor(x), (int) Math.floor(z));
@ -508,9 +508,9 @@ public class BlockVector2 {
/**
* Perform a 2D transformation on this vector and return a new one.
*
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param translateX what to add after rotation
* @param translateZ what to add after rotation
* @return a new vector
@ -526,7 +526,8 @@ public class BlockVector2 {
double z2 = x * sin + z * cos;
return BlockVector2.at(
x2 + aboutX + translateX,
z2 + aboutZ + translateZ);
z2 + aboutZ + translateZ
);
}
/**
@ -537,8 +538,8 @@ public class BlockVector2 {
*/
public BlockVector2 getMinimum(BlockVector2 v2) {
return new BlockVector2(
Math.min(x, v2.x),
Math.min(z, v2.z)
Math.min(x, v2.x),
Math.min(z, v2.z)
);
}
@ -550,8 +551,8 @@ public class BlockVector2 {
*/
public BlockVector2 getMaximum(BlockVector2 v2) {
return new BlockVector2(
Math.max(x, v2.x),
Math.max(z, v2.z)
Math.max(x, v2.x),
Math.max(z, v2.z)
);
}
@ -620,9 +621,11 @@ public class BlockVector2 {
/**
* Returns a string representation that is supported by the parser.
*
* @return string
*/
public String toParserString() {
return x + "," + z;
}
}

View File

@ -85,13 +85,14 @@ public abstract class BlockVector3 {
public static boolean isLongPackable(BlockVector3 location) {
return isHorizontallyInBounds(location.getX())
&& isHorizontallyInBounds(location.getZ())
&& WORLD_Y_MIN <= location.getY() && location.getY() <= WORLD_Y_MAX;
&& isHorizontallyInBounds(location.getZ())
&& WORLD_Y_MIN <= location.getY() && location.getY() <= WORLD_Y_MAX;
}
public static void checkLongPackable(BlockVector3 location) {
checkArgument(isLongPackable(location),
"Location exceeds long packing limits: %s", location);
"Location exceeds long packing limits: %s", location
);
}
private static final long BITS_26 = mask(26);
@ -103,10 +104,12 @@ public abstract class BlockVector3 {
// thread-safe initialization idiom
private static final class YzxOrderComparator {
private static final Comparator<BlockVector3> YZX_ORDER =
Comparator.comparingInt(BlockVector3::getY)
.thenComparingInt(BlockVector3::getZ)
.thenComparingInt(BlockVector3::getX);
Comparator.comparingInt(BlockVector3::getY)
.thenComparingInt(BlockVector3::getZ)
.thenComparingInt(BlockVector3::getX);
}
/**
@ -583,9 +586,9 @@ public abstract class BlockVector3 {
//FAWE start - getter
public BlockVector3 cross(BlockVector3 other) {
return new BlockVector3Imp(
getY() * other.getZ() - getZ() * other.getY(),
getZ() * other.getX() - getX() * other.getZ(),
getX() * other.getY() - getY() * other.getX()
getY() * other.getZ() - getZ() * other.getY(),
getZ() * other.getX() - getX() * other.getZ(),
getX() * other.getY() - getY() * other.getX()
);
}
//FAWE end
@ -600,7 +603,7 @@ public abstract class BlockVector3 {
//FAWE start - getter
public boolean containedWithin(BlockVector3 min, BlockVector3 max) {
return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max
.getY() && getZ() >= min.getZ() && getZ() <= max.getZ();
.getY() && getZ() >= min.getZ() && getZ() <= max.getZ();
}
//FAWE end
@ -671,9 +674,9 @@ public abstract class BlockVector3 {
/**
* Perform a 2D transformation on this vector and return a new one.
*
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param translateX what to add after rotation
* @param translateZ what to add after rotation
* @return a new vector
@ -690,9 +693,9 @@ public abstract class BlockVector3 {
double z2 = x * sin + z * cos;
return BlockVector3.at(
x2 + aboutX + translateX,
getY(),
z2 + aboutZ + translateZ
x2 + aboutX + translateX,
getY(),
z2 + aboutZ + translateZ
);
}
//FAWE end
@ -861,6 +864,7 @@ public abstract class BlockVector3 {
/**
* Returns a string representation that is supported by the parser.
*
* @return string
*/
public String toParserString() {

View File

@ -24,11 +24,11 @@ package com.sk89q.worldedit.math;
*/
public final class BlockVector3Imp extends BlockVector3 {
public static final BlockVector3Imp ZERO = new BlockVector3Imp(0, 0, 0);
public static final BlockVector3Imp ZERO = new BlockVector3Imp(0, 0, 0);
public static final BlockVector3Imp UNIT_X = new BlockVector3Imp(1, 0, 0);
public static final BlockVector3Imp UNIT_Y = new BlockVector3Imp(0, 1, 0);
public static final BlockVector3Imp UNIT_Z = new BlockVector3Imp(0, 0, 1);
public static final BlockVector3Imp ONE = new BlockVector3Imp(1, 1, 1);
public static final BlockVector3Imp ONE = new BlockVector3Imp(1, 1, 1);
public static BlockVector3Imp at(double x, double y, double z) {
return at((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z));
@ -84,4 +84,5 @@ public final class BlockVector3Imp extends BlockVector3 {
public String toString() {
return "(" + getX() + ", " + getY() + ", " + getZ() + ")";
}
}

View File

@ -123,4 +123,5 @@ public final class MathUtils {
public static double roundHalfUp(double value) {
return Math.signum(value) * Math.round(Math.abs(value));
}
}

View File

@ -29,11 +29,11 @@ import static com.sk89q.worldedit.math.BlockVector2.COMPARING_GRID_ARRANGEMENT;
public class RegionOptimizedChunkComparator {
private static final Comparator<BlockVector2> CHUNK_COMPARATOR =
Comparator.comparing((BlockVector2 chunkPos) -> chunkPos.shr(5), COMPARING_GRID_ARRANGEMENT)
.thenComparing(COMPARING_GRID_ARRANGEMENT);
Comparator.comparing((BlockVector2 chunkPos) -> chunkPos.shr(5), COMPARING_GRID_ARRANGEMENT)
.thenComparing(COMPARING_GRID_ARRANGEMENT);
public static final Comparator<BlockVector3> INSTANCE
= Comparator.comparing(blockPos -> blockPos.toBlockVector2().shr(4), CHUNK_COMPARATOR);
= Comparator.comparing(blockPos -> blockPos.toBlockVector2().shr(4), CHUNK_COMPARATOR);
private RegionOptimizedChunkComparator() {
}

View File

@ -27,8 +27,8 @@ import java.util.Comparator;
public class RegionOptimizedComparator {
public static final Comparator<BlockVector3> INSTANCE
= RegionOptimizedChunkComparator.INSTANCE
.thenComparing(BlockVector3.sortByCoordsYzx());
= RegionOptimizedChunkComparator.INSTANCE
.thenComparing(BlockVector3.sortByCoordsYzx());
private RegionOptimizedComparator() {
}

View File

@ -378,9 +378,9 @@ public final class Vector2 {
/**
* Perform a 2D transformation on this vector and return a new one.
*
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param translateX what to add after rotation
* @param translateZ what to add after rotation
* @return a new vector
@ -396,7 +396,8 @@ public final class Vector2 {
double z2 = x * sin + z * cos;
return new Vector2(
x2 + aboutX + translateX,
z2 + aboutZ + translateZ);
z2 + aboutZ + translateZ
);
}
/**
@ -407,8 +408,8 @@ public final class Vector2 {
*/
public Vector2 getMinimum(Vector2 v2) {
return new Vector2(
Math.min(x, v2.x),
Math.min(z, v2.z)
Math.min(x, v2.x),
Math.min(z, v2.z)
);
}
@ -420,8 +421,8 @@ public final class Vector2 {
*/
public Vector2 getMaximum(Vector2 v2) {
return new Vector2(
Math.max(x, v2.x),
Math.max(z, v2.z)
Math.max(x, v2.x),
Math.max(z, v2.z)
);
}
@ -482,6 +483,7 @@ public final class Vector2 {
/**
* Returns a string representation that is supported by the parser.
*
* @return string
*/
public String toParserString() {

View File

@ -66,6 +66,7 @@ public abstract class Vector3 {
// thread-safe initialization idiom
private static final class YzxOrderComparator {
private static final Comparator<Vector3> YZX_ORDER = (a, b) -> {
return ComparisonChain.start()
.compare(a.getY(), b.getY())
@ -73,6 +74,7 @@ public abstract class Vector3 {
.compare(a.getX(), b.getX())
.result();
};
}
/**
@ -87,6 +89,7 @@ public abstract class Vector3 {
}
//FAWE start
/**
* Gets the x coordinate rounded, accounting for negative coordinates
*
@ -484,9 +487,9 @@ public abstract class Vector3 {
//FAWE start - getter
public Vector3 cross(Vector3 other) {
return Vector3.at(
getY() * other.getZ() - getZ() * other.getY(),
getZ() * other.getX() - getX() * other.getZ(),
getX() * other.getY() - getY() * other.getX()
getY() * other.getZ() - getZ() * other.getY(),
getZ() * other.getX() - getX() * other.getZ(),
getX() * other.getY() - getY() * other.getX()
);
}
//FAWE end
@ -500,7 +503,8 @@ public abstract class Vector3 {
*/
//FAWE start - getter
public boolean containedWithin(Vector3 min, Vector3 max) {
return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max.getY() && getZ() >= min.getZ() && getZ() <= max.getZ();
return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max.getY() && getZ() >= min.getZ() && getZ() <= max
.getZ();
}
//FAWE end
@ -585,9 +589,9 @@ public abstract class Vector3 {
/**
* Perform a 2D transformation on this vector and return a new one.
*
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param angle in degrees
* @param aboutX about which x coordinate to rotate
* @param aboutZ about which z coordinate to rotate
* @param translateX what to add after rotation
* @param translateZ what to add after rotation
* @return a new vector
@ -604,9 +608,9 @@ public abstract class Vector3 {
double z2 = x * sin + z * cos;
return Vector3.at(
x2 + aboutX + translateX,
getY(),
z2 + aboutZ + translateZ
x2 + aboutX + translateX,
getY(),
z2 + aboutZ + translateZ
);
}
//FAWE end
@ -724,6 +728,7 @@ public abstract class Vector3 {
}
//FAWE start
/**
* Tests if vectors are equal, accounting for floating point errors
*
@ -742,10 +747,7 @@ public abstract class Vector3 {
if (Math.abs(getY() - other.getY()) > 0.000001d) {
return false;
}
if (Math.abs(getZ() - other.getZ()) > 0.000001d) {
return false;
}
return true;
return !(Math.abs(getZ() - other.getZ()) > 0.000001d);
}
//FAWE end
@ -767,6 +769,7 @@ public abstract class Vector3 {
/**
* Returns a string representation that is supported by the parser.
*
* @return string
*/
//FAWE start - getter

View File

@ -28,7 +28,7 @@ public class GaussianKernel extends Kernel {
* Constructor of the kernel.
*
* @param radius the resulting diameter will be radius * 2 + 1
* @param sigma controls 'flatness'
* @param sigma controls 'flatness'
*/
public GaussianKernel(int radius, double sigma) {
super(radius * 2 + 1, radius * 2 + 1, createKernel(radius, sigma));

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.math.convolution;
import com.fastasyncworldedit.core.registry.state.PropertyGroup;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.function.mask.Mask;
@ -26,13 +27,12 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.Regions;
import com.fastasyncworldedit.core.registry.state.PropertyGroup;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Iterator;
import javax.annotation.Nullable;
import java.util.Iterator;
import static com.google.common.base.Preconditions.checkNotNull;
@ -58,7 +58,7 @@ public class HeightMap {
* Constructs the HeightMap.
*
* @param session an edit session
* @param region the region
* @param region the region
*/
//FAWE start
public HeightMap(EditSession session, Region region) {
@ -112,9 +112,26 @@ public class HeightMap {
for (int z = 0; z < height; ++z) {
for (int x = 0; x < width; ++x, index++) {
if (mask != null) {
yTmp = session.getNearestSurfaceTerrainBlock(x + minX, z + minZ, yTmp, minY, maxY, Integer.MIN_VALUE, Integer.MAX_VALUE, mask);
yTmp = session.getNearestSurfaceTerrainBlock(
x + minX,
z + minZ,
yTmp,
minY,
maxY,
Integer.MIN_VALUE,
Integer.MAX_VALUE,
mask
);
} else {
yTmp = session.getNearestSurfaceTerrainBlock(x + minX, z + minZ, yTmp, minY, maxY, Integer.MIN_VALUE, Integer.MAX_VALUE);
yTmp = session.getNearestSurfaceTerrainBlock(
x + minX,
z + minZ,
yTmp,
minY,
maxY,
Integer.MIN_VALUE,
Integer.MAX_VALUE
);
}
switch (yTmp) {
case Integer.MIN_VALUE:
@ -151,7 +168,7 @@ public class HeightMap {
/**
* Apply the filter 'iterations' amount times.
*
* @param filter the filter
* @param filter the filter
* @param iterations the number of iterations
* @return number of blocks affected
* @throws MaxChangedBlocksException if the maximum block change limit is exceeded

View File

@ -43,9 +43,9 @@ public class HeightMapFilter {
/**
* Construct the HeightMapFilter object.
*
* @param kernelWidth the width
* @param kernelWidth the width
* @param kernelHeight the height
* @param kernelData the data
* @param kernelData the data
*/
public HeightMapFilter(int kernelWidth, int kernelHeight, float[] kernelData) {
checkNotNull(kernelData);
@ -74,9 +74,8 @@ public class HeightMapFilter {
* Filter with a 2D kernel.
*
* @param inData the data
* @param width the width
* @param width the width
* @param height the height
*
* @return the modified height map
*/
public int[] filter(int[] inData, int width, int height) {

View File

@ -36,8 +36,8 @@ public final class Polygons {
/**
* Calculates the polygon shape of a cylinder which can then be used for e.g. intersection detection.
*
* @param center the center point of the cylinder
* @param radius the radius of the cylinder
* @param center the center point of the cylinder
* @param radius the radius of the cylinder
* @param maxPoints max points to be used for the calculation
* @return a list of {@link BlockVector2} which resemble the shape as a polygon
*/

View File

@ -104,15 +104,15 @@ public class KochanekBartelsInterpolation implements Interpolation {
* Returns the linear combination of the given coefficients with the nodes adjacent to baseIndex.
*
* @param baseIndex node index
* @param f1 coefficient for baseIndex-1
* @param f2 coefficient for baseIndex
* @param f3 coefficient for baseIndex+1
* @param f4 coefficient for baseIndex+2
* @param f1 coefficient for baseIndex-1
* @param f2 coefficient for baseIndex
* @param f3 coefficient for baseIndex+1
* @param f4 coefficient for baseIndex+2
* @return linear combination of nodes[n-1..n+2] with f1..4
*/
private Vector3 linearCombination(int baseIndex, double f1, double f2, double f3, double f4) {
final Vector3 r1 = retrieve(baseIndex - 1).multiply(f1);
final Vector3 r2 = retrieve(baseIndex ).multiply(f2);
final Vector3 r2 = retrieve(baseIndex).multiply(f2);
final Vector3 r3 = retrieve(baseIndex + 1).multiply(f3);
final Vector3 r4 = retrieve(baseIndex + 2).multiply(f4);
@ -123,7 +123,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
* Retrieves a node. Indexes are clamped to the valid range.
*
* @param index node index to retrieve
* @return nodes[clamp(0, nodes.length-1)]
* @return nodes[clamp(0, nodes.length - 1)]
*/
private Vector3 retrieve(int index) {
if (index < 0) {
@ -190,7 +190,10 @@ public class KochanekBartelsInterpolation implements Interpolation {
final Vector3 b = coeffB[index];
final Vector3 c = coeffC[index];
return a.multiply(1.5 * position - 3.0 * index).add(b).multiply(2.0 * position).add(a.multiply(1.5 * index).subtract(b).multiply(2.0 * index)).add(c).multiply(scaling);
return a.multiply(1.5 * position - 3.0 * index).add(b).multiply(2.0 * position).add(a
.multiply(1.5 * index)
.subtract(b)
.multiply(2.0 * index)).add(c).multiply(scaling);
}
@Override
@ -226,11 +229,11 @@ public class KochanekBartelsInterpolation implements Interpolation {
case 1:
// This case is merely a speed-up for a very common case
return arcLengthRecursive(indexLeft, remainderLeft, 1.0)
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
default:
return arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0)
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
}
}

View File

@ -130,11 +130,11 @@ public class LinearInterpolation implements Interpolation {
case 1:
// This case is merely a speed-up for a very common case
return arcLengthRecursive(indexA, remainderA, 1.0)
+ arcLengthRecursive(indexB, 0.0, remainderB);
+ arcLengthRecursive(indexB, 0.0, remainderB);
default:
return arcLengthRecursive(indexA, remainderA, indexB - 1, 1.0)
+ arcLengthRecursive(indexB, 0.0, remainderB);
+ arcLengthRecursive(indexB, 0.0, remainderB);
}
}

View File

@ -105,9 +105,11 @@ public class AffineTransform implements Transform, Serializable {
}
}
public AffineTransform(double xx, double yx, double zx, double tx,
double xy, double yy, double zy, double ty, double xz, double yz,
double zz, double tz) {
public AffineTransform(
double xx, double yx, double zx, double tx,
double xy, double yy, double zy, double ty, double xz, double yz,
double zz, double tz
) {
m00 = xx;
m01 = yx;
m02 = zx;
@ -128,9 +130,9 @@ public class AffineTransform implements Transform, Serializable {
@Override
public boolean isIdentity() {
return m00 == m11 && m11 == m22 && m22 == 1
&& m01 == m02 && m02 == m03 && m03 == 0
&& m10 == m12 && m12 == m13 && m13 == 0
&& m20 == m21 && m21 == m23 && m23 == 0;
&& m01 == m02 && m02 == m03 && m03 == 0
&& m10 == m12 && m12 == m13 && m13 == 0
&& m20 == m21 && m21 == m23 && m23 == 0;
}
/**
@ -186,7 +188,8 @@ public class AffineTransform implements Transform, Serializable {
(m20 * m01 - m00 * m21) / det,
(m00 * m11 - m10 * m01) / det,
(m00 * (m21 * m13 - m11 * m23) + m01 * (m10 * m23 - m20 * m13)
- m03 * (m10 * m21 - m20 * m11)) / det);
- m03 * (m10 * m21 - m20 * m11)) / det
);
}
// ===================================================================
@ -215,7 +218,8 @@ public class AffineTransform implements Transform, Serializable {
return new AffineTransform(
n00, n01, n02, n03,
n10, n11, n12, n13,
n20, n21, n22, n23);
n20, n21, n22, n23
);
}
/**
@ -241,7 +245,8 @@ public class AffineTransform implements Transform, Serializable {
return new AffineTransform(
n00, n01, n02, n03,
n10, n11, n12, n13,
n20, n21, n22, n23);
n20, n21, n22, n23
);
}
public AffineTransform translate(Vector3 vec) {
@ -263,7 +268,8 @@ public class AffineTransform implements Transform, Serializable {
new AffineTransform(
1, 0, 0, 0,
0, cot, -sit, 0,
0, sit, cot, 0));
0, sit, cot, 0
));
}
public AffineTransform rotateY(double theta) {
@ -273,7 +279,8 @@ public class AffineTransform implements Transform, Serializable {
new AffineTransform(
cot, 0, sit, 0,
0, 1, 0, 0,
-sit, 0, cot, 0));
-sit, 0, cot, 0
));
}
public AffineTransform rotateZ(double theta) {
@ -283,7 +290,8 @@ public class AffineTransform implements Transform, Serializable {
new AffineTransform(
cot, -sit, 0, 0,
sit, cot, 0, 0,
0, 0, 1, 0));
0, 0, 1, 0
));
}
public AffineTransform scale(double s) {
@ -369,7 +377,21 @@ public class AffineTransform implements Transform, Serializable {
@Override
public String toString() {
return String.format("Affine[%g %g %g %g, %g %g %g %g, %g %g %g %g]}", m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23);
return String.format(
"Affine[%g %g %g %g, %g %g %g %g, %g %g %g %g]}",
m00,
m01,
m02,
m03,
m10,
m11,
m12,
m13,
m20,
m21,
m22,
m23
);
}

View File

@ -36,7 +36,7 @@ public final class Transforms {
*
* <p>Direction is unaffected.</p>
*
* @param location the location
* @param location the location
* @param transform the transform
* @return the transformed location
*/