UNPKG

@scandit/web-datacapture-core

Version:

Scandit Data Capture SDK for the Web

1 lines 2.06 kB
import {b,a as a$1}from'./chunk-77BBIAZE.js';var a=class m extends b{constructor(r,n,i,e,t,h,p,s,c){super(r,n,i,e),this._centerLeft=t,this._topCenter=h,this._centerRight=p,this._bottomCenter=s,this._center=c;}get centerRight(){return this._centerRight}get center(){return this._center}get centerLeft(){return this._centerLeft}get topCenter(){return this._topCenter}get bottomCenter(){return this._bottomCenter}static fromJSON(r){let{topLeft:n,topRight:i,bottomRight:e,bottomLeft:t,centerLeft:h,topCenter:p,centerRight:s,bottomCenter:c,center:P}=r,b=a$1.fromJSON(n),O=a$1.fromJSON(i),l=a$1.fromJSON(e),y=a$1.fromJSON(t),S=a$1.fromJSON(h),x=a$1.fromJSON(p),J=a$1.fromJSON(s),N=a$1.fromJSON(c),g=a$1.fromJSON(P);return new m(b,O,l,y,S,x,J,N,g)}toJSONObject(){return {...super.toJSONObject(),center:this._center.toJSONObject(),bottomCenter:this._bottomCenter.toJSONObject(),topCenter:this._topCenter.toJSONObject(),centerLeft:this._centerLeft.toJSONObject(),centerRight:this._centerRight.toJSONObject()}}orderVerticesByPosition(){let r=[[this.topLeft,this.topRight],[this.topRight,this.bottomRight],[this.bottomRight,this.bottomLeft],[this.bottomLeft,this.topLeft]],n=r.reduce((s,c)=>{let P=new a$1((s[0].x+s[1].x)/2,(s[0].y+s[1].y)/2),b=new a$1((c[0].x+c[1].x)/2,(c[0].y+c[1].y)/2);return P.y<b.y?s:c},r[0]),i=n[0].x<=n[1].x?n[0]:n[1],e=n[0].x>n[1].x?n[0]:n[1],t=[this.topLeft,this.topRight,this.bottomLeft,this.bottomRight].filter(s=>!s.equals(i)&&!s.equals(e)),h=new m(i,e,t[0],t[1],new a$1((i.x+t[1].x)/2,(i.y+t[1].y)/2),new a$1((i.x+e.x)/2,(i.y+e.y)/2),new a$1((e.x+t[0].x)/2,(e.y+t[0].y)/2),new a$1((t[1].x+t[0].x)/2,(t[1].y+t[0].y)/2),this.center),p=new m(i,e,t[1],t[0],new a$1((i.x+t[0].x)/2,(i.y+t[0].y)/2),new a$1((i.x+e.x)/2,(i.y+e.y)/2),new a$1((e.x+t[1].x)/2,(e.y+t[1].y)/2),new a$1((t[0].x+t[1].x)/2,(t[0].y+t[1].y)/2),this.center);return this.getArea(h)>=this.getArea(p)?h:p}getArea(r){let n=[r.topLeft,r.topRight,r.bottomRight,r.bottomLeft,r.topLeft],i=0;for(let e=0;e<n.length-1;e++)i+=n[e].x*n[e+1].y-n[e+1].x*n[e].y;return Math.abs(i)/2}};export{a};