File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,12 @@ import { Loop } from '../s2/Loop'
99export const marshal = ( loop : Loop , ordinal : number ) : geojson . Position [ ] => {
1010 const ring = loop . vertices . map ( position . marshal )
1111 if ( ordinal > 0 ) ring . reverse ( ) // outer ring remains CCW, inner rings become CW
12- ring . push ( ring [ 0 ] ) // add matching start/end points
12+ if ( ring . length ) ring . push ( ring [ 0 ] ) // add matching start/end points
1313 return ring
1414}
1515
1616/**
17- * Constructs an s2 Loop given a geojson Polygon ring & ordinal .
17+ * Constructs an s2 Loop given a geojson Polygon ring.
1818 * @category Constructors
1919 *
2020 * Handles differences between GeoJSON and S2:
@@ -36,7 +36,8 @@ export const unmarshal = (ring: geojson.Position[]): Loop => {
3636 // Loops are not allowed to have duplicate vertices (whether adjacent or not)
3737 if ( containsDuplicateVertices ( ring ) ) {
3838 // adjacent duplicates are fixable
39- ring = removeAdjacentDuplicateVertices ( ring )
39+ ring = removeAdjacentDuplicateVertices ( ring , 0 )
40+ if ( ring . length < 3 ) return new Loop ( [ ] )
4041
4142 // non-adjacent duplicates are not fixable
4243 if ( containsDuplicateVertices ( ring ) ) return new Loop ( [ ] )
You can’t perform that action at this time.
0 commit comments