This is about a Grasshopper development actually but it relates to Rhino’s Curve. I am looking for a way to compare lots of Curve objects efficiently.
For example, I have a custom component which has some curves as an input. The next time it runs, I want to compare the new inputs with the previous ones to check if there was any modifications.
With GeometryEquals I get the correct result but it is too slow. I also tried with GetHashCode on the Curves but I observed some collisions. Is there another way with comparable speed to hashing but precise accuracy?
The documentation reads: “This CRC can be used as a quick way to see if two objects are not identical.”.
If it can be used to check if two objects are not identical, I assume it can be used to also check for the reverse? This is important because the code will be something like this:
List<uint> storedCRCs; // store CRCs from previous solution here
bool checkForModifications(List<Curve> newCurves) {
for (int i = 0; i < newCurves.Count; i++) {
uint curveCRC = newCurves[i].DataCRC(0);
if (!storedCRCS.Contains(curveCRC)) return true;
}
return false;
}
Edit: I am in essence asking if the CRC result is guaranteed to be the same if an object has not changed. In that case, the above code can be made much more efficient with the use of HashSet<uint> and HashSet.SetEquals.