// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/arcade/functions/geomasync","require exports ../../geometry/Geometry ../../geometry/Polygon ../../geometry/Polyline ../../geometry/Point ../../geometry/Extent ../../geometry/Multipoint ../../geometry/jsonUtils ../languageUtils ../kernel ../../kernel dojo/Deferred ../../geometry/geometryEngineAsync ./centroid".split(" "),function(C,t,f,p,q,u,r,x,v,c,l,y,B,g,z){function m(c){return w?c.clone():v.fromJson(c.toJson())}function A(c){return 0===y.version.indexOf("4.")?p.fromExtent(c):new p({spatialReference:c.spatialReference,
rings:[[[c.xmin,c.ymin],[c.xmin,c.ymax],[c.xmax,c.ymax],[c.xmax,c.ymin],[c.xmin,c.ymin]]]})}Object.defineProperty(t,"__esModule",{value:!0});var w=0===y.version.indexOf("4.");t.registerFunctions=function(e,t,h){function n(d){c.pcCheck(d,2,2);if(!(d[0]instanceof f&&d[1]instanceof f||d[0]instanceof f&&null===d[1]||d[1]instanceof f&&null===d[0]||null===d[0]&&null===d[1]))throw Error("Illegal Argument");}e.disjoint=function(c,b){return h(c,b,function(c,d,a){n(a);return null===a[0]||null===a[1]?!0:g.disjoint(a[0],
a[1])})};e.intersects=function(c,b){return h(c,b,function(c,d,a){n(a);return null===a[0]||null===a[1]?!1:g.intersects(a[0],a[1])})};e.touches=function(c,b){return h(c,b,function(c,d,a){n(a);return null===a[0]||null===a[1]?!1:g.touches(a[0],a[1])})};e.crosses=function(c,b){return h(c,b,function(c,d,a){n(a);return null===a[0]||null===a[1]?!1:g.crosses(a[0],a[1])})};e.within=function(c,b){return h(c,b,function(c,d,a){n(a);return null===a[0]||null===a[1]?!1:g.within(a[0],a[1])})};e.contains=function(c,
b){return h(c,b,function(c,d,a){n(a);return null===a[0]||null===a[1]?!1:g.contains(a[0],a[1])})};e.overlaps=function(c,b){return h(c,b,function(c,d,a){n(a);return null===a[0]||null===a[1]?!1:g.overlaps(a[0],a[1])})};e.equals=function(d,b){return h(d,b,function(d,b,a){c.pcCheck(a,2,2);return a[0]===a[1]?!0:a[0]instanceof f&&a[1]instanceof f?g.equals(a[0],a[1]):c.isDate(a[0])&&c.isDate(a[1])?a[0].getTime()===a[1].getTime():!1})};e.relate=function(d,b){return h(d,b,function(d,b,a){c.pcCheck(a,3,3);if(a[0]instanceof
f&&a[1]instanceof f)return g.relate(a[0],a[1],c.toString(a[2]));if(a[0]instanceof f&&null===a[1]||a[1]instanceof f&&null===a[0]||null===a[0]&&null===a[1])return!1;throw Error("Illegal Argument");})};e.intersection=function(c,b){return h(c,b,function(c,d,a){n(a);return null===a[0]||null===a[1]?null:g.intersect(a[0],a[1])})};e.union=function(d,b){return h(d,b,function(b,k,a){b=[];if(0===a.length)throw Error("Function called with wrong number of Parameters");if(1===a.length)if(c.isArray(a[0]))for(k=
0;k<a[0].length;k++){if(null!==a[0][k])if(a[0][k]instanceof f)b.push(a[0][k]);else throw Error("Illegal Argument");}else if(c.isImmutableArray(a[0]))for(a=a[0].toArray(),k=0;k<a.length;k++){if(null!==a[k])if(a[k]instanceof f)b.push(a[k]);else throw Error("Illegal Argument");}else{if(a[0]instanceof f)return c.fixSpatialReference(m(a[0]),d.spatialReference);if(null===a[0])return null;throw Error("Illegal Argument");}else for(k=0;k<a.length;k++)if(null!==a[k])if(a[k]instanceof f)b.push(a[k]);else throw Error("Illegal Argument");
return 0===b.length?null:g.union(b)})};e.difference=function(c,b){return h(c,b,function(c,b,a){n(a);return null!==a[0]&&null===a[1]?m(a[0]):null===a[0]?null:g.difference(a[0],a[1])})};e.symmetricdifference=function(c,b){return h(c,b,function(c,b,a){n(a);return null===a[0]&&null===a[1]?null:null===a[0]?m(a[1]):null===a[1]?m(a[0]):g.symmetricDifference(a[0],a[1])})};e.clip=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,2);if(!(a[1]instanceof r)&&null!==a[1])throw Error("Illegal Argument");
if(null===a[0])return null;if(!(a[0]instanceof f))throw Error("Illegal Argument");return null===a[1]?null:g.clip(a[0],a[1])})};e.cut=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,2);if(!(a[1]instanceof q)&&null!==a[1])throw Error("Illegal Argument");if(null===a[0])return[];if(!(a[0]instanceof f))throw Error("Illegal Argument");return null===a[1]?[m(a[0])]:g.cut(a[0],a[1])})};e.area=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,1,2);if(null===a[0])return 0;if(!(a[0]instanceof f))throw Error("Illegal Argument");
return g.planarArea(a[0],l.convertSquareUnitsToCode(c.defaultUndefined(a[1],-1)))})};e.areageodetic=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,1,2);if(null===a[0])return 0;if(!(a[0]instanceof f))throw Error("Illegal Argument");return g.geodesicArea(a[0],l.convertSquareUnitsToCode(c.defaultUndefined(a[1],-1)))})};e.length=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,1,2);if(null===a[0])return 0;if(!(a[0]instanceof f))throw Error("Illegal Argument");return g.planarLength(a[0],
l.convertLinearUnitsToCode(c.defaultUndefined(a[1],-1)))})};e.lengthgeodetic=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,1,2);if(null===a[0])return 0;if(!(a[0]instanceof f))throw Error("Illegal Argument");return g.geodesicLength(a[0],l.convertLinearUnitsToCode(c.defaultUndefined(a[1],-1)))})};e.distance=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,3);if(!(a[0]instanceof f))throw Error("Illegal Argument");if(!(a[1]instanceof f))throw Error("Illegal Argument");return g.distance(a[0],
a[1],l.convertLinearUnitsToCode(c.defaultUndefined(a[2],-1)))})};e.densify=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,3);if(null===a[0])return null;if(!(a[0]instanceof f))throw Error("Illegal Argument");b=c.toNumber(a[1]);if(isNaN(b))throw Error("Illegal Argument");if(0>=b)throw Error("Illegal Argument");return a[0]instanceof p||a[0]instanceof q?g.densify(a[0],b,l.convertLinearUnitsToCode(c.defaultUndefined(a[2],-1))):a[0]instanceof r?g.densify(A(a[0]),b,l.convertLinearUnitsToCode(c.defaultUndefined(a[2],
-1))):a[0]})};e.densifygeodetic=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,3);if(null===a[0])return null;if(!(a[0]instanceof f))throw Error("Illegal Argument");b=c.toNumber(a[1]);if(isNaN(b))throw Error("Illegal Argument");if(0>=b)throw Error("Illegal Argument");return a[0]instanceof p||a[0]instanceof q?g.geodesicDensify(a[0],b,l.convertLinearUnitsToCode(c.defaultUndefined(a[2],-1))):a[0]instanceof r?g.geodesicDensify(A(a[0]),b,l.convertLinearUnitsToCode(c.defaultUndefined(a[2],-1))):
a[0]})};e.generalize=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,4);if(null===a[0])return null;if(!(a[0]instanceof f))throw Error("Illegal Argument");b=c.toNumber(a[1]);if(isNaN(b))throw Error("Illegal Argument");return g.generalize(a[0],b,c.toBoolean(c.defaultUndefined(a[2],!0)),l.convertLinearUnitsToCode(c.defaultUndefined(a[3],-1)))})};e.buffer=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,3);if(null===a[0])return null;if(!(a[0]instanceof f))throw Error("Illegal Argument");
b=c.toNumber(a[1]);if(isNaN(b))throw Error("Illegal Argument");return 0===b?m(a[0]):g.buffer(a[0],b,l.convertLinearUnitsToCode(c.defaultUndefined(a[2],-1)))})};e.buffergeodetic=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,3);if(null===a[0])return null;if(!(a[0]instanceof f))throw Error("Illegal Argument");b=c.toNumber(a[1]);if(isNaN(b))throw Error("Illegal Argument");return 0===b?m(a[0]):g.geodesicBuffer(a[0],b,l.convertLinearUnitsToCode(c.defaultUndefined(a[2],-1)))})};e.offset=function(d,
b){return h(d,b,function(b,d,a){c.pcCheck(a,2,6);if(null===a[0])return null;if(!(a[0]instanceof p||a[0]instanceof q))throw Error("Illegal Argument");b=c.toNumber(a[1]);if(isNaN(b))throw Error("Illegal Argument");d=c.toNumber(c.defaultUndefined(a[4],10));if(isNaN(d))throw Error("Illegal Argument");var f=c.toNumber(c.defaultUndefined(a[5],0));if(isNaN(f))throw Error("Illegal Argument");return g.offset(a[0],b,l.convertLinearUnitsToCode(c.defaultUndefined(a[2],-1)),c.toString(c.defaultUndefined(a[3],
"round")).toLowerCase(),d,f)})};e.rotate=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,2,3);b=a[0];if(null===b)return null;if(!(b instanceof f))throw Error("Illegal Argument");b instanceof r&&(b=p.fromExtent(b));d=c.toNumber(a[1]);if(isNaN(d))throw Error("Illegal Argument");a=c.defaultUndefined(a[2],null);if(null===a)return g.rotate(b,d);if(a instanceof u)return g.rotate(b,d,a);throw Error("Illegal Argument");})};e.centroid=function(d,b){return h(d,b,function(b,g,a){c.pcCheck(a,1,1);if(null===
a[0])return null;if(!(a[0]instanceof f))throw Error("Illegal Argument");return a[0]instanceof u?c.fixSpatialReference(m(a[0]),d.spatialReference):a[0]instanceof p?w?a[0].centroid:a[0].getCentroid():a[0]instanceof q?z.centroidPolyline(a[0]):a[0]instanceof x?z.centroidMultiPoint(a[0]):a[0]instanceof r?w?a[0].center:a[0].getExtent().getCenter():null})};e.multiparttosinglepart=function(d,b){return h(d,b,function(b,e,a){c.pcCheck(a,1,1);var h=[];if(null===a[0])return null;if(!(a[0]instanceof f))throw Error("Illegal Argument");
if(a[0]instanceof u||a[0]instanceof r)return[c.fixSpatialReference(m(a[0]),d.spatialReference)];var k=new B;g.simplify(a[0]).then(l.callback(function(b){if(b instanceof p){for(var f=[],g=[],e=0;e<b.rings.length;e++)if(b.isClockwise(b.rings[e])){var l=v.fromJson({rings:[b.rings[e]],hasZ:b.hasZ,hazM:b.hasM,spatialReference:b.spatialReference.toJson()});f.push(l)}else g.push({ring:b.rings[e],pt:b.getPoint(e,0)});for(e=0;e<g.length;e++)for(b=0;b<f.length;b++)if(f[b].contains(g[e].pt)){f[b].addRing(g[e].ring);
break}k.resolve(f)}else if(b instanceof q){f=[];for(e=0;e<b.paths.length;e++)g=v.fromJson({paths:[b.paths[e]],hasZ:b.hasZ,hazM:b.hasM,spatialReference:b.spatialReference.toJson()}),f.push(g);k.resolve(f)}else if(a[0]instanceof x){b=c.fixSpatialReference(m(a[0]),d.spatialReference);for(e=0;e<b.points.length;e++)h.push(b.getPoint(e));k.resolve(h)}else k.resolve(null)},k),l.errback(k));return k.promise})};e.issimple=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,1,1);if(null===a[0])return!0;
if(a[0]instanceof f)return g.isSimple(a[0]);throw Error("Illegal Argument");})};e.simplify=function(d,b){return h(d,b,function(b,d,a){c.pcCheck(a,1,1);if(null===a[0])return null;if(a[0]instanceof f)return g.simplify(a[0]);throw Error("Illegal Argument");})}}});