1 /*************************************** 2 * Copyright 2011, 2012 GlobWeb contributors. 3 * 4 * This file is part of GlobWeb. 5 * 6 * GlobWeb is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * GlobWeb is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with GlobWeb. If not, see <http://www.gnu.org/licenses/>. 18 ***************************************/ 19 20 define( function() { 21 22 /**************************************************************************************************************/ 23 24 /** @constructor 25 @export 26 GeoBound constructor 27 */ 28 var GeoBound = function( w, s, e, n ) 29 { 30 this.south = s; 31 this.west = w; 32 this.north = n; 33 this.east = e; 34 } 35 36 /**************************************************************************************************************/ 37 38 /** 39 Get geo center 40 */ 41 GeoBound.prototype.getCenter = function() 42 { 43 return [ (this.east+this.west)*0.5, (this.south+this.north)*0.5, 0.0 ]; 44 } 45 46 /**************************************************************************************************************/ 47 48 /** @export 49 Get north 50 */ 51 GeoBound.prototype.getNorth = function() 52 { 53 return this.north; 54 } 55 56 /**************************************************************************************************************/ 57 58 /** @export 59 Get south 60 */ 61 GeoBound.prototype.getSouth = function() 62 { 63 return this.south; 64 } 65 66 /**************************************************************************************************************/ 67 68 /** @export 69 Get west 70 */ 71 GeoBound.prototype.getWest = function() 72 { 73 return this.west; 74 } 75 76 /**************************************************************************************************************/ 77 78 /** @export 79 Get east 80 */ 81 GeoBound.prototype.getEast = function() 82 { 83 return this.east; 84 } 85 86 /**************************************************************************************************************/ 87 88 /** 89 Compute the geo bound from coordinates 90 */ 91 GeoBound.prototype.computeFromCoordinates = function( coordinates ) 92 { 93 this.west = coordinates[0][0]; 94 this.east = coordinates[0][0]; 95 this.south = coordinates[0][1]; 96 this.north = coordinates[0][1]; 97 98 for ( var i = 1; i < coordinates.length; i++ ) 99 { 100 this.west = Math.min( this.west, coordinates[i][0] ); 101 this.east = Math.max( this.east, coordinates[i][0] ); 102 this.south = Math.min( this.south, coordinates[i][1] ); 103 this.north = Math.max( this.north, coordinates[i][1] ); 104 } 105 } 106 107 /**************************************************************************************************************/ 108 109 /** 110 Intersects this geo bound with another one 111 */ 112 GeoBound.prototype.intersects = function( geoBound ) 113 { 114 if ( this.west >= geoBound.east || this.east <= geoBound.west ) 115 return false; 116 117 if ( this.south >= geoBound.north || this.north <= geoBound.south ) 118 return false; 119 120 return true; 121 } 122 123 /**************************************************************************************************************/ 124 125 return GeoBound; 126 127 }); 128