
//= depends: zapi

/**
 * ZAPI.GeoParser is a mixin used by geo parsing classes.
 *
 * @name ZAPI.GeoParser
 * @constructor
 */
ZAPI.namespace('Geo').Parser = {
	/**
	 * Figures out bounds for collections of points.
	 *
	 * @scope ZAPI.GeoParser.prototype
	 * @private
	 */
	_extendBounds: function(lat, lng) {
		if (this.bounds) {
			if (lat < this.bounds[0][0]) {
				this.bounds[0][0] = lat;
			}

			if (lat > this.bounds[1][0]) {
				this.bounds[1][0] = lat;
			}

			if (lng < 0) {
				if (lng > this.bounds[1][1]) {
					this.bounds[1][1] = lng;
				}
				else if (lng < this.bounds[0][1]) {
					this.bounds[0][1] = lng;
				}
 			}
 			else {
				if (lng < this.bounds[1][1]) {
					this.bounds[1][1] = lng;
				}
				else if (lng > this.bounds[0][1]) {
					this.bounds[0][1] = lng;
				}
 			}
		}
		else {
			this.bounds = [ [ lat, lng ], [ lat, lng ] ];
		}
	},

	/**
	 * Clears the current bounds.
	 */
	clearBounds: function() {
		this.bounds = undefined;
	}
};
