//----------------------------------------------------------
// Copyright (C) ESRI. All rights reserved.
//----------------------------------------------------------
Type.registerNamespace('ESRI.ADF.Geometries');ESRI.ADF.Geometries.Geometry = function(spatialReference) {
this._spatialReference = spatialReference;};ESRI.ADF.Geometries.Geometry.prototype = { 
get_spatialReference : function() {
return this._spatialReference;},
set_spatialReference : function(value) {
if(value!=this._spatialReference) {
this._spatialReference = value;this.raisePropertyChanged('spatialReference');}
},
getEnvelope : function() {
throw(new Error.notImplemented('getEnvelope'));}
};ESRI.ADF.Geometries.Geometry.registerClass('ESRI.ADF.Geometries.Geometry');ESRI.ADF.Geometries.Point = function(x,y,spatialReference) { 
ESRI.ADF.Geometries.Point.initializeBase(this, [spatialReference]);this.coordinates = [0.0,0.0];if(x) this.coordinates[0] = x;if(y) this.coordinates[1] = y;}
ESRI.ADF.Geometries.Point.prototype = {
toString : function(separator) {
if(!separator) separator = ',';return this.coordinates[0].toString() + separator + this.coordinates[1].toString();},
equals : function(other) {
return (this.coordinates[0]==other.coordinates[0] && this.coordinates[1]==other.coordinates[1]);},
getEnvelope : function() {
return new ESRI.ADF.Geometries.Envelope(this,this);},
get_x : function() {
return this.coordinates[0];},
set_x : function(value) {
this.coordinates[0] = value;},
get_y : function() {
return this.coordinates[1];},
set_y : function(value) {
this.coordinates[1] = value;}
}
ESRI.ADF.Geometries.Point.fromString = function(value) {
var arr = value.split(',');var x = parseFloat(arr[0]);var y = parseFloat(arr[1]);return new ESRI.ADF.Geometries.Point(x,y);}
ESRI.ADF.Geometries.Point.registerClass('ESRI.ADF.Geometries.Point', ESRI.ADF.Geometries.Geometry);ESRI.ADF.Geometries.GeometryCollection = function(geomtype,spatialReference) { 
ESRI.ADF.Geometries.GeometryCollection.initializeBase(this, [spatialReference]);this._geoms = [];if(!geomtype)
this._type = ESRI.ADF.Geometries.Geometry
else
this._type = geomtype;}
ESRI.ADF.Geometries.GeometryCollection.prototype = {
isEmpty : function() {
return (this._geoms.length>0);},
get_count : function() {
return this._geoms.length;},
add : function(geom) {
if(Sys.Debug.isDebug) { var e = Function._validateParams(arguments, [ {name: geom, type: this._type} ]);if(e) { throw e;} };this._geoms[this._geoms.length] = geom;},
get : function(index) {
return this._geoms[index];},
getFirst : function() {
if(this._geoms.length==0) return null;else return this._geoms[0];},
getLast : function() {
if(this._geoms.length==0) return null;else return this._geoms[this._geoms.length-1];},
remove : function(geom) {
Array.remove(this._geoms, point);},
removeAt : function(index) {
Array.removeAt(this._geoms, index);},
insert : function(index, geom) {
if(Sys.Debug.isDebug) { var e = Function._validateParams(arguments, [ {name: point, type: this._type} ]);if(e) { throw e;} };Array.insert(this._geoms, index, point);},
clear : function() {
Array.clear(this._geoms);},
getEnvelope : function() {
var env=null;for(var idx=0;idx<this.get_count();idx++) {
if(env) env = env.join(this._geoms[idx].getEnvelope());else env = this._geoms[idx].getEnvelope();}
return env;}
}
ESRI.ADF.Geometries.GeometryCollection.registerClass('ESRI.ADF.Geometries.GeometryCollection', ESRI.ADF.Geometries.Geometry);ESRI.ADF.Geometries.CoordinateCollection = function(points,spatialReference) { 
ESRI.ADF.Geometries.CoordinateCollection.initializeBase(this, [spatialReference]);this._coords = points?points:[];}
ESRI.ADF.Geometries.CoordinateCollection.prototype = {
toString : function(pntSeperator,coordSeparator) {
var pntCount = this.get_count();if(pntCount==0) return '';if(!pntSeperator) pntSeperator = ' ';var sb = new Sys.StringBuilder();sb.append(this.get(0)[0] + coordSeparator + this.get(0)[1]);for(var idx=1;idx<pntCount;idx++) {
sb.append(pntSeperator);sb.append(this.get(idx)[0] + coordSeparator + this.get(idx)[1]);}
return sb.toString();},
getEnvelope : function() {
if(this._coords.length===0) return null;var minx=this._coords[0][0];var miny=this._coords[0][1];var maxx=minx;var maxy=miny;for(var idx=1;idx<this.get_count();idx++) {
var g = this._coords[idx]
minx=Math.min(minx,g[0]);miny=Math.min(miny,g[1]);maxx=Math.max(maxx,g[0]);maxy=Math.max(maxy,g[1]);}
return new ESRI.ADF.Geometries.Envelope(minx,miny,maxx,maxy);},
get : function(index) {
return this._coords[index];},
getAsPoint : function(index) {
return new ESRI.ADF.Geometries.Point(this._coords[index][0],this._coords[index][1]);},
add : function(coord) {
this._coords[this._coords.length] = coord;},
get_coordinates : function(){
return this._coords;},
set_coordinates : function(value){
this._coords = value;},
getFirst : function() {
if(this._coords.length==0) return null;else return this._coords[0];},
getLast : function() {
if(this._coords.length==0) return null;else return this._coords[this._coords.length-1];}, 
removeAt : function(index) {
Array.removeAt(this._coords, index);},
get_count : function() {
return this._coords.length;},
clear : function() {
this._coords = [];} 
}
ESRI.ADF.Geometries.CoordinateCollection.fromString = function(value) {
var pnts = new ESRI.ADF.Geometries.CoordinateCollection();if(!value) { return pnts;}
var arr = value.split(' ');var geoms = [];for(var k=0;k<arr.length;k++) {
if(arr[k]) {
Array.add(geoms, ESRI.ADF.Geometries.Point.fromString(arr[k]).coordinates);}
}
pnts._coords = geoms;return pnts;}
ESRI.ADF.Geometries.CoordinateCollection.registerClass('ESRI.ADF.Geometries.CoordinateCollection',ESRI.ADF.Geometries.Geometry);ESRI.ADF.Geometries.Polyline = function(path, spatialReference) { 
ESRI.ADF.Geometries.Polyline.initializeBase(this, [spatialReference]);this._paths = new ESRI.ADF.Geometries.GeometryCollection(ESRI.ADF.Geometries.CoordinateCollection, spatialReference);if(path) this._paths.add(path);}
ESRI.ADF.Geometries.Polyline.prototype = { 
addPath : function(path) {
this._paths.add(path);},
getPath : function(n) {
return this._paths.get(n);},
getPathCount : function() {
return this._paths.get_count();},
getEnvelope : function() {
return this._paths.getEnvelope();}
}
ESRI.ADF.Geometries.Polyline.registerClass('ESRI.ADF.Geometries.Polyline', ESRI.ADF.Geometries.Geometry);ESRI.ADF.Geometries.Surface = function(spatialReference) { 
ESRI.ADF.Geometries.Surface.initializeBase(this, [spatialReference]);}
ESRI.ADF.Geometries.Surface.prototype = {
get_area : function() {
throw(new Error.notImplemented('get_area'));}
}
ESRI.ADF.Geometries.Surface.registerClass('ESRI.ADF.Geometries.Surface', ESRI.ADF.Geometries.Geometry);ESRI.ADF.Geometries.Polygon = function(ring, spatialReference) { 
ESRI.ADF.Geometries.Polygon.initializeBase(this, [spatialReference]);this._rings = new ESRI.ADF.Geometries.GeometryCollection(ESRI.ADF.Geometries.CoordinateCollection, spatialReference);if(ring) this._rings.add(ring);}
ESRI.ADF.Geometries.Polygon.prototype = {
addRing : function(ring) {
this._rings.add(ring);},
getRing : function(n) {
return this._rings.get(n);},
getRingCount : function() {
return this._rings.get_count();},
getEnvelope : function() {
return this._rings.getEnvelope();}
}
ESRI.ADF.Geometries.Polygon.registerClass('ESRI.ADF.Geometries.Polygon', ESRI.ADF.Geometries.Surface);ESRI.ADF.Geometries.Oval = function(center, width, height, spatialReference) { 
ESRI.ADF.Geometries.Oval.initializeBase(this, [spatialReference]);this._center = center;this._width = width;this._height = (height==null || height==undefined)?width:height;}
ESRI.ADF.Geometries.Oval.prototype = {
getEnvelope : function() {
return new ESRI.ADF.Geometries.Envelope(
this._center.get_x()-Math.abs(this._width)*0.5, this._center.get_y()-Math.abs(this._height)*0.5,
this._center.get_x()+Math.abs(this._width)*0.5, this._center.get_y()+Math.abs(this._height)*0.5,
this._spatialReference);},
get_area : function() {
return Math.PI * Math.abs(this._width) * Math.abs(this._height);},
toString : function() {
return this.getEnvelope().toString();},
get_center : function() {
return this._center;},
set_center : function(value) { this._center = value;},
get_width : function() {
return this._width;},
set_width : function(value) { this._width = value;},
get_height : function() {
return this._height;},
set_height : function(value) { this._height = value;}
}
ESRI.ADF.Geometries.Oval.registerClass('ESRI.ADF.Geometries.Oval', ESRI.ADF.Geometries.Surface);ESRI.ADF.Geometries.Envelope = function() { 
var n = arguments.length;var spatialReference = null;if(n>2 && String.isInstanceOfType(arguments[n-1])) {
spatialReference = arguments[n-1];}
else if(n<2) throw new Error.argument('ESRI.ADF.Geometries.Envelope','Invalid number of arguments');if(ESRI.ADF.Geometries.Point.isInstanceOfType(arguments[0]) && ESRI.ADF.Geometries.Point.isInstanceOfType(arguments[1])) {
this._xmin = Math.min(arguments[0].get_x(),arguments[1].get_x());this._ymin = Math.min(arguments[0].get_y(),arguments[1].get_y());this._xmax = Math.max(arguments[0].get_x(),arguments[1].get_x());this._ymax = Math.max(arguments[0].get_y(),arguments[1].get_y());}
else if(n>=4 && Number.isInstanceOfType(arguments[0]) && Number.isInstanceOfType(arguments[1]) && 
Number.isInstanceOfType(arguments[2]) && Number.isInstanceOfType(arguments[3])) {
this._xmin = Math.min(arguments[0],arguments[2]);this._ymin = Math.min(arguments[1],arguments[3]);this._xmax = Math.max(arguments[0],arguments[2]);this._ymax = Math.max(arguments[1],arguments[3]);}
else throw new Error.argument('ESRI.ADF.Geometries.Envelope','Invalid arguments');ESRI.ADF.Geometries.Envelope.initializeBase(this, [spatialReference]);}
ESRI.ADF.Geometries.Envelope.prototype = {
get_area : function() {
return (this.get_width()*this.get_height());},
toString : function() {
return '[' + this._xmin+','+this._ymin + ' ' +this._xmax+','+this._ymax + ']';},
get_xmin : function() {
return this._xmin;},
set_xmin : function(value) {
this._xmin = value;},
get_ymin : function() {
return this._ymin;},
set_ymin : function(value) {
this._ymin = value;},
get_xmax : function() {
return this._xmax;},
set_xmax : function(value) {
this._xmax = value;},
get_ymax : function() {
return this._ymax;},
set_ymax : function(value) {
this._ymax = value;}, 
intersects : function(env2) {
if(!env2) return false;return !(env2._xmin > this._xmax ||
env2._xmax < this._xmin ||
env2._ymin > this._ymax ||
env2._ymax < this._ymin);},
join : function(env2) {
if(!env2) return this;return new ESRI.ADF.Geometries.Envelope(
new ESRI.ADF.Geometries.Point(
(this._xmin<env2._xmin?this._xmin:env2._xmin),
(this._ymin<env2._ymin?this._ymin:env2._ymin)),
new ESRI.ADF.Geometries.Point(
(this._xmax>env2._xmax?this._xmax:env2._xmax),
(this._ymax>env2._ymax?this._ymax:env2._ymax)),
this._spatialReference);},
get_width : function() {
return (this._xmax-this._xmin);},
get_height : function() {
return (this._ymax-this._ymin);},
get_center : function() {
return new ESRI.ADF.Geometries.Point(
(this._xmin+this._xmax)*0.5,
(this._ymin+this._ymax)*0.5, this._spatialReference);},
intersection : function(env2) {
if(!this.intersects(env2)) return null;return new ESRI.ADF.Geometries.Envelope(
new ESRI.ADF.Geometries.Point(
(this._xmin>env2._xmin?this._xmin:env2._xmin),
(this._ymin>env2._ymin?this._ymin:env2._ymin)),
new ESRI.ADF.Geometries.Point(
(this._xmax<env2._xmax?this._xmax:env2._xmax),
(this._ymax<env2._ymax?this._ymax:env2._ymax)),
this._spatialReference);},
getEnvelope : function() {
return this.clone();},
clone : function() {
return new ESRI.ADF.Geometries.Envelope(this._xmin,this._ymin,this._xmax,this._ymax);}
}
ESRI.ADF.Geometries.Envelope.registerClass('ESRI.ADF.Geometries.Envelope', ESRI.ADF.Geometries.Surface);if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();