ADD #roc mask

This commit is contained in:
Jesse Boyd 2018-04-29 16:32:45 +10:00
parent 81a76dfd30
commit 0f2125cc83
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 80 additions and 22 deletions

View File

@ -12,15 +12,15 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
public static double ADJACENT_MOD = 0.5;
public static double DIAGONAL_MOD = 1 / Math.sqrt(8);
private final CachedMask mask;
private final double max;
private final double min;
private final boolean overlay;
private final boolean checkFirst;
private final int maxY;
private final int distance;
protected final CachedMask mask;
protected final double max;
protected final double min;
protected final boolean overlay;
protected final boolean checkFirst;
protected final int maxY;
protected final int distance;
private transient MutableBlockVector mutable = new MutableBlockVector();
protected transient MutableBlockVector mutable = new MutableBlockVector();
public AngleMask(Extent extent, double min, double max, boolean overlay, int distance) {
super(extent);
@ -46,19 +46,19 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
}
}
private transient int cacheCenX;
private transient int cacheCenZ;
private transient int cacheBotX = Integer.MIN_VALUE;
private transient int cacheBotZ = Integer.MIN_VALUE;
private transient int cacheCenterZ;
protected transient int cacheCenX;
protected transient int cacheCenZ;
protected transient int cacheBotX = Integer.MIN_VALUE;
protected transient int cacheBotZ = Integer.MIN_VALUE;
protected transient int cacheCenterZ;
private transient byte[] cacheHeights;
protected transient byte[] cacheHeights;
private transient int lastY;
private transient int lastX = Integer.MIN_VALUE;
private transient int lastZ = Integer.MIN_VALUE;
private transient boolean foundY;
private transient boolean lastValue;
protected transient int lastY;
protected transient int lastX = Integer.MIN_VALUE;
protected transient int lastZ = Integer.MIN_VALUE;
protected transient boolean foundY;
protected transient boolean lastValue;
public int getHeight(int x, int y, int z) {
// return getExtent().getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
@ -91,7 +91,7 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
}
}
private boolean testSlope(int x, int y, int z) {
protected boolean testSlope(int x, int y, int z) {
double slope;
boolean aboveMin;
lastY = y;

View File

@ -0,0 +1,31 @@
package com.boydti.fawe.object.mask;
import com.sk89q.worldedit.extent.Extent;
public class ROCAngleMask extends AngleMask {
public ROCAngleMask(Extent extent, double min, double max, boolean overlay, int distance) {
super(extent, min, max, overlay, distance);
}
@Override
protected boolean testSlope(int x, int y, int z) {
double slope, tmp;
boolean aboveMin;
lastY = y;
int base = getHeight(x, y, z);
slope = ((getHeight(x + distance, y, z) - base) - (base - getHeight(x - distance, y, z))) * ADJACENT_MOD;
tmp = ((getHeight(x, y, z + distance) - base) - (base - getHeight(x, y, z - distance))) * ADJACENT_MOD;
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
tmp = ((getHeight(x + distance, y, z + distance) - base) - (base - getHeight(x - distance, y, z - distance))) * DIAGONAL_MOD;
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
tmp = ((getHeight(x - distance, y, z + distance) - base) - (base - getHeight(x + distance, y, z - distance))) * DIAGONAL_MOD;
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
return lastValue = (slope >= min && slope <= max);
}
}

View File

@ -256,10 +256,10 @@ public class MaskCommands extends MethodCommands {
}
@Command(
aliases = {"\\", "/"},
aliases = {"\\", "/", "#angle"},
desc = "Restrict to specific terrain angle",
help = "Restrict to specific terrain angle\n" +
"The -o flag will only overlay" +
"The -o flag will only overlay\n" +
"Example: /[0d][45d]\n" +
"Explanation: Allows any block where the adjacent block is between 0 and 45 degrees.\n" +
"Example: /[3][20]\n" +
@ -283,6 +283,33 @@ public class MaskCommands extends MethodCommands {
return new AngleMask(extent, y1, y2, overlay, distance);
}
@Command(
aliases = {"(", ")", "#roc"},
desc = "Restrict to near specific terrain slope rate of change",
help = "Restrict to near specific terrain slope rate of change\n" +
"The -o flag will only overlay\n" +
"Example: ([0d][45d][5]\n" +
"Explanation: Restrict near where the angle changes between 0-45 degrees within 5 blocks\n" +
"Note: Use negatives for decreasing slope",
usage = "<min> <max> [distance=1]",
min = 2,
max = 2
)
public Mask roc(Extent extent, String min, String max, @Switch('o') boolean overlay, @Optional("4") int distance) throws ExpressionException {
double y1, y2;
boolean override;
if (max.endsWith("d")) {
double y1d = Expression.compile(min.substring(0, min.length() - 1)).evaluate();
double y2d = Expression.compile(max.substring(0, max.length() - 1)).evaluate();
y1 = (Math.tan(y1d * (Math.PI / 180)));
y2 = (Math.tan(y2d * (Math.PI / 180)));
} else {
y1 = (Expression.compile(min).evaluate());
y2 = (Expression.compile(max).evaluate());
}
return new ROCAngleMask(extent, y1, y2, overlay, distance);
}
@Command(
aliases = {"{"},
desc = "Restricts blocks to within a specific radius range of the initial block",