mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-10-04 17:37:55 +02:00
Hot-fix passable, for reducing false positives.
Prevents iterating too far, at the cost of skipping some testing.
This commit is contained in:
parent
d564cf17e9
commit
84d47e52b9
@ -39,11 +39,11 @@ public abstract class RayTracing {
|
|||||||
/** Maximum steps that will be done. */
|
/** Maximum steps that will be done. */
|
||||||
private int maxSteps = Integer.MAX_VALUE;
|
private int maxSteps = Integer.MAX_VALUE;
|
||||||
|
|
||||||
public RayTracing(double x0, double y0, double z0, double x1, double y1, double z1){
|
public RayTracing(double x0, double y0, double z0, double x1, double y1, double z1) {
|
||||||
set(x0, y0, z0, x1, y1, z1);
|
set(x0, y0, z0, x1, y1, z1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RayTracing(){
|
public RayTracing() {
|
||||||
set(0, 0, 0, 0, 0, 0);
|
set(0, 0, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public abstract class RayTracing {
|
|||||||
* @param y1
|
* @param y1
|
||||||
* @param z1
|
* @param z1
|
||||||
*/
|
*/
|
||||||
public void set(double x0, double y0, double z0, double x1, double y1, double z1){
|
public void set(double x0, double y0, double z0, double x1, double y1, double z1) {
|
||||||
// this.x0 = x0;
|
// this.x0 = x0;
|
||||||
// this.y0 = y0;
|
// this.y0 = y0;
|
||||||
// this.z0 = z0;
|
// this.z0 = z0;
|
||||||
@ -80,24 +80,24 @@ public abstract class RayTracing {
|
|||||||
step = 0;
|
step = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final double tDiff(final double dTotal, final double offset, final int block, final int endBlock){
|
private static final double tDiff(final double dTotal, final double offset, final int block, final int endBlock) {
|
||||||
if (dTotal > 0.0){
|
if (dTotal > 0.0) {
|
||||||
if (offset >= 1.0) {
|
if (offset >= 1.0) {
|
||||||
// Static block change (e.g. diagonal move).
|
// Static block change (e.g. diagonal move).
|
||||||
return block == endBlock ? Double.MAX_VALUE : 0.0;
|
return 0.0; // block == endBlock ? Double.MAX_VALUE : 0.0;
|
||||||
} else {
|
} else {
|
||||||
return (1.0 - offset) / dTotal;
|
return (1.0 - offset) / dTotal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (dTotal < 0.0){
|
else if (dTotal < 0.0) {
|
||||||
if (offset <= 0.0) {
|
if (offset <= 0.0) {
|
||||||
// Static block change (e.g. diagonal move).
|
// Static block change (e.g. diagonal move).
|
||||||
return block == endBlock ? Double.MAX_VALUE : 0.0;
|
return 0.0; //block == endBlock ? Double.MAX_VALUE : 0.0;
|
||||||
} else {
|
} else {
|
||||||
return offset / -dTotal;
|
return offset / -dTotal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,13 +105,13 @@ public abstract class RayTracing {
|
|||||||
/**
|
/**
|
||||||
* Loop through blocks.
|
* Loop through blocks.
|
||||||
*/
|
*/
|
||||||
public void loop(){
|
public void loop() {
|
||||||
// TODO: Might intercept 0 dist ?
|
// TODO: Might intercept 0 dist ?
|
||||||
|
|
||||||
// Time to block edge.
|
// Time to block edge.
|
||||||
double tX, tY, tZ, tMin;
|
double tX, tY, tZ, tMin;
|
||||||
boolean changed;
|
boolean changed;
|
||||||
while (1.0 - t > tol){
|
while (1.0 - t > tol) {
|
||||||
// Determine smallest time to block edge.
|
// Determine smallest time to block edge.
|
||||||
tX = tDiff(dX, oX, blockX, endBlockX);
|
tX = tDiff(dX, oX, blockX, endBlockX);
|
||||||
tY = tDiff(dY, oY, blockY, endBlockY);
|
tY = tDiff(dY, oY, blockY, endBlockY);
|
||||||
@ -135,7 +135,7 @@ public abstract class RayTracing {
|
|||||||
if (!step(blockX, blockY, blockZ, oX, oY, oZ, tMin)) {
|
if (!step(blockX, blockY, blockZ, oX, oY, oZ, tMin)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (t + tMin >= 1.0 - tol) {
|
if (t + tMin >= 1.0 - tol) { // && isEndBlock()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Advance (add to t etc.).
|
// Advance (add to t etc.).
|
||||||
@ -145,13 +145,13 @@ public abstract class RayTracing {
|
|||||||
oZ = Math.min(1.0, Math.max(0.0, oZ + tMin * dZ));
|
oZ = Math.min(1.0, Math.max(0.0, oZ + tMin * dZ));
|
||||||
// TODO: Consider Heuristic change of the checking order for dy > 0 vs. dy < 0.
|
// TODO: Consider Heuristic change of the checking order for dy > 0 vs. dy < 0.
|
||||||
// x
|
// x
|
||||||
if (tX == tMin){
|
if (tX == tMin && blockX != endBlockX) {
|
||||||
if (dX < 0){
|
if (dX < 0) {
|
||||||
oX = 1.0;
|
oX = 1.0;
|
||||||
blockX --;
|
blockX --;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
else if (dX > 0){
|
else if (dX > 0) {
|
||||||
oX = 0.0;
|
oX = 0.0;
|
||||||
blockX ++;
|
blockX ++;
|
||||||
changed = true;
|
changed = true;
|
||||||
@ -159,13 +159,13 @@ public abstract class RayTracing {
|
|||||||
}
|
}
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
// y
|
// y
|
||||||
if (tY == tMin){
|
if (tY == tMin && blockY != endBlockY) {
|
||||||
if (dY < 0){
|
if (dY < 0) {
|
||||||
oY = 1.0;
|
oY = 1.0;
|
||||||
blockY --;
|
blockY --;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
else if (dY > 0){
|
else if (dY > 0) {
|
||||||
oY = 0.0;
|
oY = 0.0;
|
||||||
blockY ++;
|
blockY ++;
|
||||||
changed = true;
|
changed = true;
|
||||||
@ -173,13 +173,13 @@ public abstract class RayTracing {
|
|||||||
}
|
}
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
// z
|
// z
|
||||||
if (tZ == tMin){
|
if (tZ == tMin && blockZ != endBlockZ) {
|
||||||
if (dZ < 0){
|
if (dZ < 0) {
|
||||||
oZ = 1.0;
|
oZ = 1.0;
|
||||||
blockZ --;
|
blockZ --;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
else if (dZ > 0){
|
else if (dZ > 0) {
|
||||||
oZ = 0.0;
|
oZ = 0.0;
|
||||||
blockZ ++;
|
blockZ ++;
|
||||||
changed = true;
|
changed = true;
|
||||||
@ -188,7 +188,7 @@ public abstract class RayTracing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
t += tMin;
|
t += tMin;
|
||||||
if (!changed || step >= maxSteps){
|
if (!changed || step >= maxSteps) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,6 +203,10 @@ public abstract class RayTracing {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEndBlock() {
|
||||||
|
return blockX == endBlockX && blockY == endBlockY && blockZ == endBlockZ;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is for external use. The field step will be incremented before
|
* This is for external use. The field step will be incremented before
|
||||||
* step(...) is called, thus checking it from within step means to get the
|
* step(...) is called, thus checking it from within step means to get the
|
||||||
@ -210,7 +214,7 @@ public abstract class RayTracing {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getStepsDone(){
|
public int getStepsDone() {
|
||||||
return step;
|
return step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,16 @@ public class TestRayTracing {
|
|||||||
|
|
||||||
protected static double maxFactor = 9.0;
|
protected static double maxFactor = 9.0;
|
||||||
|
|
||||||
protected static int maxSteps(double dX, double dY, double dZ){
|
protected static int maxSteps(double dX, double dY, double dZ) {
|
||||||
return (int) (maxFactor * (1 + Math.abs(dX) + Math.abs(dY) + Math.abs(dZ)));
|
return (int) (maxFactor * (1 + Math.abs(dX) + Math.abs(dY) + Math.abs(dZ)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CountRayTracing extends RayTracing{
|
public static class CountRayTracing extends RayTracing {
|
||||||
|
|
||||||
public CountRayTracing(double x0, double y0, double z0, double x1, double y1, double z1) {
|
public CountRayTracing(double x0, double y0, double z0, double x1, double y1, double z1) {
|
||||||
super(x0, y0, z0, x1, y1, z1);
|
super(x0, y0, z0, x1, y1, z1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean step(int blockX, int blockY, int blockZ, double oX,
|
protected boolean step(int blockX, int blockY, int blockZ, double oX,
|
||||||
double oY, double oZ, double dT) {
|
double oY, double oZ, double dT) {
|
||||||
@ -37,19 +39,20 @@ public class TestRayTracing {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double[] randomCoords(double max){
|
public static double[] randomCoords(double max) {
|
||||||
double[] res = new double[6];
|
double[] res = new double[6];
|
||||||
for (int i = 0; i < 6 ; i++){
|
for (int i = 0; i < 6 ; i++) {
|
||||||
res[i] = (random.nextDouble() * 2.0 - 1.0 ) * max;
|
res[i] = (random.nextDouble() * 2.0 - 1.0 ) * max;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double[] randomBlockCoords(int max){
|
public static double[] randomBlockCoords(int max) {
|
||||||
double[] res = new double[6];
|
double[] res = new double[6];
|
||||||
for (int i = 0; i < 6 ; i++){
|
for (int i = 0; i < 6 ; i++) {
|
||||||
res[i] = random.nextInt(max * 2 + 1) - max;
|
res[i] = random.nextInt(max * 2 + 1) - max;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@ -58,7 +61,7 @@ public class TestRayTracing {
|
|||||||
public static void doFail(String message, double[] coords) {
|
public static void doFail(String message, double[] coords) {
|
||||||
System.out.println("---- Failure trace ----");
|
System.out.println("---- Failure trace ----");
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
if (coords != null){
|
if (coords != null) {
|
||||||
System.out.println("{" + coords[0] + ", " + coords[1]+ ", " + coords[2] + " , " + coords[3] + ", " + coords[4]+ ", " + coords[5] + "}");
|
System.out.println("{" + coords[0] + ", " + coords[1]+ ", " + coords[2] + " , " + coords[3] + ", " + coords[4]+ ", " + coords[5] + "}");
|
||||||
dumpRawRayTracing(coords);
|
dumpRawRayTracing(coords);
|
||||||
}
|
}
|
||||||
@ -70,7 +73,7 @@ public class TestRayTracing {
|
|||||||
* @param coords
|
* @param coords
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static RayTracing checkConsistency(final double[] coords){
|
public static RayTracing checkConsistency(final double[] coords) {
|
||||||
RayTracing rt = new RayTracing(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]) {
|
RayTracing rt = new RayTracing(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]) {
|
||||||
|
|
||||||
protected int lbx, lby, lbz;
|
protected int lbx, lby, lbz;
|
||||||
@ -92,7 +95,7 @@ public class TestRayTracing {
|
|||||||
step = 0;
|
step = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private boolean ignEdge(double offset, double dTotal){
|
// private boolean ignEdge(double offset, double dTotal) {
|
||||||
// return offset == 1 && dTotal > 0 || offset == 0 && dTotal < 0;
|
// return offset == 1 && dTotal > 0 || offset == 0 && dTotal < 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@ -101,13 +104,13 @@ public class TestRayTracing {
|
|||||||
// TODO: This does not check last step for some occasions where it should.
|
// TODO: This does not check last step for some occasions where it should.
|
||||||
step ++;
|
step ++;
|
||||||
|
|
||||||
if (dT < 0.0){
|
if (dT < 0.0) {
|
||||||
doFail("dT < 0 at t = " + StringUtil.fdec3.format(t), coords);
|
doFail("dT < 0 at t = " + StringUtil.fdec3.format(t), coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check if this check makes sense at all (dT=0 happens during multi-transitions.)l.
|
// TODO: Check if this check makes sense at all (dT=0 happens during multi-transitions.)l.
|
||||||
// if (dT == 0.0 && 1.0 - (t + dT) > tol){
|
// if (dT == 0.0 && 1.0 - (t + dT) > tol) {
|
||||||
// if (!ignEdge(oX, dX) && !ignEdge(oY, dY) && !ignEdge(oZ, dZ)){
|
// if (!ignEdge(oX, dX) && !ignEdge(oY, dY) && !ignEdge(oZ, dZ)) {
|
||||||
// doFail("Premature dT = 0 at t = " + StringUtil.fdec3.format(t), coords);
|
// doFail("Premature dT = 0 at t = " + StringUtil.fdec3.format(t), coords);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@ -117,8 +120,8 @@ public class TestRayTracing {
|
|||||||
checkOffset(oZ, "z");
|
checkOffset(oZ, "z");
|
||||||
|
|
||||||
// TODO: check with last block coordinates
|
// TODO: check with last block coordinates
|
||||||
if (lbx == blockX && lby == blockY && lbz == blockZ){
|
if (lbx == blockX && lby == blockY && lbz == blockZ) {
|
||||||
if (1.0 - (t + dT) > tol){
|
if (1.0 - (t + dT) > tol) {
|
||||||
doFail("Expect block coordinates to change with each step (step=" + step + ", t=" + StringUtil.fdec3.format(t) +").", coords);
|
doFail("Expect block coordinates to change with each step (step=" + step + ", t=" + StringUtil.fdec3.format(t) +").", coords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,18 +142,18 @@ public class TestRayTracing {
|
|||||||
@Override
|
@Override
|
||||||
public void loop() {
|
public void loop() {
|
||||||
super.loop();
|
super.loop();
|
||||||
checkBlockTarget(coords[3], blockX, oX, dX, ldt, "x");
|
// checkBlockTarget(coords[3], blockX, oX, dX, ldt, "x");
|
||||||
checkBlockTarget(coords[4], blockY, oY, dY, ldt, "y");
|
// checkBlockTarget(coords[4], blockY, oY, dY, ldt, "y");
|
||||||
checkBlockTarget(coords[5], blockZ, oZ, dZ, ldt, "z");
|
// checkBlockTarget(coords[5], blockZ, oZ, dZ, ldt, "z");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBlockTarget(double target, int current, double offset, double dTotal, double dT, String name){
|
private void checkBlockTarget(double target, int current, double offset, double dTotal, double dT, String name) {
|
||||||
int b = Location.locToBlock(target);
|
int b = Location.locToBlock(target);
|
||||||
if (current != b){
|
if (current != b) {
|
||||||
// TODO: Might do with or without these ?
|
// TODO: Might do with or without these ?
|
||||||
// if (current == b + 1 && dTotal > 0 && offset == 0) return;
|
// if (current == b + 1 && dTotal > 0 && offset == 0) return;
|
||||||
// if (current == b - 1 && dTotal < 0 && offset == 1) return;
|
// if (current == b - 1 && dTotal < 0 && offset == 1) return;
|
||||||
if (Math.abs(dT * dTotal + offset + (double) current - target) <= 0.001){
|
if (Math.abs(dT * dTotal + offset + (double) current - target) <= 0.001) {
|
||||||
// TODO: Narrow down by edge coordinates or so.
|
// TODO: Narrow down by edge coordinates or so.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -161,6 +164,9 @@ public class TestRayTracing {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
rt.loop();
|
rt.loop();
|
||||||
|
if (!rt.isEndBlock()) {
|
||||||
|
//doFail("Incorrect end block.", coords);
|
||||||
|
}
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +174,12 @@ public class TestRayTracing {
|
|||||||
CountRayTracing crt = new CountRayTracing(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
|
CountRayTracing crt = new CountRayTracing(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
|
||||||
crt.loop();
|
crt.loop();
|
||||||
int done = crt.getStepsDone();
|
int done = crt.getStepsDone();
|
||||||
if (done != steps) doFail("Wrong number of steps: " + done + " instead of " + steps, coords);
|
if (done != steps) {
|
||||||
|
doFail("Wrong number of steps: " + done + " instead of " + steps, coords);
|
||||||
|
}
|
||||||
|
if (!crt.isEndBlock()) {
|
||||||
|
//doFail("Incorrect end block.", coords);
|
||||||
|
}
|
||||||
return crt;
|
return crt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +194,7 @@ public class TestRayTracing {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean step(int blockX, int blockY, int blockZ, double oX, double oY, double oZ, double dT) {
|
protected boolean step(int blockX, int blockY, int blockZ, double oX, double oY, double oZ, double dT) {
|
||||||
dump(blockX, blockY, blockZ, oX, oY, oZ, t, dT);
|
dump(blockX, blockY, blockZ, oX, oY, oZ, t, dT);
|
||||||
if (step > maxSteps(dX, dY, dZ)){
|
if (step > maxSteps(dX, dY, dZ)) {
|
||||||
System.out.println("[WARNING] Max steps exceeded: " + maxSteps(dX, dY, dZ));
|
System.out.println("[WARNING] Max steps exceeded: " + maxSteps(dX, dY, dZ));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -191,19 +202,22 @@ public class TestRayTracing {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
rt.loop();
|
rt.loop();
|
||||||
|
if (!rt.isEndBlock()) {
|
||||||
|
System.out.println("[WARNING] Incorrect end block.");
|
||||||
|
}
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNumberOfSteps(){
|
public void testNumberOfSteps() {
|
||||||
// Hand picked stuff.
|
// Hand picked stuff.
|
||||||
checkNumberOfSteps(new double[]{0.5, 0.5, 0.5, 1.5, -0.5, 1.5}, 4);
|
checkNumberOfSteps(new double[]{0.5, 0.5, 0.5, 1.5, -0.5, 1.5}, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConsistency(){
|
public void testConsistency() {
|
||||||
// Past failures / making a difference.
|
// Past failures / making a difference.
|
||||||
for (double[] coords : new double[][]{
|
for (double[] coords : new double[][] {
|
||||||
// Sort by x0.
|
// Sort by x0.
|
||||||
new double[]{-9.873, -4.773, -3.387, -0.161, -1.879, -7.079},
|
new double[]{-9.873, -4.773, -3.387, -0.161, -1.879, -7.079},
|
||||||
new double[]{-3.0066423238842366, 0.8056808285866079, 5.359238045631369 , 2.0000000356757375, -2.3002237817433757, -5.889349195033338},
|
new double[]{-3.0066423238842366, 0.8056808285866079, 5.359238045631369 , 2.0000000356757375, -2.3002237817433757, -5.889349195033338},
|
||||||
@ -211,19 +225,20 @@ public class TestRayTracing {
|
|||||||
new double[]{7.388348424961977, -8.000000029346532, -2.5365675909347507 , 2.17126848312847, 3.236994108042559, -8.423292642985071},
|
new double[]{7.388348424961977, -8.000000029346532, -2.5365675909347507 , 2.17126848312847, 3.236994108042559, -8.423292642985071},
|
||||||
new double[]{7.525633617461991, 2.654408573114717, 3.5119744782127893 , 9.99999995904821, 9.599753890871172, 6.721727939686946},
|
new double[]{7.525633617461991, 2.654408573114717, 3.5119744782127893 , 9.99999995904821, 9.599753890871172, 6.721727939686946},
|
||||||
new double[] {-6.0, -4.0, -3.0 , -4.0, -3.0, -2.0},
|
new double[] {-6.0, -4.0, -3.0 , -4.0, -3.0, -2.0},
|
||||||
}){
|
new double[]{-3.0, 3.0, -6.0 , 2.0, -3.0, 4.0},
|
||||||
|
}) {
|
||||||
checkConsistency(coords);
|
checkConsistency(coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean e = BuildParameters.testLevel > 0;
|
final boolean e = BuildParameters.testLevel > 0;
|
||||||
|
|
||||||
// Random tests.
|
// Random tests.
|
||||||
for (int i = 0; i < (e ? 50000000 : 100000); i++){
|
for (int i = 0; i < (e ? 50000000 : 100000); i++) {
|
||||||
checkConsistency(randomCoords(10.0));
|
checkConsistency(randomCoords(10.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make these work.
|
// TODO: make these work.
|
||||||
for (int i = 0; i < (e ? 10000000 : 1000); i++){
|
for (int i = 0; i < (e ? 10000000 : 1000); i++) {
|
||||||
checkConsistency(randomBlockCoords(6));
|
checkConsistency(randomBlockCoords(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user