/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import r from"../../../core/Logger.js";import{NumericIdentifiableMixin as o}from"../../../core/NumericIdentifiable.js";import{property as i,subclass as s}from"../../../core/accessorSupport/decorators.js";import{project as n}from"../../../geometry/projectionUtils.js";import{extentContainsPoint as m,polygonContainsPoint as a}from"../../../geometry/support/contains.js";import{nearestCoordinate as l}from"../../../geometry/support/near.js";var c;let p=c=class extends(o(t)){constructor(e){super(e),this.geometry=null,this.spatialReference=null}get normalizedGeometry(){if(null==this.geometry||!this.spatialReference)return null;if(!this.spatialReference.equals(this.geometry.spatialReference))try{return n(this.geometry,this.spatialReference)}catch(e){return r.getLogger(this).error("#constraints.geometry","could not project the geometry to the view's spatial reference",{geometry:this.geometry,spatialReference:this.spatialReference,error:e}),null}return this.geometry}constrain(e,t){if(null==this.normalizedGeometry)return e;const r=e.targetGeometry;if("extent"===this.normalizedGeometry.type?m(this.normalizedGeometry,r):a(this.normalizedGeometry,r))return e;const{coordinate:o}=l(this.normalizedGeometry,r);return o?(e.targetGeometry=o,e):e}clone(){return new c({geometry:this.geometry?.clone(),spatialReference:this.spatialReference?.clone()})}};e([i({constructOnly:!0})],p.prototype,"geometry",void 0),e([i({readOnly:!0})],p.prototype,"normalizedGeometry",null),e([i({constructOnly:!0})],p.prototype,"spatialReference",void 0),p=c=e([s("esri.views.2d.constraints.GeometryConstraint")],p);export{p as GeometryConstraint};
