use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.
the class CircleTests method testInitValidation.
public void testInitValidation() {
GeometryValidator validator = new GeographyValidator(true);
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(20, 10, -1)));
assertEquals("Circle radius [-1.0] cannot be negative", ex.getMessage());
ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(20, 100, 1)));
assertEquals("invalid latitude 100.0; must be between -90.0 and 90.0", ex.getMessage());
ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(200, 10, 1)));
assertEquals("invalid longitude 200.0; must be between -180.0 and 180.0", ex.getMessage());
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(new Circle(200, 10, 1, 20)));
assertEquals("found Z value [1.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
new StandardValidator(true).validate(new Circle(200, 10, 1, 20));
}
use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.
the class CircleTests method testBasicSerialization.
public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("CIRCLE (20.0 10.0 15.0)", wkt.toWKT(new Circle(20, 10, 15)));
assertEquals(new Circle(20, 10, 15), wkt.fromWKT("circle (20.0 10.0 15.0)"));
assertEquals("CIRCLE (20.0 10.0 15.0 25.0)", wkt.toWKT(new Circle(20, 10, 25, 15)));
assertEquals(new Circle(20, 10, 25, 15), wkt.fromWKT("circle (20.0 10.0 15.0 25.0)"));
assertEquals("CIRCLE EMPTY", wkt.toWKT(Circle.EMPTY));
assertEquals(Circle.EMPTY, wkt.fromWKT("CIRCLE EMPTY)"));
}
use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.
the class MultiPolygonTests method testBasicSerialization.
public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("MULTIPOLYGON (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))", wkt.toWKT(new MultiPolygon(Collections.singletonList(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }))))));
assertEquals(new MultiPolygon(Collections.singletonList(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 })))), wkt.fromWKT("MULTIPOLYGON (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))"));
assertEquals("MULTIPOLYGON EMPTY", wkt.toWKT(MultiPolygon.EMPTY));
assertEquals(MultiPolygon.EMPTY, wkt.fromWKT("MULTIPOLYGON EMPTY)"));
}
use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.
the class PolygonTests method testBasicSerialization.
public void testBasicSerialization() throws IOException, ParseException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
assertEquals("POLYGON ((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0))", wkt.toWKT(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }))));
assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 })), wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3, 3 1))"));
assertEquals("POLYGON ((3.0 1.0 5.0, 4.0 2.0 4.0, 5.0 3.0 3.0, 3.0 1.0 5.0))", wkt.toWKT(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }, new double[] { 5, 4, 3, 5 }))));
assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }, new double[] { 5, 4, 3, 5 })), wkt.fromWKT("POLYGON ((3 1 5, 4 2 4, 5 3 3, 3 1 5))"));
// Auto closing in coerce mode
assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 })), wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3))"));
assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }, new double[] { 5, 4, 3, 5 })), wkt.fromWKT("POLYGON ((3 1 5, 4 2 4, 5 3 3))"));
assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }), Collections.singletonList(new LinearRing(new double[] { 0.5, 2.5, 2.0, 0.5 }, new double[] { 1.5, 1.5, 1.0, 1.5 }))), wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3, 3 1), (0.5 1.5, 2.5 1.5, 2.0 1.0))"));
assertEquals("POLYGON EMPTY", wkt.toWKT(Polygon.EMPTY));
assertEquals(Polygon.EMPTY, wkt.fromWKT("POLYGON EMPTY)"));
}
use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.
the class BaseGeometryTestCase method copyInstance.
@SuppressWarnings("unchecked")
@Override
protected T copyInstance(T instance, Version version) throws IOException {
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
String text = wkt.toWKT(instance);
try {
return (T) wkt.fromWKT(text);
} catch (ParseException e) {
throw new OpenSearchException(e);
}
}
Aggregations