import Geometry from"./Geometry.js";import{abstract}from"../util.js";import{createOrUpdateFromFlatCoordinates,getCenter}from"../extent.js";import{rotate,scale,transform2D,translate}from"./flat/transform.js";class SimpleGeometry extends Geometry{constructor(){super(),this.layout="XY",this.stride=2,this.flatCoordinates=null}computeExtent(t){return createOrUpdateFromFlatCoordinates(this.flatCoordinates,0,this.flatCoordinates.length,this.stride,t)}getCoordinates(){return abstract()}getFirstCoordinate(){return this.flatCoordinates.slice(0,this.stride)}getFlatCoordinates(){return this.flatCoordinates}getLastCoordinate(){return this.flatCoordinates.slice(this.flatCoordinates.length-this.stride)}getLayout(){return this.layout}getSimplifiedGeometry(t){if(this.simplifiedGeometryRevision!==this.getRevision()&&(this.simplifiedGeometryMaxMinSquaredTolerance=0,this.simplifiedGeometryRevision=this.getRevision()),t<0||0!==this.simplifiedGeometryMaxMinSquaredTolerance&&t<=this.simplifiedGeometryMaxMinSquaredTolerance)return this;const e=this.getSimplifiedGeometryInternal(t);return e.getFlatCoordinates().length<this.flatCoordinates.length?e:(this.simplifiedGeometryMaxMinSquaredTolerance=t,this)}getSimplifiedGeometryInternal(t){return this}getStride(){return this.stride}setFlatCoordinates(t,e){this.stride=getStrideForLayout(t),this.layout=t,this.flatCoordinates=e}setCoordinates(t,e){abstract()}setLayout(t,e,r){let i;if(t)i=getStrideForLayout(t);else{for(let t=0;t<r;++t){if(0===e.length)return this.layout="XY",void(this.stride=2);e=e[0]}t=getLayoutForStride(i=e.length)}this.layout=t,this.stride=i}applyTransform(t){this.flatCoordinates&&(t(this.flatCoordinates,this.flatCoordinates,this.stride),this.changed())}rotate(t,e){var r,i=this.getFlatCoordinates();i&&(r=this.getStride(),rotate(i,0,i.length,r,t,e,i),this.changed())}scale(t,e,r){void 0===e&&(e=t),r=r||getCenter(this.getExtent());var i,o=this.getFlatCoordinates();o&&(i=this.getStride(),scale(o,0,o.length,i,t,e,r,o),this.changed())}translate(t,e){var r,i=this.getFlatCoordinates();i&&(r=this.getStride(),translate(i,0,i.length,r,t,e,i),this.changed())}}function getLayoutForStride(t){let e;return 2==t?e="XY":3==t?e="XYZ":4==t&&(e="XYZM"),e}function getStrideForLayout(t){let e;return"XY"==t?e=2:"XYZ"==t||"XYM"==t?e=3:"XYZM"==t&&(e=4),e}function transformGeom2D(t,e,r){var i=t.getFlatCoordinates();if(!i)return null;t=t.getStride();return transform2D(i,0,i.length,t,e,r)}export default SimpleGeometry;export{getStrideForLayout,transformGeom2D};