I'm having trouble with a comparison method being used in Java/Processing.
It says it violates its general contract, which I understand means it doesn't work on the relationships between the items consistently...
But I don't understand why. Since it just returns the angle, theta, based on the ratio of ycor to xcor (like sin to cos), shouldn't it sort them consistently based on their positions from 0 to 360 degrees?
public int compareTo(Orb other) {
double X = Math.atan2(ycor,xcor);
if (Math.atan2(other.ycor,other.xcor) > X) {
return -1;
}
if (Math.atan2(other.ycor,other.xcor) == X) {
return 0;
}
return 1;
}
Any help is very appreciated, thanks!
The specific context is that the error occurs when a Collection.Sort() is run.