use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class DistanceTest method should_not_contain_polygon.
@Test
public void should_not_contain_polygon() {
Polygon polygon = Polygon.fromPoints(Point.fromCoordinates(3, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 4), Point.fromCoordinates(10, 4));
// final point falls outside of distance at x axis.
assertThat(distance.contains(polygon)).isFalse();
}
use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class DistanceTest method should_contain_polygon.
@Test
public void should_contain_polygon() {
Polygon polygon = Polygon.fromPoints(Point.fromCoordinates(3, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 4), Point.fromCoordinates(4, 4));
assertThat(distance.contains(polygon)).isTrue();
}
use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class GeoTest method should_build_polygon_from_coordinates.
@Test
public void should_build_polygon_from_coordinates() {
Polygon polygon = Geo.polygon(1, 2, 3, 4, 5, 6, 7, 8);
assertThat(polygon.getExteriorRing()).hasSize(4).contains(Point.fromCoordinates(1, 2)).contains(Point.fromCoordinates(3, 4)).contains(Point.fromCoordinates(5, 6)).contains(Point.fromCoordinates(7, 8));
assertThat(polygon.getInteriorRings()).isEmpty();
}
use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class DefaultPolygonTest method should_expose_rings.
@Test
public void should_expose_rings() {
assertThat(polygon.getExteriorRing()).containsOnly(Point.fromCoordinates(30, 10), Point.fromCoordinates(10, 20), Point.fromCoordinates(20, 40), Point.fromCoordinates(40, 40));
assertThat(polygon.getInteriorRings().isEmpty()).isTrue();
Polygon fromWkt = Polygon.fromWellKnownText(wkt);
assertThat(fromWkt.getExteriorRing()).containsOnly(Point.fromCoordinates(30, 10), Point.fromCoordinates(10, 20), Point.fromCoordinates(20, 40), Point.fromCoordinates(40, 40));
assertThat(fromWkt.getInteriorRings().isEmpty()).isTrue();
Polygon complex = Polygon.builder().addRing(Point.fromCoordinates(0, 0), Point.fromCoordinates(0, 3), Point.fromCoordinates(5, 3), Point.fromCoordinates(5, 0)).addRing(Point.fromCoordinates(1, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 2), Point.fromCoordinates(2, 1)).addRing(Point.fromCoordinates(3, 1), Point.fromCoordinates(3, 2), Point.fromCoordinates(4, 2), Point.fromCoordinates(4, 1)).build();
assertThat(complex.getExteriorRing()).containsOnly(Point.fromCoordinates(0, 0), Point.fromCoordinates(0, 3), Point.fromCoordinates(5, 3), Point.fromCoordinates(5, 0));
assertThat(complex.getInteriorRings()).hasSize(2);
assertThat(complex.getInteriorRings().get(0)).containsOnly(Point.fromCoordinates(1, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 2), Point.fromCoordinates(2, 1));
assertThat(complex.getInteriorRings().get(1)).containsOnly(Point.fromCoordinates(3, 1), Point.fromCoordinates(3, 2), Point.fromCoordinates(4, 2), Point.fromCoordinates(4, 1));
Polygon complexFromWkt = Polygon.fromWellKnownText("POLYGON ((0 0, 5 0, 5 3, 0 3, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1), (3 1, 3 2, 4 2, 4 1, 3 1))");
assertThat(complexFromWkt.getExteriorRing()).containsOnly(Point.fromCoordinates(0, 0), Point.fromCoordinates(0, 3), Point.fromCoordinates(5, 3), Point.fromCoordinates(5, 0));
assertThat(complexFromWkt.getInteriorRings()).hasSize(2);
assertThat(complexFromWkt.getInteriorRings().get(0)).containsOnly(Point.fromCoordinates(1, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 2), Point.fromCoordinates(2, 1));
assertThat(complexFromWkt.getInteriorRings().get(1)).containsOnly(Point.fromCoordinates(3, 1), Point.fromCoordinates(3, 2), Point.fromCoordinates(4, 2), Point.fromCoordinates(4, 1));
}
use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class DefaultPolygonTest method should_accept_empty_shape.
@Test
public void should_accept_empty_shape() throws Exception {
Polygon polygon = Polygon.fromWellKnownText("POLYGON EMPTY");
assertThat(polygon.getExteriorRing()).isEmpty();
assertThat(((DefaultPolygon) polygon).getOgcGeometry().isEmpty()).isTrue();
}
Aggregations