Added isSimilar() to Quaternion, Vector2f, Vector3f and Vector4f (#1015)

* Added isSimilar() to Quaternion.

* Added isSimilar() to Vector2f.

* Added isSimilar() to Vector3f.

* Added isSimilar() to Vector4f.

* Modified isSimilar() to consider NaN.
accellbaker
Ali-RS 6 years ago committed by Stephen Gold
parent 637162e484
commit 7363662f21
  1. 25
      jme3-core/src/main/java/com/jme3/math/Quaternion.java
  2. 19
      jme3-core/src/main/java/com/jme3/math/Vector2f.java
  3. 22
      jme3-core/src/main/java/com/jme3/math/Vector3f.java
  4. 25
      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
@ -1280,6 +1280,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;
}
/**
*
* <code>hashCode</code> returns the hash code value as an integer and is

@ -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
@ -694,6 +694,23 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
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;
}
/**
* <code>toString</code> returns the string representation of this vector
* object. The format of the string is such: com.jme.math.Vector2f

@ -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
@ -970,6 +970,26 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
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;
}
/**
* <code>hashCode</code> returns a unique code for this vector object based
* on its values. If two vectors are logically equivalent, they will return

@ -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
@ -875,6 +875,29 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
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;
}
/**
* <code>hashCode</code> returns a unique code for this vector object based
* on its values. If two vectors are logically equivalent, they will return

Loading…
Cancel
Save