-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Tangent W calculation #938
Conversation
W Tangent calculation was impacted by floating point rounding error and generate inverted vector randomly
} | ||
|
||
return w; | ||
float nx = Math.Abs(normal.X) <= Tools.Epsilon ? 0 : normal.X; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an override for Tools.IsAlmostEqualTo
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well technically this is
float nx = Tools.IsAlmostEqualTo(normal.X,Tools.Epsilon)? 0 : normal.X;
so i do not know how to name this function :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, no worries. I just like using helper functions for math, so they're reusable and documented via code.
A header like:
public static bool IsAlmostEqualTo(this float current, float other, float epsilon)
{
return Math.Abs(current - other) < epsilon
}
Should let us use it like
float nx = current.isAlmostEqualTo(0, Tools.Epsilon);
Just to minimize the amount of wild math we're using
W Tangent calculation was impacted by floating point rounding error and generate inverted vector randomly. Fix #936