UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.11 kB
import{isSome as t,isNone as e}from"../../../../core/maybe.js";import{List as i}from"./cpuMapped/FreeList.js";class n{constructor(t,e,i,n,a){this.target=t,this.geometryType=e,this.materialKey=i,this.indexFrom=n,this.indexCount=a}get indexEnd(){return this.indexFrom+this.indexCount}extend(t){this.indexCount+=t}}class a{constructor(t,e){this.geometryType=0,this._target=t,this.geometryType=e}static from(e,i,n,d){const r=new a(e,i);if(t(d))for(const t of d)n.seekIndex(t),r.addRecord(n);else for(;n.next();)r.addRecord(n);return r}addRecord(t){const a=this._target,d=this.geometryType,r=t.materialKey;let s=t.indexFrom,o=t.indexCount;const h=t.vertexFrom,x=t.vertexCount;if(o||(s=h,o=x),e(this._head)){const t=new n(a,d,r,s,o);return void(this._head=new i(t))}let m=null,c=this._head;for(;c;){if(s<c.data.indexFrom)return this._insert(r,s,o,m,c);m=c,c=c.next}this._insert(r,s,o,m,null)}forEach(e){t(this._head)&&this._head.forEach(e)}*infos(){if(t(this._head))for(const t of this._head.values())yield t}_insert(a,d,r,s,o){if(e(s)&&e(o)){const t=new n(this._target,this.geometryType,a,d,r);this._head=new i(t)}return e(s)&&t(o)?this._insertAtHead(a,d,r,o):t(s)&&e(o)?this._insertAtEnd(a,d,r,s):t(s)&&t(o)?this._insertAtMiddle(a,d,r,s,o):void 0}_insertAtHead(t,e,a,d){const r=e+a;if(t===d.data.materialKey&&r===d.data.indexFrom)d.data.indexFrom=e,d.data.indexCount+=a;else{const r=new n(this._target,this.geometryType,t,e,a);this._head=new i(r),this._head.next=d}}_insertAtEnd(t,e,a,d){if(d.data.materialKey===t&&d.data.indexEnd===e)d.data.indexCount+=a;else{const r=new n(this._target,this.geometryType,t,e,a),s=new i(r);d.next=s}}_insertAtMiddle(t,e,a,d,r){const s=e+a;if(d.data.materialKey===t&&d.data.indexEnd===e)d.data.indexCount+=a,d.data.materialKey===r.data.materialKey&&d.data.indexEnd===r.data.indexFrom&&(d.data.indexCount+=r.data.indexCount,d.next=r.next);else if(t===r.data.materialKey&&s===r.data.indexFrom)r.data.indexFrom=e,r.data.indexCount+=a;else{const s=new n(this._target,this.geometryType,t,e,a),o=new i(s);d.next=o,o.next=r}}}export{a as FeatureDisplayList,n as FeatureDisplayListInfo};