@@ -22,7 +22,7 @@ class ClipTest {
2222 void testLoadGeoJSON () {
2323 Path cwd = Path .of ("" ).toAbsolutePath ();
2424 Path pathFromRoot = Path .of ("tiles" , "src" , "test" , "resources" , "clip.geojson" );
25- var clip = Clip .fromGeoJSONFile (stats , 0 , 0 , false , cwd .resolveSibling (pathFromRoot ));
25+ var clip = Clip .fromGeoJSONFile (stats , 0 , 0 , false , Clip . DEFAULT_BUFFER , cwd .resolveSibling (pathFromRoot ));
2626 assertNotNull (clip );
2727 }
2828
@@ -32,7 +32,7 @@ void testLoadNonJSON() {
3232 Path pathFromRoot = Path .of ("tiles" , "src" , "test" , "resources" , "empty.geojson" );
3333 Path path = cwd .resolveSibling (pathFromRoot );
3434 assertThrows (FileFormatException .class , () -> {
35- Clip .fromGeoJSONFile (stats , 0 , 0 , false , path );
35+ Clip .fromGeoJSONFile (stats , 0 , 0 , false , Clip . DEFAULT_BUFFER , path );
3636 });
3737 }
3838
@@ -46,7 +46,8 @@ void testClipLine() throws GeometryException {
4646 ));
4747
4848 // a rectangle that is 50% of the earths width, centered at null island.
49- var n = new Clip (stats , 0 , 0 , false , newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
49+ var n = new Clip (stats , 0 , 0 , false , Clip .DEFAULT_BUFFER ,
50+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
5051 var clipped = n .postProcessTile (TileCoord .ofXYZ (0 , 0 , 0 ), Map .of ("layer" , unclipped ));
5152
5253 assertEquals (1 , clipped .size ());
@@ -64,7 +65,8 @@ void testClipLineMulti() throws GeometryException {
6465 ));
6566
6667 // a rectangle that is 50% of the earths width, centered at null island.
67- var n = new Clip (stats , 0 , 0 , false , newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
68+ var n = new Clip (stats , 0 , 0 , false , Clip .DEFAULT_BUFFER ,
69+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
6870 var clipped = n .postProcessTile (TileCoord .ofXYZ (0 , 0 , 0 ), Map .of ("layer" , unclipped ));
6971
7072 assertEquals (1 , clipped .size ());
@@ -82,7 +84,8 @@ void testClipPolygon() throws GeometryException {
8284 ));
8385
8486 // a rectangle that is 50% of the earths width, centered at null island.
85- var n = new Clip (stats , 0 , 0 , false , newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
87+ var n = new Clip (stats , 0 , 0 , false , Clip .DEFAULT_BUFFER ,
88+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
8689 var clipped = n .postProcessTile (TileCoord .ofXYZ (0 , 0 , 0 ), Map .of ("layer" , unclipped ));
8790
8891 assertEquals (1 , clipped .size ());
@@ -99,7 +102,8 @@ void testClipBelowMinZoom() throws GeometryException {
99102 Map .of ("foo" , "bar" )
100103 ));
101104
102- var n = new Clip (stats , 1 , 1 , false , newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
105+ var n = new Clip (stats , 1 , 1 , false , Clip .DEFAULT_BUFFER ,
106+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
103107 var clipped = n .postProcessTile (TileCoord .ofXYZ (0 , 0 , 0 ), Map .of ("layer" , unclipped ));
104108 assertEquals (0 , clipped .size ());
105109 }
@@ -112,7 +116,8 @@ void testClipWhollyOutside() throws GeometryException {
112116 Map .of ("foo" , "bar" )
113117 ));
114118
115- var n = new Clip (stats , 0 , 0 , false , newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
119+ var n = new Clip (stats , 0 , 0 , false , Clip .DEFAULT_BUFFER ,
120+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
116121 var clipped = n .postProcessTile (TileCoord .ofXYZ (0 , 0 , 0 ), Map .of ("layer" , unclipped ));
117122 assertEquals (0 , clipped .size ());
118123 }
@@ -125,7 +130,8 @@ void testClipInInterior() throws GeometryException {
125130 Map .of ("foo" , "bar" )
126131 ));
127132
128- var n = new Clip (stats , 0 , 3 , false , newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
133+ var n = new Clip (stats , 0 , 3 , false , Clip .DEFAULT_BUFFER ,
134+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
129135 var clipped = n .postProcessTile (TileCoord .ofXYZ (3 , 3 , 3 ), Map .of ("layer" , unclipped ));
130136 assertEquals (1 , clipped .size ());
131137 assertEquals (1 , clipped .get ("layer" ).size ());
@@ -140,11 +146,46 @@ void testClipLineBuffer() throws GeometryException {
140146 ));
141147
142148 // a rectangle that is 50% of the earths width, centered at null island.
143- var n = new Clip (stats , 0 , 0 , true , newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
149+ var n = new Clip (stats , 0 , 0 , true , Clip .DEFAULT_BUFFER ,
150+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
144151 var clipped = n .postProcessTile (TileCoord .ofXYZ (0 , 0 , 0 ), Map .of ("layer" , unclipped ));
145152
146153 assertEquals (1 , clipped .size ());
147154 assertEquals (1 , clipped .get ("layer" ).size ());
148155 assertEquals (newLineString (62 , 128 , 194 , 128 ), clipped .get ("layer" ).getFirst ().geometry ().decode ());
149156 }
157+
158+ @ Test
159+ void testClipLineBufferZero () throws GeometryException {
160+ List <VectorTile .Feature > unclipped = new ArrayList <>();
161+ unclipped .add (new VectorTile .Feature ("layer" , 1 ,
162+ VectorTile .encodeGeometry (newLineString (0 , 128 , 256 , 128 )),
163+ Map .of ("foo" , "bar" )
164+ ));
165+
166+ var n = new Clip (stats , 0 , 0 , true , 0 ,
167+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
168+ var clipped = n .postProcessTile (TileCoord .ofXYZ (0 , 0 , 0 ), Map .of ("layer" , unclipped ));
169+
170+ assertEquals (1 , clipped .size ());
171+ assertEquals (1 , clipped .get ("layer" ).size ());
172+ assertEquals (newLineString (64 , 128 , 192 , 128 ), clipped .get ("layer" ).getFirst ().geometry ().decode ());
173+ }
174+
175+ @ Test
176+ void testClipLineBufferLargerThanDefault () throws GeometryException {
177+ List <VectorTile .Feature > unclipped = new ArrayList <>();
178+ unclipped .add (new VectorTile .Feature ("layer" , 1 ,
179+ VectorTile .encodeGeometry (newLineString (0 , 128 , 256 , 128 )),
180+ Map .of ("foo" , "bar" )
181+ ));
182+
183+ var n = new Clip (stats , 0 , 0 , true , 8.0 ,
184+ newPolygon (0.25 , 0.25 , 0.75 , 0.25 , 0.75 , 0.75 , 0.25 , 0.75 , 0.25 , 0.25 ));
185+ var clipped = n .postProcessTile (TileCoord .ofXYZ (0 , 0 , 0 ), Map .of ("layer" , unclipped ));
186+
187+ assertEquals (1 , clipped .size ());
188+ assertEquals (1 , clipped .get ("layer" ).size ());
189+ assertEquals (newLineString (60 , 128 , 196 , 128 ), clipped .get ("layer" ).getFirst ().geometry ().decode ());
190+ }
150191}
0 commit comments