Questionable vector equality?
See original GitHub issueThe following is the Equals method of Vertex3f:
/// <summary>
/// Indicates whether the this IVertex3 is equal to another IVertex3.
/// </summary>
/// <param name="other">
/// An IVertex3 to compare with this object.
/// </param>
/// <returns>
/// It returns true if the this IVertex3 is equal to <paramref name="other"/>; otherwise, false.
/// </returns>
public bool Equals(IVertex3 other)
{
const float Epsilon = 1e-6f;
if (ReferenceEquals(null, other))
return false;
if (Math.Abs(X - other.X) >= Epsilon)
return (false);
if (Math.Abs(Y - other.Y) >= Epsilon)
return (false);
if (Math.Abs(Z - other.Z) >= Epsilon)
return (false);
return (true);
}
I do not think that using an absolute Epsilon is the right approach in Equals(). This can lead to strange behaviors. Consider the following code:
Vertex3f v1 = new Vertex3f(1e-7f);
Vertex3f v2 = new Vertex3f(1e-9f);
bool equal = (v1 == v2); // = true
I suggest that you get rid of epsilon entirely and stick to true equality (especially since the summary of the method indicates that it is a true equality).
You could add an “approximately equal” method but in that case use a relative error. Something like:
Math.Abs(X - other.X) >= Epsilon*Math.Max(Math.Abs(X), Math.Abs(other.X))
Your OpenGL binding is very good. Many thanks for your impressive work!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
notation - Is there a symbol for potential equality?
The Unicode symbol ≟ can be used for questionable equality. Unicode Reference: https://www.compart.com/en/unicode/U+225F.
Read more >How to compare two vectors for equality? - c++
You can construct a std::unordered_set from each vector, then compare those, as shown in the code snippet below:
Read more >Which one of two definitions of vector equality are valid?
Which one of two definitions of vector equality are valid? Two vectors AB and CD are equivalent, (1) if components of vectors are...
Read more >Comparing vectors for equality. - by Taras Tsugrii
I've recently stumbled upon a code responsible for checking if user selected all days of the week, e.g. 1, 2, 3, 4, 5,...
Read more >9 Questionable Equality Stock Illustrations, Vectors & Clipart
9 questionable equality illustrations & vectors are available royalty-free. ... Sign ruble and question on scale. Isolated 3D illustration on white background.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
On a related subject, what do you think about adding static Translation, Rotation, etc? This would allow constructs such as:
shaderProgram.SetUniform(ctx, name, Matrix4x4.Rotation(q)*Matrix4x4.Translation(translation));
Instead of:
Vertex* tests requires some more testing, but the skeleton is done. Matrix classes are on the way, but surely they definitively need a review and a test set.