Closed CBenghi closed 4 years ago
Ignore my previous question, I now understand that the return value behavior was intended.
I've added xml comment to my repository as follows:
/// <summary>
/// Sets the lenght of the vector to 1 or 0.
///
/// If the vector's initial length is smaller than <see cref="epsilon"/> the vector is degenerate and
/// the resulting length is 0, otherwise 1
/// </summary>
/// <param name="epsilon">a value to determine the normalization behaviour threshold</param>
/// <returns>the original length of the vector, before normalization, if this was smaller than <see cref="epsilon"/> then zero is returned.</returns>
public double Normalize(double epsilon = MathUtil.Epsilon)
{
double length = Length;
if (length > epsilon)
{
double invLength = 1.0 / length;
x *= invLength;
y *= invLength;
z *= invLength;
return length;
}
else
{
x = y = z = 0;
return 0;
}
}
EDIT: The code in this comment had regressions, the new one in the reply below might be useful for the XML comment.
Hello @rms80,
I'm puzzled by the return value of
Vector3D.Normalize()
. You are returninglength
which only gets updated if the initial value is < 0.If this is not the intended behavior I'd change the code to:
Happy to post a PR if you are interested. Best, Claudio