The following code says that
c1 == c2 and
c2 == c3, but
c1 != c3.
TOL = 0.11 class C: def __init__(self, x): self.x = x def __eq__(self, other): return abs(self.x - other.x) <= TOL c1 = C(1.1) c2 = C(1.2) c3 = C(1.3) print(c1 == c2) # True print(c2 == c3) # True print(c1 == c3) # False
For the same reason the shape in the middle in the image below could be equal to all the other shapes, while no other shape would be equal to all the others.
No matter how small or large the tolerance is, there will always be an angle for the top line of the shapes where the problem arises.
I need to find a reliable way to match the shapes so that when
c1 == c1 once,
c1 == c1 always. In the example above I can accept that either
c2 == c3 or
c2 != c3, but whatever is the case, it has to be (1) consistent during the execution and (2) consistent with other comparisons.
If I tighten the tolerance, then no shapes will ever be equal to other shapes, because of the small errors introduced by transformations.
If I loosen the tolerance, then all the shapes will be identical, which is not good.
Perhaps there is a comparison algorithm that remembers the first instance of each value ever compared, and creates a bucket for it? So that in my first example, if I compare c1 to c2 first then the reference value will be 1.1 and c2 will be different from c3, but if i compare c2 to c1 first then the reference value will be 1.2 and they all will be equal.
Is there a way to avoid this problem?