I am having an issue that I did not realize before that Rhino has a point tolerance. It concluded that points;
-5.26930645920454,6.6957560903893,0 and
-5.26930645920482,6.6957560903894,0
are not the same. The first coordinate came from a CurveCurveIntersection and the second came from the end point of the curve. Basically I try to compare the end of the curve (that made the instersection with the curve) and the intersection. Is it possible that I got this result?
Also keep in mind that intersection operations for curves are also an approximation. (Find an intersection point with less tolerance than x)
Therefore: comparing two points are exactly the same (==) will almost never work. You should check if the distance between these two points is less than the document tolerance to conclude if they are the same point.
You almost never want to write code like the following:
double x;
double y;
...
if (x == y)
{
...
}
Most floating point operations involve at least a tiny loss of precision and so even if two numbers are equal for all practical purposes, they may not be exactly equal down to the last bit, and so the equality test is likely to fail.
For example, the following code snippet prints -1.77635683940025E-15 . Although in theory, squaring should undo a square root, the round-trip operation is slightly inaccurate.
var x = 10.0;
var y = System.Math.Sqrt(x);
y *= y;
if (x == y)
RhinoApp.WriteLine("Square root is exact");
else
RhinoApp.WriteLine($"{{0}}", x-y);
In most cases, the equality test above should be written as something like the following:
Here tolerance is some threshold that defines what is “close enough” for equality. This begs the question of how close is close enough. This cannot be answered in the abstract; you have to know something about your particular problem to know how close is close enough in your context.