question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Questionable vector equality?

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
antoineclacommented, Sep 24, 2017

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:

transform = new ModelMatrix();
transform.Translate(translation);
transform.Rotate(q);
shaderProgram.SetUniform(ctx, name, transform);
0reactions
luca-piccionicommented, Sep 23, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found