src/util/PolygonSplitter.js
function (points) {
                var iMap = new HashMap();
                var newPoints = [];
                var intersections = [];
                var polygons = [];
                var iMaps = [];
                var poleIndex = -1;

                var pole = this.findIntersectionAndPole(points, newPoints, intersections, iMap);

                if (intersections.length === 0) {
                    polygons.push(newPoints);
                    iMaps.push(iMap);
                    return this.formatContourOutput(polygons, pole, poleIndex, iMaps);
                }

                if (intersections.length > 2) {
                    intersections.sort(function (a, b) {
                        return b.latitude - a.latitude;
                    });
                }

                if (pole !== Location.poles.NONE) {
                    newPoints = this.handleOnePole(newPoints, intersections, iMap, pole);
                    iMap = this.reindexIntersections(intersections, iMap, this.poleIndexOffset);
                }
                if (intersections.length === 0) {
                    polygons.push(newPoints);
                    iMaps.push(iMap);
                    poleIndex = 0;
                    return this.formatContourOutput(polygons, pole, poleIndex, iMaps);
                }

                this.linkIntersections(intersections, iMap);

                poleIndex = this.makePolygons(newPoints, intersections, iMap, polygons, iMaps);

                return this.formatContourOutput(polygons, pole, poleIndex, iMaps);
            }
function (points) {
                var iMap = new HashMap();
                var newPoints = [];
                var intersections = [];
                var polygons = [];
                var iMaps = [];
                var poleIndex = -1;

                var pole = this.findIntersectionAndPole(points, newPoints, intersections, iMap);

                if (intersections.length === 0) {
                    polygons.push(newPoints);
                    iMaps.push(iMap);
                    return this.formatContourOutput(polygons, pole, poleIndex, iMaps);
                }

                if (intersections.length > 2) {
                    intersections.sort(function (a, b) {
                        return b.latitude - a.latitude;
                    });
                }

                if (pole !== Location.poles.NONE) {
                    newPoints = this.handleOnePole(newPoints, intersections, iMap, pole);
                    iMap = this.reindexIntersections(intersections, iMap, this.poleIndexOffset);
                }
                if (intersections.length === 0) {
                    polygons.push(newPoints);
                    iMaps.push(iMap);
                    poleIndex = 0;
                    return this.formatContourOutput(polygons, pole, poleIndex, iMaps);
                }

                this.linkIntersections(intersections, iMap);

                poleIndex = this.makePolygons(newPoints, intersections, iMap, polygons, iMaps);

                return this.formatContourOutput(polygons, pole, poleIndex, iMaps);
            }
function ( points ) { var iMap = new HashMap ( ) ; var newPoints = [ ] ; var intersections = [ ] ; var polygons = [ ] ; var iMaps = [ ] ; var poleIndex = - 1 ; var pole = this . findIntersectionAndPole ( points , newPoints , intersections , iMap ) ; if ( intersections . length === 0 ) { polygons . push ( newPoints ) ; iMaps . push ( iMap ) ; return this . formatContourOutput ( polygons , pole , poleIndex , iMaps ) ; } if ( intersections . length > 2 ) { intersections . sort ( function ( a , b ) { return b . latitude - a . latitude ; } ) ; } if ( pole !== Location . poles . NONE ) { newPoints = this . handleOnePole ( newPoints , intersections , iMap , pole ) ; iMap = this . reindexIntersections ( intersections , iMap , this . poleIndexOffset ) ; } if ( intersections . length === 0 ) { polygons . push ( newPoints ) ; iMaps . push ( iMap ) ; poleIndex = 0 ; return this . formatContourOutput ( polygons , pole , poleIndex , iMaps ) ; } this . linkIntersections ( intersections , iMap ) ; poleIndex = this . makePolygons ( newPoints , intersections , iMap , polygons , iMaps ) ; return this . formatContourOutput ( polygons , pole , poleIndex , iMaps ) ; }
Splits a polygon that cross the anti-meridian or contain a pole.

@param {Location[] | Position[]} points an array of Locations or Positions that define a polygon
@returns {Object} @see PolygonSplitter.formatContourOutput
Splits a polygon that cross the anti - meridian or contain a pole .