Skip to content

Commit

Permalink
Fix numerical error in CentroidCalculatorTests#testPolygonAsPoint (el…
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Jul 9, 2020
1 parent 09867ec commit a251bf3
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,16 @@ public void testPolygonWithEqualSizedHole() {
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));
}
Expand Down

0 comments on commit a251bf3

Please sign in to comment.