public void extend ( LatLonPoint p ) { if ( contains ( p ) ) return ; double lat = p . getLatitude ( ) ; double lon = p . getLongitude ( ) ; // lat is easy to deal with if ( lat > upperRight . getLatitude ( ) ) { upperRight . setLatitude ( lat ) ; } if ( lat < lowerLeft . getLatitude ( ) ) { lowerLeft . setLatitude ( lat ) ; } // lon is uglier if ( allLongitude ) { // do nothing } else if ( crossDateline ) { // bounding box crosses the +/- 180 seam double d1 = lon - upperRight . getLongitude ( ) ; double d2 = lowerLeft . getLongitude ( ) - lon ; if ( ( d1 > 0.0 ) && ( d2 > 0.0 ) ) { // needed ? if ( d1 > d2 ) { lowerLeft . setLongitude ( lon ) ; } else { upperRight . setLongitude ( lon ) ; } } } else { // normal case if ( lon > upperRight . getLongitude ( ) ) { if ( lon - upperRight . getLongitude ( ) > lowerLeft . getLongitude ( ) - lon + 360 ) { crossDateline = true ; lowerLeft . setLongitude ( lon ) ; } else { upperRight . setLongitude ( lon ) ; } } else if ( lon < lowerLeft . getLongitude ( ) ) { if ( lowerLeft . getLongitude ( ) - lon > lon + 360.0 - upperRight . getLongitude ( ) ) { crossDateline = true ; upperRight . setLongitude ( lon ) ; } else { lowerLeft . setLongitude ( lon ) ; } } } // recalc delta, center width = upperRight . getLongitude ( ) - lowerLeft . getLongitude ( ) ; lon0 = ( upperRight . getLongitude ( ) + lowerLeft . getLongitude ( ) ) / 2 ; if ( crossDateline ) { width += 360 ; lon0 -= 180 ; } this . allLongitude = this . allLongitude || ( this . width >= 360.0 ) ; }
Extend the bounding box to contain this point