src/util/PolygonSplitter.js
function (points, newPoints, intersections, iMap) {
                var containsPole = false;
                var minLatitude = 90.0;
                var maxLatitude = -90.0;
                this.addedIndex = -1;

                for (var i = 0, lenC = points.length; i < lenC; i++) {
                    var pt1 = points[i];
                    var pt2 = points[(i + 1) % lenC];

                    minLatitude = Math.min(minLatitude, pt1.latitude);
                    maxLatitude = Math.max(maxLatitude, pt1.latitude);

                    var doesCross = Location.locationsCrossDateLine([pt1, pt2]);
                    if (doesCross) {
                        containsPole = !containsPole;

                        var iLatitude = Location.meridianIntersection(pt1, pt2, 180);
                        if (iLatitude === null) {
                            iLatitude = (pt1.latitude + pt2.latitude) / 2;
                        }
                        var iLongitude = WWMath.signum(pt1.longitude) * 180 || 180;

                        var iLoc1 = this.createPoint(iLatitude, iLongitude, pt1.altitude);
                        var iLoc2 = this.createPoint(iLatitude, -iLongitude, pt2.altitude);

                        this.safeAdd(newPoints, pt1, i, lenC);

                        var index = newPoints.length;
                        iMap.set(index, this.makeIntersectionEntry(index));
                        iMap.set(index + 1, this.makeIntersectionEntry(index + 1));
                        intersections.push({
                            indexEnd: index,
                            indexStart: index + 1,
                            latitude: iLatitude
                        });

                        newPoints.push(iLoc1);
                        newPoints.push(iLoc2);

                        this.safeAdd(newPoints, pt2, i + 1, lenC);
                    }
                    else {
                        this.safeAdd(newPoints, pt1, i, lenC);
                        this.safeAdd(newPoints, pt2, i + 1, lenC);
                    }
                }

                var pole = Location.poles.NONE;
                if (containsPole) {
                    pole = this.determinePole(minLatitude, maxLatitude);
                }

                return pole;
            }
function (points, newPoints, intersections, iMap) {
                var containsPole = false;
                var minLatitude = 90.0;
                var maxLatitude = -90.0;
                this.addedIndex = -1;

                for (var i = 0, lenC = points.length; i < lenC; i++) {
                    var pt1 = points[i];
                    var pt2 = points[(i + 1) % lenC];

                    minLatitude = Math.min(minLatitude, pt1.latitude);
                    maxLatitude = Math.max(maxLatitude, pt1.latitude);

                    var doesCross = Location.locationsCrossDateLine([pt1, pt2]);
                    if (doesCross) {
                        containsPole = !containsPole;

                        var iLatitude = Location.meridianIntersection(pt1, pt2, 180);
                        if (iLatitude === null) {
                            iLatitude = (pt1.latitude + pt2.latitude) / 2;
                        }
                        var iLongitude = WWMath.signum(pt1.longitude) * 180 || 180;

                        var iLoc1 = this.createPoint(iLatitude, iLongitude, pt1.altitude);
                        var iLoc2 = this.createPoint(iLatitude, -iLongitude, pt2.altitude);

                        this.safeAdd(newPoints, pt1, i, lenC);

                        var index = newPoints.length;
                        iMap.set(index, this.makeIntersectionEntry(index));
                        iMap.set(index + 1, this.makeIntersectionEntry(index + 1));
                        intersections.push({
                            indexEnd: index,
                            indexStart: index + 1,
                            latitude: iLatitude
                        });

                        newPoints.push(iLoc1);
                        newPoints.push(iLoc2);

                        this.safeAdd(newPoints, pt2, i + 1, lenC);
                    }
                    else {
                        this.safeAdd(newPoints, pt1, i, lenC);
                        this.safeAdd(newPoints, pt2, i + 1, lenC);
                    }
                }

                var pole = Location.poles.NONE;
                if (containsPole) {
                    pole = this.determinePole(minLatitude, maxLatitude);
                }

                return pole;
            }
function ( points , newPoints , intersections , iMap ) { var containsPole = false ; var minLatitude = 90.0 ; var maxLatitude = - 90.0 ; this . addedIndex = - 1 ; for ( var i = 0 , lenC = points . length ; i < lenC ; i ++ ) { var pt1 = points [ i ] ; var pt2 = points [ ( i + 1 ) % lenC ] ; minLatitude = Math . min ( minLatitude , pt1 . latitude ) ; maxLatitude = Math . max ( maxLatitude , pt1 . latitude ) ; var doesCross = Location . locationsCrossDateLine ( [ pt1 , pt2 ] ) ; if ( doesCross ) { containsPole = ! containsPole ; var iLatitude = Location . meridianIntersection ( pt1 , pt2 , 180 ) ; if ( iLatitude === null ) { iLatitude = ( pt1 . latitude + pt2 . latitude ) / 2 ; } var iLongitude = WWMath . signum ( pt1 . longitude ) * 180 || 180 ; var iLoc1 = this . createPoint ( iLatitude , iLongitude , pt1 . altitude ) ; var iLoc2 = this . createPoint ( iLatitude , - iLongitude , pt2 . altitude ) ; this . safeAdd ( newPoints , pt1 , i , lenC ) ; var index = newPoints . length ; iMap . set ( index , this . makeIntersectionEntry ( index ) ) ; iMap . set ( index + 1 , this . makeIntersectionEntry ( index + 1 ) ) ; intersections . push ( { indexEnd : index , indexStart : index + 1 , latitude : iLatitude } ) ; newPoints . push ( iLoc1 ) ; newPoints . push ( iLoc2 ) ; this . safeAdd ( newPoints , pt2 , i + 1 , lenC ) ; } else { this . safeAdd ( newPoints , pt1 , i , lenC ) ; this . safeAdd ( newPoints , pt2 , i + 1 , lenC ) ; } } var pole = Location . poles . NONE ; if ( containsPole ) { pole = this . determinePole ( minLatitude , maxLatitude ) ; } return pole ; }
Internal. Applications should not call this method.
Finds the intersections with the anti-meridian and if the polygon contains one of the poles.
A new polygon is constructed with the intersections and pole points and stored in newPoints

@param {Location[] | Position[]} points An array of Locations or Positions that define a polygon
@param {Location[] | Position[]} newPoints An empty array where to store the resulting polygon with intersections
@param {Array} intersections An empty array where to store the intersection latitude and index
@param {HashMap} iMap A hashMap to store intersection data
The key is the index in the newPoints array and value is PolygonSplitter.makeIntersectionEntry
@returns {Number} The pole number @see Location.poles
Internal . Applications should not call this method . Finds the intersections with the anti - meridian and if the polygon contains one of the poles . A new polygon is constructed with the intersections and pole points and stored in newPoints