diff --git a/jme3-core/src/main/java/com/jme3/math/Quaternion.java b/jme3-core/src/main/java/com/jme3/math/Quaternion.java index 0625b8edd..0a5b818b6 100644 --- a/jme3-core/src/main/java/com/jme3/math/Quaternion.java +++ b/jme3-core/src/main/java/com/jme3/math/Quaternion.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -1279,6 +1279,29 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl } return true; } + + /** + * Returns true if this quaternion is similar to the specified quaternion + * within some value of epsilon. + */ + public boolean isSimilar(Quaternion other, float epsilon) { + if (other == null) { + return false; + } + if (Float.compare(Math.abs(other.x - x), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.y - y), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.z - z), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.w - w), epsilon) > 0) { + return false; + } + return true; + } /** * diff --git a/jme3-core/src/main/java/com/jme3/math/Vector2f.java b/jme3-core/src/main/java/com/jme3/math/Vector2f.java index 1ad2ac0c6..22a3cb6e1 100644 --- a/jme3-core/src/main/java/com/jme3/math/Vector2f.java +++ b/jme3-core/src/main/java/com/jme3/math/Vector2f.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -693,6 +693,23 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable return false; return true; } + + /** + * Returns true if this vector is similar to the specified vector within + * some value of epsilon. + */ + public boolean isSimilar(Vector2f other, float epsilon) { + if (other == null) { + return false; + } + if (Float.compare(Math.abs(other.x - x), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.y - y), epsilon) > 0) { + return false; + } + return true; + } /** * toString returns the string representation of this vector diff --git a/jme3-core/src/main/java/com/jme3/math/Vector3f.java b/jme3-core/src/main/java/com/jme3/math/Vector3f.java index d5fdac06c..04638ef2b 100644 --- a/jme3-core/src/main/java/com/jme3/math/Vector3f.java +++ b/jme3-core/src/main/java/com/jme3/math/Vector3f.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -969,6 +969,26 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable if (Float.compare(z,comp.z) != 0) return false; return true; } + + /** + * Returns true if this vector is similar to the specified vector within + * some value of epsilon. + */ + public boolean isSimilar(Vector3f other, float epsilon) { + if (other == null) { + return false; + } + if (Float.compare(Math.abs(other.x - x), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.y - y), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.z - z), epsilon) > 0) { + return false; + } + return true; + } /** * hashCode returns a unique code for this vector object based diff --git a/jme3-core/src/main/java/com/jme3/math/Vector4f.java b/jme3-core/src/main/java/com/jme3/math/Vector4f.java index 2993c4f0c..d7c3e48f1 100644 --- a/jme3-core/src/main/java/com/jme3/math/Vector4f.java +++ b/jme3-core/src/main/java/com/jme3/math/Vector4f.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -874,6 +874,29 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable if (Float.compare(w,comp.w) != 0) return false; return true; } + + /** + * Returns true if this vector is similar to the specified vector within + * some value of epsilon. + */ + public boolean isSimilar(Vector4f other, float epsilon) { + if (other == null) { + return false; + } + if (Float.compare(Math.abs(other.x - x), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.y - y), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.z - z), epsilon) > 0) { + return false; + } + if (Float.compare(Math.abs(other.w - w), epsilon) > 0) { + return false; + } + return true; + } /** * hashCode returns a unique code for this vector object based @@ -1001,4 +1024,4 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable throw new IllegalArgumentException("index must be either 0, 1, 2 or 3"); } -} \ No newline at end of file +}