use of org.opensearch.geometry.utils.WellKnownText 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.WellKnownText in project OpenSearch by opensearch-project.
the class GeometryValidatorTests method testOneValidator.
public void testOneValidator() throws Exception {
WellKnownText parser = new WellKnownText(true, new OneValidator());
parser.fromWKT("POINT (0 1)");
parser.fromWKT("POINT (0 1 0.5)");
IllegalArgumentException ex;
ex = expectThrows(IllegalArgumentException.class, () -> parser.fromWKT("CIRCLE (1 2 3)"));
assertEquals("invalid latitude 2.0; must be between -1.0 and 1.0", ex.getMessage());
ex = expectThrows(IllegalArgumentException.class, () -> parser.fromWKT("POINT (2 1)"));
assertEquals("invalid longitude 2.0; must be between -1.0 and 1.0", ex.getMessage());
ex = expectThrows(IllegalArgumentException.class, () -> parser.fromWKT("LINESTRING (1 -1 0, 0 0 2)"));
assertEquals("invalid altitude 2.0; must be between -1.0 and 1.0", ex.getMessage());
ex = expectThrows(IllegalArgumentException.class, () -> parser.fromWKT("POLYGON ((0.3 0.1, 0.4 0.2, 5 0.3, 0.3 0.1))"));
assertEquals("invalid longitude 5.0; must be between -1.0 and 1.0", ex.getMessage());
ex = expectThrows(IllegalArgumentException.class, () -> parser.fromWKT("POLYGON ((0.3 0.1, 0.4 0.2, 0.5 0.3, 0.3 0.1), (0.5 1.5, 2.5 1.5, 2.0 1.0))"));
assertEquals("invalid latitude 1.5; must be between -1.0 and 1.0", ex.getMessage());
ex = expectThrows(IllegalArgumentException.class, () -> parser.fromWKT("MULTIPOINT (0 1, -2 1)"));
assertEquals("invalid longitude -2.0; must be between -1.0 and 1.0", ex.getMessage());
}
use of org.opensearch.geometry.utils.WellKnownText in project OpenSearch by opensearch-project.
the class GeometryValidatorTests method testNoopValidator.
public void testNoopValidator() throws Exception {
WellKnownText parser = new WellKnownText(true, new NoopValidator());
parser.fromWKT("CIRCLE (10000 20000 30000)");
parser.fromWKT("POINT (10000 20000)");
parser.fromWKT("LINESTRING (10000 20000, 0 0)");
parser.fromWKT("POLYGON ((300 100, 400 200, 500 300, 300 100), (50 150, 250 150, 200 100))");
parser.fromWKT("MULTIPOINT (10000 20000, 20000 30000)");
}
use of org.opensearch.geometry.utils.WellKnownText 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.WellKnownText 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)"));
}
Aggregations