Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix precision issue in CI for cartesian centroids #104707

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,30 @@ private static Object valueMapper(CsvTestUtils.Type type, Object value) {
if (value == null) {
return "null";
}
if (type == CsvTestUtils.Type.GEO_POINT) {
// GeoPoint tests are failing in clustered integration tests because of tiny precision differences at very small scales
if (type == CsvTestUtils.Type.GEO_POINT || type == CsvTestUtils.Type.CARTESIAN_POINT) {
// Point tests are failing in clustered integration tests because of tiny precision differences at very small scales
if (value instanceof GeoPoint point) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we really get a GeoPoint here? I would expect only WKT can get to this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, older code would have reached this, but I don't think the current code ever does. I could clean this up in another PR.

return normalizedGeoPoint(point.getX(), point.getY());
}
if (value instanceof String wkt) {
try {
Geometry geometry = WellKnownText.fromWKT(GeometryValidator.NOOP, false, wkt);
if (geometry instanceof Point point) {
return normalizedGeoPoint(point.getX(), point.getY());
return normalizedPoint(type, point.getX(), point.getY());
}
} catch (Throwable ignored) {}
}
}
return value.toString();
}

private static String normalizedPoint(CsvTestUtils.Type type, double x, double y) {
if (type == CsvTestUtils.Type.GEO_POINT) {
return normalizedGeoPoint(x, y);
}
return String.format(Locale.ROOT, "POINT (%f %f)", (float) x, (float) y);
}

private static String normalizedGeoPoint(double x, double y) {
x = decodeLongitude(encodeLongitude(x));
y = decodeLatitude(encodeLatitude(y));
Expand Down