fix a potential division by zero
parent
d743a221e8
commit
0116b80795
|
@ -257,12 +257,17 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
public static double Mag(Vector3 v)
|
public static double Mag(Vector3 v)
|
||||||
{
|
{
|
||||||
return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 Norm(Vector3 vector)
|
public static Vector3 Norm(Vector3 vector)
|
||||||
{
|
{
|
||||||
double mag = Mag(vector);
|
double mag = Mag(vector);
|
||||||
return new Vector3(vector.x / mag, vector.y / mag, vector.z / mag);
|
if (mag > 0.0)
|
||||||
|
{
|
||||||
|
double invMag = 1.0 / mag;
|
||||||
|
return vector * invMag;
|
||||||
|
}
|
||||||
|
return new Vector3(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in New Issue