|
1 | 1 | package com.mapbox.turf; |
2 | 2 |
|
3 | | -import static org.junit.Assert.assertEquals; |
4 | | -import static org.junit.Assert.assertNotEquals; |
5 | | -import static org.junit.Assert.assertNotNull; |
6 | | -import static org.junit.Assert.assertTrue; |
7 | | - |
8 | | -import com.mapbox.geojson.Feature; |
9 | | -import com.mapbox.geojson.MultiLineString; |
10 | 3 | import com.mapbox.core.TestUtils; |
| 4 | +import com.mapbox.geojson.Feature; |
11 | 5 | import com.mapbox.geojson.FeatureCollection; |
12 | | -import com.mapbox.geojson.Polygon; |
| 6 | +import com.mapbox.geojson.Geometry; |
| 7 | +import com.mapbox.geojson.GeometryCollection; |
13 | 8 | import com.mapbox.geojson.LineString; |
| 9 | +import com.mapbox.geojson.MultiLineString; |
| 10 | +import com.mapbox.geojson.MultiPoint; |
14 | 11 | import com.mapbox.geojson.MultiPolygon; |
15 | 12 | import com.mapbox.geojson.Point; |
| 13 | +import com.mapbox.geojson.Polygon; |
16 | 14 |
|
17 | 15 | import org.junit.Assert; |
18 | 16 | import org.junit.Rule; |
|
23 | 21 | import java.util.ArrayList; |
24 | 22 | import java.util.List; |
25 | 23 |
|
| 24 | +import static org.junit.Assert.assertArrayEquals; |
| 25 | +import static org.junit.Assert.assertEquals; |
| 26 | +import static org.junit.Assert.assertNotEquals; |
| 27 | +import static org.junit.Assert.assertNotNull; |
| 28 | + |
26 | 29 | public class TurfMeasurementTest extends TestUtils { |
27 | 30 |
|
28 | 31 | private static final String LINE_DISTANCE_ROUTE_ONE = "turf-line-distance/route1.geojson"; |
29 | 32 | private static final String LINE_DISTANCE_ROUTE_TWO = "turf-line-distance/route2.geojson"; |
30 | 33 | private static final String LINE_DISTANCE_POLYGON = "turf-line-distance/polygon.geojson"; |
31 | 34 | private static final String TURF_ALONG_DC_LINE = "turf-along/dc-line.geojson"; |
32 | 35 | private static final String TURF_BBOX_POINT = "turf-bbox/point.geojson"; |
| 36 | + private static final String TURF_BBOX_MULTI_POINT = "turf-bbox/multipoint.geojson"; |
33 | 37 | private static final String TURF_BBOX_LINESTRING = "turf-bbox/linestring.geojson"; |
34 | 38 | private static final String TURF_BBOX_POLYGON = "turf-bbox/polygon.geojson"; |
35 | 39 | private static final String TURF_BBOX_MULTILINESTRING = "turf-bbox/multilinestring.geojson"; |
@@ -301,4 +305,40 @@ public void bboxFromMultiPolygon() throws IOException, TurfException { |
301 | 305 | assertEquals(103, bbox[2], DELTA); |
302 | 306 | assertEquals(3, bbox[3], DELTA); |
303 | 307 | } |
| 308 | + |
| 309 | + @Test |
| 310 | + public void bboxFromGeometry() throws IOException, TurfException { |
| 311 | + Geometry geometry = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON)); |
| 312 | + double[] bbox = TurfMeasurement.bbox(geometry); |
| 313 | + |
| 314 | + assertEquals(4, bbox.length); |
| 315 | + assertEquals(100, bbox[0], DELTA); |
| 316 | + assertEquals(0, bbox[1], DELTA); |
| 317 | + assertEquals(103, bbox[2], DELTA); |
| 318 | + assertEquals(3, bbox[3], DELTA); |
| 319 | + } |
| 320 | + |
| 321 | + @Test |
| 322 | + public void bboxFromGeometryCollection() throws IOException, TurfException { |
| 323 | + // Check that geometry collection and direct bbox are equal |
| 324 | + MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON)); |
| 325 | + assertArrayEquals(TurfMeasurement.bbox(multiPolygon), TurfMeasurement.bbox(GeometryCollection.fromGeometry(multiPolygon)), DELTA); |
| 326 | + |
| 327 | + // Check all geometry types |
| 328 | + List<Geometry> geometries = new ArrayList<>(); |
| 329 | + geometries.add(Feature.fromJson(loadJsonFixture(TURF_BBOX_POINT)).geometry()); |
| 330 | + geometries.add(MultiPoint.fromJson(loadJsonFixture(TURF_BBOX_MULTI_POINT))); |
| 331 | + geometries.add(LineString.fromJson(loadJsonFixture(TURF_BBOX_LINESTRING))); |
| 332 | + geometries.add(MultiLineString.fromJson(loadJsonFixture(TURF_BBOX_MULTILINESTRING))); |
| 333 | + geometries.add(Feature.fromJson(loadJsonFixture(TURF_BBOX_POLYGON)).geometry()); |
| 334 | + geometries.add(MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_MULTIPOLYGON))); |
| 335 | + geometries.add(GeometryCollection.fromGeometry(Point.fromLngLat(-1., -1.))); |
| 336 | + double[] bbox = TurfMeasurement.bbox(GeometryCollection.fromGeometries(geometries)); |
| 337 | + |
| 338 | + assertEquals(4, bbox.length); |
| 339 | + assertEquals(-1, bbox[0], DELTA); |
| 340 | + assertEquals(-10, bbox[1], DELTA); |
| 341 | + assertEquals(130, bbox[2], DELTA); |
| 342 | + assertEquals(4, bbox[3], DELTA); |
| 343 | + } |
304 | 344 | } |
0 commit comments