/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{equals as t}from"../../../../core/arrayUtils.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{projectAndScale as r,transformMat3 as o}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{fromValues as a,create as e}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{invert as s}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{EllipticArc7Segment as c}from"../EditGeometry.js";import{getScaleTransform as n,scaleArc as f}from"./curveOperationUtils.js";class l{constructor(t,i,r,o,e=0){this.origin=t,this.axis1=i,this.factor1=r,this.factor2=o,this._accumulationType=e,this.axis2=a(i[1],-i[0])}_scale({pos:t,leftSegment:i},o,a){const e=i?.toCurveOrCoordinate(),{origin:s,axis1:c,axis2:n}=this;r(t,t,s,c,o),r(t,t,s,n,a),m(i,s,c,n,o,a,e)}apply(t){this._scale(t,this.factor1,this.factor2)}undo(t){this._scale(t,1/this.factor1,1/this.factor2)}canAccumulate(i){return i instanceof l&&t(this.origin,i.origin)&&t(this.axis1,i.axis1)}accumulate(t,i){1===i._accumulationType?this._scale(t,i.factor1/this.factor1,i.factor2/this.factor2):this._scale(t,i.factor1,i.factor2)}accumulateParams(t){const i=1===t._accumulationType;this.factor1=i?t.factor1:this.factor1*t.factor1,this.factor2=i?t.factor2:this.factor2*t.factor2}}function m(t,a,l,m,h,p,u){switch(t?.type){case null:case void 0:case"line":return;case"bezier":{const{controlPoint1:i,controlPoint2:o}=t.curveDefinition;r(i,i,a,l,h),r(i,i,a,m,p),r(o,o,a,l,h),r(o,o,a,m,p);break}case"circular-arc":case"elliptic-arc-4":case"elliptic-arc-7":{if(!u)return;const r=t.leftVertex.pos,x=n(a[0],a[1],l[0],l[1],m[0],m[1],h,p),g=s(i(),x),j=g?o(e(),[r[0],r[1]],g):r,[,y,_,v,b,d,A]=f(u,[j[0],j[1]],t,a,l,m,h,p).a;if("elliptic-arc-7"===t.type){const i=t.curveDefinition;i.centerPoint=y,i.sweep=_,i.orientation=v,i.rotation=b,i.semiMajorAxisLength=d,i.minorMajorAxisRatio=A}else{const i=new c(t.part,t.leftVertex,t.rightVertex,{centerPoint:y,sweep:_,orientation:v,rotation:b,semiMajorAxisLength:d,minorMajorAxisRatio:A});t.part.segments.splice(t.part.segments.indexOf(t),1,i)}return}}}export{l as ScaleVertex};
