FastMath's sphericalToCartesian and related methods fix

While I was checking for something in that class I noticed those following methods don’t check if store is null or not (as other methods do in this and other classes).



This would fix the resulting NPE.



[patch]

This patch file was generated by NetBeans IDE

It uses platform neutral UTF-8 encoding and n newlines.

— Base (BASE)

+++ Locally Modified (Based On LOCAL)

@@ -815,6 +815,9 @@

*/

public static Vector3f sphericalToCartesian(Vector3f sphereCoords,

Vector3f store) {

  •    if (store == null) {<br />
    
  •        store = new Vector3f();<br />
    
  •    }<br />
    

store.y = sphereCoords.x * FastMath.sin(sphereCoords.z);

float a = sphereCoords.x * FastMath.cos(sphereCoords.z);

store.x = a * FastMath.cos(sphereCoords.y);

@@ -830,6 +833,9 @@

*/

public static Vector3f cartesianToSpherical(Vector3f cartCoords,

Vector3f store) {

  •    if (store == null) {<br />
    
  •        store = new Vector3f();<br />
    
  •    }<br />
    

float x = cartCoords.x;

if (x == 0) {

x = FastMath.FLT_EPSILON;

@@ -851,6 +857,9 @@

*/

public static Vector3f sphericalToCartesianZ(Vector3f sphereCoords,

Vector3f store) {

  •    if (store == null) {<br />
    
  •        store = new Vector3f();<br />
    
  •    }<br />
    

store.z = sphereCoords.x * FastMath.sin(sphereCoords.z);

float a = sphereCoords.x * FastMath.cos(sphereCoords.z);

store.x = a * FastMath.cos(sphereCoords.y);

@@ -866,6 +875,9 @@

*/

public static Vector3f cartesianZToSpherical(Vector3f cartCoords,

Vector3f store) {

  •    if (store == null) {<br />
    
  •        store = new Vector3f();<br />
    
  •    }<br />
    

float x = cartCoords.x;

if (x == 0) {

x = FastMath.FLT_EPSILON;

[/patch]

4 Likes

Go ahead and commit :wink:

Committed.

1 Like