From 14ab35e323771e83a7e338bbae5f8d2e4bdf9107 Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Thu, 9 Jul 2020 08:42:07 +0200 Subject: [PATCH] Fix numerical error in CentroidCalculatorTests#testPolygonAsPoint (#59012) (#59272) --- .../spatial/index/fielddata/CentroidCalculatorTests.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculatorTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculatorTests.java index 8f22c48e733..bb5f7f83041 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculatorTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculatorTests.java @@ -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)); }