Explorar o código

Quaternion: resolve issue #945 (length of argument isn't checked) (#1484)

Stephen Gold %!s(int64=4) %!d(string=hai) anos
pai
achega
b0d8e76068
Modificáronse 1 ficheiros con 12 adicións e 9 borrados
  1. 12 9
      jme3-core/src/main/java/com/jme3/math/Quaternion.java

+ 12 - 9
jme3-core/src/main/java/com/jme3/math/Quaternion.java

@@ -1023,18 +1023,21 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
     }
 
     /**
+     * <code>toAxes</code> determines the axes of the coordinate system
+     * described by this Quaternion.
      *
-     * <code>toAxes</code> takes in an array of three vectors. Each vector
-     * corresponds to an axis of the coordinate system defined by the quaternion
-     * rotation.
-     *
-     * @param axis the array of vectors to be filled.
+     * @param axes an array to store the results (not null, length=3, modified)
      */
-    public void toAxes(Vector3f axis[]) {
+    public void toAxes(Vector3f axes[]) {
+        if (axes.length != 3) {
+            throw new IllegalArgumentException(
+                    "Axes array must have three elements");
+        }
+
         Matrix3f tempMat = toRotationMatrix();
-        axis[0] = tempMat.getColumn(0, axis[0]);
-        axis[1] = tempMat.getColumn(1, axis[1]);
-        axis[2] = tempMat.getColumn(2, axis[2]);
+        axes[0] = tempMat.getColumn(0, axes[0]);
+        axes[1] = tempMat.getColumn(1, axes[1]);
+        axes[2] = tempMat.getColumn(2, axes[2]);
     }
 
     /**