From 4187bc0e4dd8196e0a3701c089bb378ad6323136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Wed, 7 Jul 2021 00:57:47 +0200 Subject: [PATCH] Add epsilon operator --- .../java/net/minestom/server/utils/coordinate/Vec.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/net/minestom/server/utils/coordinate/Vec.java b/src/main/java/net/minestom/server/utils/coordinate/Vec.java index 6c223d6be..684974688 100644 --- a/src/main/java/net/minestom/server/utils/coordinate/Vec.java +++ b/src/main/java/net/minestom/server/utils/coordinate/Vec.java @@ -392,6 +392,15 @@ public final class Vec implements Point { @FunctionalInterface public interface Operator { + /** + * Checks each axis' value, if it's below {@code 1E-6} then it gets replaced with {@code 0} + */ + Operator EPSILON = (x, y, z) -> new Vec( + Math.abs(x) < 1E-6 ? 0 : x, + Math.abs(y) < 1E-6 ? 0 : y, + Math.abs(z) < 1E-6 ? 0 : z + ); + @NotNull Vec apply(double x, double y, double z); }