fix a potential division by zero

0.7-release
dahlia 2010-07-08 11:10:08 -07:00
parent f5d5898964
commit d06b75fe3b
1 changed files with 9 additions and 4 deletions

View File

@ -259,10 +259,15 @@ namespace OpenSim.Region.ScriptEngine.Shared
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