@@ -27,11 +27,23 @@ public class TurfConversionTest extends TestUtils {
2727 private static final String TURF_EXPLODE_MULTIPOLYGON = "turf-explode/multipolygon.geojson" ;
2828 private static final String TURF_EXPLODE_GEOMETRY_COLLECTION = "turf-explode/geometrycollection.geojson" ;
2929
30+ private static final String TURF_POLYGON_TO_LINE_PATH_IN = "turf-polygon-to-line/in/" ;
31+ private static final String TURF_POLYGON_TO_LINE_PATH_OUT = "turf-polygon-to-line/expected/" ;
32+
33+ private static final String TURF_POLYGON_TO_LINE_FILENAME_POLYGON = "polygon.geojson" ;
34+ private static final String TURF_POLYGON_TO_LINE_FILENAME_GEOMETRY_POLYGON = "geometry-polygon.geojson" ;
35+ private static final String TURF_POLYGON_TO_LINE_FILENAME_POLYGON_WITH_HOLE = "polygon-with-hole.geojson" ;
36+
37+ private static final String TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON = "multi-polygon.geojson" ;
38+ private static final String TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_OUTER_DOUGHNUT = "multi-polygon-outer-doughnut.geojson" ;
39+ private static final String TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_WITH_HOLES = "multi-polygon-with-holes.geojson" ;
40+
41+
3042 @ Rule
3143 public ExpectedException thrown = ExpectedException .none ();
3244
3345 @ Test
34- public void radiansToDistance () throws Exception {
46+ public void radiansToDistance () {
3547 assertEquals (
3648 1 , TurfConversion .radiansToLength (1 , TurfConstants .UNIT_RADIANS ), DELTA );
3749 assertEquals (
@@ -41,7 +53,7 @@ public void radiansToDistance() throws Exception {
4153 }
4254
4355 @ Test
44- public void distanceToRadians () throws Exception {
56+ public void distanceToRadians () {
4557 assertEquals (
4658 1 , TurfConversion .lengthToRadians (1 , TurfConstants .UNIT_RADIANS ), DELTA );
4759 assertEquals (
@@ -51,7 +63,7 @@ public void distanceToRadians() throws Exception {
5163 }
5264
5365 @ Test
54- public void distanceToDegrees () throws Exception {
66+ public void distanceToDegrees () {
5567 assertEquals (
5668 57.29577951308232 , TurfConversion .lengthToDegrees (1 , TurfConstants .UNIT_RADIANS ), DELTA );
5769 assertEquals (
@@ -79,25 +91,25 @@ public void convertDistance() throws TurfException {
7991 }
8092
8193 @ Test
82- public void explodePointSingleFeature () throws IOException , NullPointerException {
94+ public void explodePointSingleFeature () throws NullPointerException {
8395 Point point = Point .fromLngLat (102 , 0.5 );
8496 assertEquals (1 , TurfConversion .explode (Feature .fromGeometry (point )).features ().size ());
8597 }
8698
8799 @ Test
88- public void explodeMultiPointSingleFeature () throws IOException , NullPointerException {
100+ public void explodeMultiPointSingleFeature () throws NullPointerException {
89101 MultiPoint multiPoint = MultiPoint .fromJson (loadJsonFixture (TURF_EXPLODE_MULTI_POINT ));
90102 assertEquals (4 , TurfConversion .explode (Feature .fromGeometry (multiPoint )).features ().size ());
91103 }
92104
93105 @ Test
94- public void explodeLineStringSingleFeature () throws IOException , NullPointerException {
106+ public void explodeLineStringSingleFeature () throws NullPointerException {
95107 LineString lineString = LineString .fromJson (loadJsonFixture (TURF_EXPLODE_LINESTRING ));
96108 assertEquals (4 , TurfConversion .explode (Feature .fromGeometry (lineString )).features ().size ());
97109 }
98110
99111 @ Test
100- public void explodePolygonSingleFeature () throws IOException , NullPointerException {
112+ public void explodePolygonSingleFeature () throws NullPointerException {
101113 Polygon polygon = Polygon .fromLngLats (Arrays .asList (
102114 Arrays .asList (
103115 Point .fromLngLat (0 , 101 ),
@@ -108,29 +120,71 @@ public void explodePolygonSingleFeature() throws IOException, NullPointerExcepti
108120 }
109121
110122 @ Test
111- public void explodeMultiLineStringSingleFeature () throws IOException , NullPointerException {
123+ public void explodeMultiLineStringSingleFeature () throws NullPointerException {
112124 MultiLineString multiLineString = MultiLineString .fromJson (loadJsonFixture (TURF_EXPLODE_MULTILINESTRING ));
113125 assertEquals (4 , TurfConversion .explode (Feature .fromGeometry (multiLineString )).features ().size ());
114126 }
115127
116128 @ Test
117- public void explodeMultiPolygonSingleFeature () throws IOException , NullPointerException {
129+ public void explodeMultiPolygonSingleFeature () throws NullPointerException {
118130 MultiPolygon multiPolygon = MultiPolygon .fromJson (loadJsonFixture (TURF_EXPLODE_MULTIPOLYGON ));
119131 assertEquals (12 , TurfConversion .explode (Feature .fromGeometry (multiPolygon )).features ().size ());
120132 }
121133
122134 @ Test
123- public void explodeGeometryCollectionSingleFeature () throws IOException , NullPointerException {
135+ public void explodeGeometryCollectionSingleFeature () throws NullPointerException {
124136 GeometryCollection geometryCollection = GeometryCollection .fromJson (loadJsonFixture (TURF_EXPLODE_GEOMETRY_COLLECTION ));
125137 assertEquals (3 , TurfConversion .explode (Feature .fromGeometry (geometryCollection )).features ().size ());
126138 }
127139
128140 @ Test
129- public void explodeFeatureCollection () throws IOException , NullPointerException {
141+ public void explodeFeatureCollection () throws NullPointerException {
130142 FeatureCollection featureCollection = FeatureCollection .fromFeatures (new Feature [] {
131143 Feature .fromGeometry (MultiLineString .fromJson (loadJsonFixture (TURF_EXPLODE_MULTILINESTRING ))),
132144 Feature .fromGeometry (MultiPolygon .fromJson (loadJsonFixture (TURF_EXPLODE_MULTIPOLYGON )))
133145 });
134146 assertEquals (16 , TurfConversion .explode (featureCollection ).features ().size ());
135147 }
148+
149+ @ Test
150+ public void polygonToLine_GeometryPolygon () throws NullPointerException {
151+ Polygon polygon = Polygon .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_GEOMETRY_POLYGON ));
152+ Feature expected = Feature .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_GEOMETRY_POLYGON ));
153+ compareJson (expected .toJson (), TurfConversion .polygonToLine (polygon ).toJson ());
154+ }
155+
156+ @ Test
157+ public void polygonToLine_Polygon () throws NullPointerException {
158+ Feature polygon = Feature .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_POLYGON ));
159+ Feature expected = Feature .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_POLYGON ));
160+ compareJson (expected .toJson (), TurfConversion .polygonToLine (polygon ).toJson ());
161+ }
162+
163+ @ Test
164+ public void polygonToLine_PolygonWithHole () throws NullPointerException {
165+ Feature polygon = Feature .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_POLYGON_WITH_HOLE ));
166+ Feature expected = Feature .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_POLYGON_WITH_HOLE ));
167+ compareJson (expected .toJson (), TurfConversion .polygonToLine (polygon ).toJson ());
168+ }
169+
170+ @ Test
171+ public void polygonToLine_MultiPolygon () throws NullPointerException {
172+ Feature multiPolygon = Feature .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON ));
173+ FeatureCollection expected = FeatureCollection .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON ));
174+ compareJson (expected .toJson (), TurfConversion .multiPolygonToLine (multiPolygon ).toJson ());
175+ }
176+
177+ @ Test
178+ public void polygonToLine_MultiPolygonWithHoles () throws NullPointerException {
179+ Feature multiPolygon = Feature .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_WITH_HOLES ));
180+ FeatureCollection expected = FeatureCollection .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_WITH_HOLES ));
181+ compareJson (expected .toJson (), TurfConversion .multiPolygonToLine (multiPolygon ).toJson ());
182+ }
183+
184+ @ Test
185+ public void polygonToLine_MultiPolygonWithOuterDoughnut () throws NullPointerException {
186+ Feature multiPolygon = Feature .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_IN + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_OUTER_DOUGHNUT ));
187+ FeatureCollection expected = FeatureCollection .fromJson (loadJsonFixture (TURF_POLYGON_TO_LINE_PATH_OUT + TURF_POLYGON_TO_LINE_FILENAME_MULTIPOLYGON_OUTER_DOUGHNUT ));
188+ compareJson (expected .toJson (), TurfConversion .multiPolygonToLine (multiPolygon ).toJson ());
189+ }
136190}
0 commit comments