use of org.opensearch.common.geo.builders.PolygonBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testNewPolygon_coordinates.
public void testNewPolygon_coordinates() {
PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinates(new Coordinate(-45, 30), new Coordinate(45, 30), new Coordinate(45, -30), new Coordinate(-45, -30), new Coordinate(-45, 30)));
Polygon poly = pb.toPolygonS4J();
LineString exterior = poly.getExteriorRing();
assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
assertEquals(exterior.getCoordinateN(1), new Coordinate(45, 30));
assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
LinearRing polygon = pb.toPolygonGeometry().getPolygon();
assertEquals(polygon.getY(0), 30, 0d);
assertEquals(polygon.getX(0), -45, 0d);
assertEquals(polygon.getY(1), 30, 0d);
assertEquals(polygon.getX(1), 45, 0d);
assertEquals(polygon.getY(2), -30, 0d);
assertEquals(polygon.getX(2), 45, 0d);
assertEquals(polygon.getY(3), -30, 0d);
assertEquals(polygon.getX(3), -45, 0d);
}
use of org.opensearch.common.geo.builders.PolygonBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testNewPolygon.
public void testNewPolygon() {
PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinate(-45, 30).coordinate(45, 30).coordinate(45, -30).coordinate(-45, -30).coordinate(-45, 30));
Polygon poly = pb.toPolygonS4J();
LineString exterior = poly.getExteriorRing();
assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
assertEquals(exterior.getCoordinateN(1), new Coordinate(45, 30));
assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
LinearRing polygon = pb.toPolygonGeometry().getPolygon();
assertEquals(polygon.getY(0), 30, 0d);
assertEquals(polygon.getX(0), -45, 0d);
assertEquals(polygon.getY(1), 30, 0d);
assertEquals(polygon.getX(1), 45, 0d);
assertEquals(polygon.getY(2), -30, 0d);
assertEquals(polygon.getX(2), 45, 0d);
assertEquals(polygon.getY(3), -30, 0d);
assertEquals(polygon.getX(3), -45, 0d);
}
use of org.opensearch.common.geo.builders.PolygonBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testPolygon3D.
public void testPolygon3D() {
String expected = "{\n" + " \"type\" : \"polygon\",\n" + " \"orientation\" : \"right\",\n" + " \"coordinates\" : [\n" + " [\n" + " [\n" + " -45.0,\n" + " 30.0,\n" + " 100.0\n" + " ],\n" + " [\n" + " 45.0,\n" + " 30.0,\n" + " 75.0\n" + " ],\n" + " [\n" + " 45.0,\n" + " -30.0,\n" + " 77.0\n" + " ],\n" + " [\n" + " -45.0,\n" + " -30.0,\n" + " 101.0\n" + " ],\n" + " [\n" + " -45.0,\n" + " 30.0,\n" + " 110.0\n" + " ]\n" + " ]\n" + " ]\n" + "}";
PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinate(new Coordinate(-45, 30, 100)).coordinate(new Coordinate(45, 30, 75)).coordinate(new Coordinate(45, -30, 77)).coordinate(new Coordinate(-45, -30, 101)).coordinate(new Coordinate(-45, 30, 110)));
assertEquals(expected, pb.toString());
}
use of org.opensearch.common.geo.builders.PolygonBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testInvalidSelfCrossingPolygon.
public void testInvalidSelfCrossingPolygon() {
PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(0, 0).coordinate(0, 2).coordinate(1, 1.9).coordinate(0.5, 1.8).coordinate(1.5, 1.8).coordinate(1, 1.9).coordinate(2, 2).coordinate(2, 0).coordinate(0, 0));
Exception e = expectThrows(InvalidShapeException.class, () -> builder.close().buildS4J());
assertThat(e.getMessage(), containsString("Self-intersection at or near point ["));
assertThat(e.getMessage(), not(containsString("NaN")));
e = expectThrows(InvalidShapeException.class, () -> buildGeometry(builder.close()));
assertThat(e.getMessage(), containsString("Self-intersection at or near point ["));
assertThat(e.getMessage(), not(containsString("NaN")));
}
use of org.opensearch.common.geo.builders.PolygonBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testPolygonWrapping.
public void testPolygonWrapping() {
PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinate(-150.0, 65.0).coordinate(-250.0, 65.0).coordinate(-250.0, -65.0).coordinate(-150.0, -65.0).close());
assertMultiPolygon(pb.buildS4J(), true);
assertMultiPolygon(buildGeometry(pb), false);
}
Aggregations