fix(astar): compareto using sign for better precision

This commit is contained in:
Paul Alnet 2024-05-03 15:09:28 +02:00
parent f77aea0371
commit df55fb1472

View file

@ -40,14 +40,8 @@ public class Label implements Comparable<Label> {
public int compareTo(Label other) { public int compareTo(Label other) {
final float difference = this.getTotalCost() - other.getTotalCost(); final float difference = this.getTotalCost() - other.getTotalCost();
final boolean equal = Math.abs(difference) < 1.0; return (int) Math.signum(difference);
if (equal) { // Note that doesn't address the requested condition regarding equality :
return 0; // "En cas d'égalité, on considèrera en premier le sommet ayant le plus petit coût estimé à la destination."
//TODO
}
// TODO ensure this works properly
// return (int)(this.pathCost - other.pathCost);
return this.pathCost - other.pathCost < 0 ? -1 : 1;
} }
} }