locationtech / proj4j

Java port of the Proj.4 library for coordinate reprojection
Other
181 stars 71 forks source link

Datum.isEqual maybe have a bug #110

Open Accelerator-Li opened 3 months ago

Accelerator-Li commented 3 months ago
    public boolean isEqual(Datum datum) {
        // false if tranforms are not equal
        if (getTransformType() != datum.getTransformType()) {
            return false;
        }
        // false if ellipsoids are not (approximately) equal
        if (ellipsoid.getEquatorRadius() != ellipsoid.getEquatorRadius()) { // <- maybe have a bug here
            if (Math.abs(ellipsoid.getEccentricitySquared()
                    - datum.ellipsoid.getEccentricitySquared()) > ELLIPSOID_E2_TOLERANCE)
                return false;
        }

        // false if transform parameters are not identical
        if (getTransformType() == TYPE_3PARAM || getTransformType() == TYPE_7PARAM) {
            for (int i = 0; i < transform.length; i++) {
                if (transform[i] != datum.transform[i])
                    return false;
            }
            return true;
        } else if (getTransformType() == TYPE_GRIDSHIFT) {
            return grids.equals(datum.grids);
        }
        return true; // datums are equal

    }

ellipsoid.getEquatorRadius() compare with itself, the condition is always false. the condition should be

ellipsoid.getEquatorRadius() != datum.ellipsoid.getEquatorRadius()