Fix numerical error in CentroidCalculatorTests#testPolygonAsPoint (#59012) (#59272)

This commit is contained in:
Ignacio Vera 2020-07-09 08:42:07 +02:00 committed by GitHub
parent 04a531dcfa
commit 14ab35e323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -251,14 +251,16 @@ public class CentroidCalculatorTests extends ESTestCase {
assertThat(calculator.getDimensionalShapeType(), equalTo(LINE));
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/58245")
public void testPolygonAsPoint() {
Point point = GeometryTestUtils.randomPoint(false);
Polygon polygon = new Polygon(new LinearRing(new double[] { point.getX(), point.getX(), point.getX(), point.getX() },
new double[] { point.getY(), point.getY(), point.getY(), point.getY() }));
CentroidCalculator calculator = new CentroidCalculator(polygon);
assertThat(calculator.getX(), equalTo(GeoUtils.normalizeLon(point.getX())));
assertThat(calculator.getY(), equalTo(GeoUtils.normalizeLat(point.getY())));
double normLon = GeoUtils.normalizeLon(point.getX());
double normLat = GeoUtils.normalizeLat(point.getY());
// make calculation to account for floating-point arithmetic
assertThat(calculator.getX(), equalTo((3 * normLon) / 3));
assertThat(calculator.getY(), equalTo((3 * normLat) / 3));
assertThat(calculator.sumWeight(), equalTo(3.0));
assertThat(calculator.getDimensionalShapeType(), equalTo(POINT));
}