mirror of
https://github.com/opensim/opensim.git
synced 2026-05-15 03:15:41 +08:00
fix a potential division by zero
This commit is contained in:
@@ -259,10 +259,15 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
||||
}
|
||||
|
||||
public static Vector3 Norm(Vector3 vector)
|
||||
{
|
||||
double mag = Mag(vector);
|
||||
return new Vector3(vector.x / mag, vector.y / mag, vector.z / mag);
|
||||
public static Vector3 Norm(Vector3 vector)
|
||||
{
|
||||
double mag = Mag(vector);
|
||||
if (mag > 0.0)
|
||||
{
|
||||
double invMag = 1.0 / mag;
|
||||
return vector * invMag;
|
||||
}
|
||||
return new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user