fix a potential division by zero

0.6.9-post-fixes
dahlia 2010-07-08 10:14:02 -07:00
parent d743a221e8
commit 0116b80795
1 changed files with 11 additions and 6 deletions

View File

@ -262,7 +262,12 @@ namespace OpenSim.Region.ScriptEngine.Shared
public static Vector3 Norm(Vector3 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