export default class Extent { constructor ( private minLon , private minLat , private maxLon , private maxLat ) { } clone ( ) { return new Extent ( this . minLon , this . minLat , this . maxLon , this . maxLat ) ; } getMinLon ( ) { return this . minLon ; } getMinLat ( ) { return this . minLat ; } getMaxLon ( ) { return this . maxLon ; } getMaxLat ( ) { return this . maxLat ; } toJson ( ) { return [ this . minLon , this . minLat , this . maxLon , this . maxLat ] ; } static merge ( extents , union ) { var result = null ; if ( extents . length === 1 ) { result = extents [ 0 ] . clone ( ) ; } else if ( extents . length > 1 ) { var minLons = [ ] ; var minLats = [ ] ; var maxLons = [ ] ; var maxLats = [ ] ; extents . forEach ( function ( extent ) { minLons . push ( extent . getMinLon ( ) ) ; minLats . push ( extent . getMinLat ( ) ) ; maxLons . push ( extent . getMaxLon ( ) ) ; maxLats . push ( extent . getMaxLat ( ) ) ; } ) ; if ( union ) { const minLon = Math . min ( ... minLons ) ; const minLat = Math . min ( ... minLats ) ; const maxLon = Math . max ( ... maxLons ) ; const maxLat = Math . max ( ... maxLats ) ; result = new Extent ( minLon , minLat , maxLon , maxLat ) ; } else { const minLon = Math . max ( ... minLons ) ; const minLat = Math . max ( ... minLats ) ; const maxLon = Math . min ( ... maxLons ) ; const maxLat = Math . min ( ... maxLats ) ; if ( minLon < maxLon && minLat < maxLat ) { result = new Extent ( minLon , minLat , maxLon , maxLat ) ; } } } return result ; } static union ( extents ) { return this . merge ( extents , true ) ; } static intersect ( extents ) { return this . merge ( extents , false ) ; } static fromLonlats ( lonlats ) { if ( lonlats . length <= 1 ) { return null ; } const lons = [ ] ; const lats = [ ] ; lonlats . forEach ( ( lonlat ) => { lons . push ( lonlat [ 0 ] ) ; lats . push ( lonlat [ 1 ] ) ; } ) ; const minLon = Math . min ( ... lons ) ; const minLat = Math . min ( ... lats ) ; const maxLon = Math . max ( ... lons ) ; const maxLat = Math . max ( ... lats ) ; const extent = new Extent ( minLon , minLat , maxLon , maxLat ) ; return extent ; } } ;