-
Notifications
You must be signed in to change notification settings - Fork 87
[no squash] Make equals method symmetric #267
Conversation
\return True if the two vector are (almost) equal, else false. */ | ||
bool equals(const vector2d<T>& other, const T tolerance = (T)ROUNDING_ERROR_f32 ) const |
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.
Not a good default. Fortunately, this parameter is not used.
The changes look good and I'm convinced they should work but this still fails my test code: diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp
--- a/source/Irrlicht/COBJMeshFileLoader.cpp
+++ b/source/Irrlicht/COBJMeshFileLoader.cpp
@@ -2,6 +2,8 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
+#undef NDEBUG
+#include <cassert>
#include "COBJMeshFileLoader.h"
#include "IMeshManipulator.h"
#include "IVideoDriver.h"
@@ -241,6 +243,28 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
currMtl->RecalculateNormals=true;
}
+ const auto pv = [] (const video::S3DVertex &v) {
+ printf("P = { %a , %a , %a }\n", v.Pos.X, v.Pos.Y, v.Pos.Z);
+ printf("N = { %a , %a , %a }\n", v.Normal.X, v.Normal.Y, v.Normal.Z);
+ printf("C = %#08x\n", v.Color.color);
+ printf("T = { %a , %a }\n", v.TCoords.X, v.TCoords.Y);
+ };
+ for (auto &it : currMtl->VertMap) {
+ if (it.first == v) {
+ assert(!(it.first < v));
+ assert(!(v < it.first));
+ } if (it.first < v) {
+ assert(!(v < it.first));
+ } else {
+ if (!(v < it.first)) {
+ pv(v);
+ puts("==");
+ pv(it.first);
+ assert(false);
+ }
+ }
+ }
+
int vertLocation;
auto n = currMtl->VertMap.find(v);
if (n != currMtl->VertMap.end()) with
|
Thinking further, isn't the problem that e.g. with whole numbers, tolerance of 1: However if you look at the relation requirements we have a fundamental problem. It's impossible to make transitivity work with fuzzy comparisons. e.g. Basically |
On numbers, both are strict (that’s why
Good point.
That’s not transitivity. It does break transitivity of equality though (defined as |
Well, yes, we need to make comparison operators transitive as it's required for std::map. However, it would require removing approximate comparisons. It would be a more dangerous change because it's hard to say which code may rely on them. |
Although, I took a quick look at where comparison operators are used in the code, and looks like it needs strict comparisons everywhere and not approximate ones. |
oops lol, was that the reason it failed all the time? |
No, it also failed for valid reasons like |
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.
Looks good to me but I thought COBJMeshFileLoader
depended on this to merge vertices properly?
I don't see why it would, for sane models at least. Wouldn't any sane write the exact same coordinates for the exact same vertex? |
I couldn't find any .obj file where it could be a problem. There are very few files where different vertices are approximately equal in the first place. But even in those files, vertices don't need to be merged. |
Fix minetest/minetest#14132
See minetest/minetest#14132 (comment)
This fix is better as it also removes some nonsense.