From d564cf17e9a1eb5dba8a0b5993fb1995e2f30130 Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 7 Mar 2015 03:07:48 +0100 Subject: [PATCH] Attempt to fix a ray-tracing issue. --- .../nocheatplus/utilities/RayTracing.java | 19 ++++++++++++------ .../nocheatplus/test/TestRayTracing.java | 20 ++++++++++--------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/RayTracing.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/RayTracing.java index eb553be1..492b878d 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/RayTracing.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/RayTracing.java @@ -21,6 +21,9 @@ public abstract class RayTracing { /** Current block. */ protected int blockX, blockY, blockZ; + /** End block. */ + protected int endBlockX, endBlockY, endBlockZ; + /** Offset within current block. */ protected double oX, oY, oZ; @@ -67,6 +70,9 @@ public abstract class RayTracing { blockX = Location.locToBlock(x0); blockY = Location.locToBlock(y0); blockZ = Location.locToBlock(z0); + endBlockX = Location.locToBlock(x1); + endBlockY = Location.locToBlock(y1); + endBlockZ = Location.locToBlock(z1); oX = (double) (x0 - blockX); oY = (double) (y0 - blockY); oZ = (double) (z0 - blockZ); @@ -74,11 +80,11 @@ public abstract class RayTracing { step = 0; } - private static final double tDiff(final double dTotal, final double offset){ + private static final double tDiff(final double dTotal, final double offset, final int block, final int endBlock){ if (dTotal > 0.0){ if (offset >= 1.0) { // Static block change (e.g. diagonal move). - return 0.0; + return block == endBlock ? Double.MAX_VALUE : 0.0; } else { return (1.0 - offset) / dTotal; } @@ -86,7 +92,7 @@ public abstract class RayTracing { else if (dTotal < 0.0){ if (offset <= 0.0) { // Static block change (e.g. diagonal move). - return 0.0; + return block == endBlock ? Double.MAX_VALUE : 0.0; } else { return offset / -dTotal; } @@ -107,9 +113,9 @@ public abstract class RayTracing { boolean changed; while (1.0 - t > tol){ // Determine smallest time to block edge. - tX = tDiff(dX, oX); - tY = tDiff(dY, oY); - tZ = tDiff(dZ, oZ); + tX = tDiff(dX, oX, blockX, endBlockX); + tY = tDiff(dY, oY, blockY, endBlockY); + tZ = tDiff(dZ, oZ, blockZ, endBlockZ); tMin = Math.min(tX, Math.min(tY, tZ)); if (tMin == Double.MAX_VALUE) { // All differences are 0 (no progress). @@ -186,6 +192,7 @@ public abstract class RayTracing { break; } } + // TODO: Catch special case with going beyond coordinates. } /** diff --git a/NCPPlugin/src/test/java/fr/neatmonster/nocheatplus/test/TestRayTracing.java b/NCPPlugin/src/test/java/fr/neatmonster/nocheatplus/test/TestRayTracing.java index 267bb06d..1644f54a 100644 --- a/NCPPlugin/src/test/java/fr/neatmonster/nocheatplus/test/TestRayTracing.java +++ b/NCPPlugin/src/test/java/fr/neatmonster/nocheatplus/test/TestRayTracing.java @@ -14,6 +14,8 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters; public class TestRayTracing { + // TODO: Add a test that fails if going beyond target block coordinate. + protected static final Random random = new Random(System.nanoTime() + 13391); protected static double maxFactor = 9.0; @@ -90,9 +92,9 @@ public class TestRayTracing { step = 0; } -// private boolean ignEdge(double offset, double dTotal){ -// return offset == 1 && dTotal > 0 || offset == 0 && dTotal < 0; -// } + // private boolean ignEdge(double offset, double dTotal){ + // return offset == 1 && dTotal > 0 || offset == 0 && dTotal < 0; + // } @Override protected boolean step(int blockX, int blockY, int blockZ, double oX, double oY, double oZ, double dT) { @@ -102,13 +104,13 @@ public class TestRayTracing { if (dT < 0.0){ 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. -// if (dT == 0.0 && 1.0 - (t + dT) > tol){ -// if (!ignEdge(oX, dX) && !ignEdge(oY, dY) && !ignEdge(oZ, dZ)){ -// doFail("Premature dT = 0 at t = " + StringUtil.fdec3.format(t), coords); -// } -// } + // if (dT == 0.0 && 1.0 - (t + dT) > tol){ + // if (!ignEdge(oX, dX) && !ignEdge(oY, dY) && !ignEdge(oZ, dZ)){ + // doFail("Premature dT = 0 at t = " + StringUtil.fdec3.format(t), coords); + // } + // } checkOffset(oX, "x"); checkOffset(oY, "y");