From 3f6b70e6ca986c2c6e73303c2e08b72814f77d07 Mon Sep 17 00:00:00 2001 From: garyantonyo Date: Wed, 2 Oct 2024 10:44:31 -0400 Subject: [PATCH] Add 0.00000000001 to "ambit radius squared" calculations to account for potential machine precision errors when calculating the ambit at specific angles. --- .../hexcasting/api/casting/eval/env/CircleCastEnv.java | 2 +- .../hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java index 7a9bac13cc..a5cfdaa625 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java @@ -139,7 +139,7 @@ public boolean isVecInRangeEnvironment(Vec3 vec) { if (sentinel != null && sentinel.extendsRange() && caster.level().dimension() == sentinel.dimension() - && vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + && vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + 0.00000000001 ) { return true; } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java index c137930071..52b7ee979e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java @@ -178,12 +178,13 @@ public boolean isVecInRangeEnvironment(Vec3 vec) { if (sentinel != null && sentinel.extendsRange() && this.caster.level().dimension() == sentinel.dimension() - && vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + // adding 0.00000000001 to avoid machine precision errors at specific angles + && vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + 0.00000000001 ) { return true; } - return vec.distanceToSqr(this.caster.position()) <= AMBIT_RADIUS * AMBIT_RADIUS; + return vec.distanceToSqr(this.caster.position()) <= AMBIT_RADIUS * AMBIT_RADIUS + 0.00000000001; } @Override