From 76c0177c9d41dee623e350f8516f4c59352e1488 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Thu, 5 Mar 2026 17:48:32 -0800 Subject: [PATCH] Fix DD equals and compareTo --- .../main/java/org/locationtech/jts/math/DD.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/core/src/main/java/org/locationtech/jts/math/DD.java b/modules/core/src/main/java/org/locationtech/jts/math/DD.java index d38349f3e2..e4aa92bdf5 100644 --- a/modules/core/src/main/java/org/locationtech/jts/math/DD.java +++ b/modules/core/src/main/java/org/locationtech/jts/math/DD.java @@ -91,7 +91,7 @@ * */ public strictfp final class DD - implements Serializable, Comparable, Cloneable + implements Serializable, Comparable
, Cloneable { /** * The value nearest to the constant Pi. @@ -985,9 +985,12 @@ public boolean isPositive() * @param y a DoubleDouble value * @return true if this value = y */ - public boolean equals(DD y) + public boolean equals(Object o) { - return hi == y.hi && lo == y.lo; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DD dd = (DD) o; + return hi == dd.hi && lo == dd.lo; } /** @@ -1030,13 +1033,12 @@ public boolean le(DD y) /** * Compares two DoubleDouble objects numerically. * + * @param other a DD value to compare to * @return -1,0 or 1 depending on whether this value is less than, equal to * or greater than the value of o */ - public int compareTo(Object o) + public int compareTo(DD other) { - DD other = (DD) o; - if (hi < other.hi) return -1; if (hi > other.hi) return 1; if (lo < other.lo) return -1;